You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

171 lines
6.7 KiB

  1. import unittest
  2. from lesspass.cli import parse_args
  3. from lesspass.profile import create_profile
  4. class TestProfile(unittest.TestCase):
  5. def test_create_profile_default(self):
  6. profile, master_password = create_profile(parse_args(["site", "login"]))
  7. self.assertTrue(profile["lowercase"])
  8. self.assertTrue(profile["uppercase"])
  9. self.assertTrue(profile["digits"])
  10. self.assertTrue(profile["symbols"])
  11. self.assertEqual(profile["length"], 16)
  12. self.assertEqual(profile["counter"], 1)
  13. self.assertEqual(profile["site"], "site")
  14. self.assertEqual(profile["login"], "login")
  15. self.assertEqual(profile["exclude"], "")
  16. self.assertIsNone(master_password)
  17. def test_create_profile_login(self):
  18. profile, _ = create_profile(parse_args(["site"]))
  19. self.assertEqual(profile["login"], "")
  20. def test_create_profile_length(self):
  21. profile, _ = create_profile(parse_args(["site", "--length", "8"]))
  22. self.assertEqual(profile["length"], 8)
  23. def test_create_profile_counter(self):
  24. profile, _ = create_profile(parse_args(["site", "--counter", "2"]))
  25. self.assertEqual(profile["counter"], 2)
  26. def test_create_profile_master_password(self):
  27. _, master_password = create_profile(
  28. parse_args(["site", "login", "master_password"])
  29. )
  30. self.assertEqual(master_password, "master_password")
  31. def test_create_profile_l(self):
  32. profile, _ = create_profile(parse_args(["site", "-l"]))
  33. self.assertTrue(profile["lowercase"])
  34. self.assertFalse(profile["uppercase"])
  35. self.assertFalse(profile["digits"])
  36. self.assertFalse(profile["symbols"])
  37. def test_create_profile_u(self):
  38. profile, _ = create_profile(parse_args(["site", "-u"]))
  39. self.assertFalse(profile["lowercase"])
  40. self.assertTrue(profile["uppercase"])
  41. self.assertFalse(profile["digits"])
  42. self.assertFalse(profile["symbols"])
  43. def test_create_profile_d(self):
  44. profile, _ = create_profile(parse_args(["site", "-d"]))
  45. self.assertFalse(profile["lowercase"])
  46. self.assertFalse(profile["uppercase"])
  47. self.assertTrue(profile["digits"])
  48. self.assertFalse(profile["symbols"])
  49. def test_create_profile_s(self):
  50. profile, _ = create_profile(parse_args(["site", "-s"]))
  51. self.assertFalse(profile["lowercase"])
  52. self.assertFalse(profile["uppercase"])
  53. self.assertFalse(profile["digits"])
  54. self.assertTrue(profile["symbols"])
  55. def test_create_profile_lu(self):
  56. profile, _ = create_profile(parse_args(["site", "-lu"]))
  57. self.assertTrue(profile["lowercase"])
  58. self.assertTrue(profile["uppercase"])
  59. self.assertFalse(profile["digits"])
  60. self.assertFalse(profile["symbols"])
  61. def test_create_profile_ld(self):
  62. profile, _ = create_profile(parse_args(["site", "-ld"]))
  63. self.assertTrue(profile["lowercase"])
  64. self.assertFalse(profile["uppercase"])
  65. self.assertTrue(profile["digits"])
  66. self.assertFalse(profile["symbols"])
  67. def test_create_profile_ls(self):
  68. profile, _ = create_profile(parse_args(["site", "-ls"]))
  69. self.assertTrue(profile["lowercase"])
  70. self.assertFalse(profile["uppercase"])
  71. self.assertFalse(profile["digits"])
  72. self.assertTrue(profile["symbols"])
  73. def test_create_profile_ud(self):
  74. profile, _ = create_profile(parse_args(["site", "-ud"]))
  75. self.assertFalse(profile["lowercase"])
  76. self.assertTrue(profile["uppercase"])
  77. self.assertTrue(profile["digits"])
  78. self.assertFalse(profile["symbols"])
  79. def test_create_profile_us(self):
  80. profile, _ = create_profile(parse_args(["site", "-us"]))
  81. self.assertFalse(profile["lowercase"])
  82. self.assertTrue(profile["uppercase"])
  83. self.assertFalse(profile["digits"])
  84. self.assertTrue(profile["symbols"])
  85. def test_create_profile_ds(self):
  86. profile, _ = create_profile(parse_args(["site", "-ds"]))
  87. self.assertFalse(profile["lowercase"])
  88. self.assertFalse(profile["uppercase"])
  89. self.assertTrue(profile["digits"])
  90. self.assertTrue(profile["symbols"])
  91. def test_create_profile_lud(self):
  92. profile, _ = create_profile(parse_args(["site", "-lud"]))
  93. self.assertTrue(profile["lowercase"])
  94. self.assertTrue(profile["uppercase"])
  95. self.assertTrue(profile["digits"])
  96. self.assertFalse(profile["symbols"])
  97. def test_create_profile_lus(self):
  98. profile, _ = create_profile(parse_args(["site", "-lus"]))
  99. self.assertTrue(profile["lowercase"])
  100. self.assertTrue(profile["uppercase"])
  101. self.assertFalse(profile["digits"])
  102. self.assertTrue(profile["symbols"])
  103. def test_create_profile_uds(self):
  104. profile, _ = create_profile(parse_args(["site", "-uds"]))
  105. self.assertFalse(profile["lowercase"])
  106. self.assertTrue(profile["uppercase"])
  107. self.assertTrue(profile["digits"])
  108. self.assertTrue(profile["symbols"])
  109. def test_create_profile_luds(self):
  110. profile, _ = create_profile(parse_args(["site", "-luds"]))
  111. self.assertTrue(profile["lowercase"])
  112. self.assertTrue(profile["uppercase"])
  113. self.assertTrue(profile["digits"])
  114. self.assertTrue(profile["symbols"])
  115. def test_create_profile_suld(self):
  116. profile, _ = create_profile(parse_args(["site", "-suld"]))
  117. self.assertTrue(profile["lowercase"])
  118. self.assertTrue(profile["uppercase"])
  119. self.assertTrue(profile["digits"])
  120. self.assertTrue(profile["symbols"])
  121. def test_create_profile_nl(self):
  122. profile, _ = create_profile(parse_args(["site", "--no-lowercase"]))
  123. self.assertFalse(profile["lowercase"])
  124. self.assertTrue(profile["uppercase"])
  125. self.assertTrue(profile["digits"])
  126. self.assertTrue(profile["symbols"])
  127. def test_create_profile_nu(self):
  128. profile, _ = create_profile(parse_args(["site", "--no-uppercase"]))
  129. self.assertTrue(profile["lowercase"])
  130. self.assertFalse(profile["uppercase"])
  131. self.assertTrue(profile["digits"])
  132. self.assertTrue(profile["symbols"])
  133. def test_create_profile_nd(self):
  134. profile, _ = create_profile(parse_args(["site", "--no-digits"]))
  135. self.assertTrue(profile["lowercase"])
  136. self.assertTrue(profile["uppercase"])
  137. self.assertFalse(profile["digits"])
  138. self.assertTrue(profile["symbols"])
  139. def test_create_profile_ns(self):
  140. profile, _ = create_profile(parse_args(["site", "--no-symbols"]))
  141. self.assertTrue(profile["lowercase"])
  142. self.assertTrue(profile["uppercase"])
  143. self.assertTrue(profile["digits"])
  144. self.assertFalse(profile["symbols"])