-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.py
61 lines (43 loc) · 2.06 KB
/
test_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import unittest
import utils
import os.path
import pyperclip
class TestUtils(unittest.TestCase):
def test_create_password_default(self):
result = utils.create_password()
self.assertEqual(len(result), 8)
def test_create_password_no_numbers(self):
result = utils.create_password(length=20, has_numbers=False)
self.assertEqual(len(result), 20)
self.assertFalse(any(number in utils.NUMBERS for number in result))
def test_create_password_no_symbols(self):
result = utils.create_password(length=20, has_symbols=False)
self.assertEqual(len(result), 20)
self.assertFalse(any(element in utils.SYMBOLS for element in result))
def test_generate_password(self):
# Generate password of length 20 with letters, numbers and symbols.
available_chars = "".join([utils.ALPHA, utils.NUMBERS, utils.SYMBOLS])
result = utils.generate_password(length=20, chars=available_chars)
self.assertEqual(len(result), 20)
self.assertTrue(any(character in utils.ALPHA for character in result))
self.assertTrue(any(number in utils.NUMBERS for number in result))
self.assertTrue(any(element in utils.SYMBOLS for element in result))
def test_save_password(self):
first_password = "first dummy password to save"
second_password = "second dummy password to save"
utils.save_password(first_password)
utils.save_password(second_password)
file_path = os.path.join(os.getcwd(), "passwords.txt")
self.assertTrue(os.path.isfile(file_path))
with open("passwords.txt") as passwords_file:
file_lines = passwords_file.readlines()
self.assertEqual(first_password, file_lines[0].strip())
self.assertEqual(second_password, file_lines[1].strip())
os.remove(file_path)
def test_copy_to_clipboard(self):
password = "1234 password to test"
pyperclip.copy(password)
result = pyperclip.paste()
self.assertEqual(password, result)
if __name__ == "__main__":
unittest.main()