-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_Password_Manager.py
More file actions
62 lines (54 loc) · 1.92 KB
/
Test_Password_Manager.py
File metadata and controls
62 lines (54 loc) · 1.92 KB
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
import os
import pytest
from Password_Manager import PasswordManager
from cryptography.fernet import Fernet
@pytest.fixture
def password_manager(tmpdir):
pm = PasswordManager()
key_path = os.path.join(tmpdir, 'key.key')
password_path = os.path.join(tmpdir, 'passwords.txt')
pm.create_key(key_path)
pm.create_password_file(password_path)
yield pm, key_path, password_path
os.remove(key_path)
os.remove(password_path)
def test_create_key(password_manager):
pm, key_path, _ = password_manager
assert os.path.exists(key_path)
def test_loading_key(password_manager):
pm, key_path, _ = password_manager
pm.loading_key(key_path)
assert pm.key is not None
def test_create_password_file(password_manager):
pm, _, password_path = password_manager
password_data = {
"email": "1234567",
"Facebook": "Meta1234",
"Youtube": "CS50_",
"Instagram": "Professor"
}
pm.create_password_file(password_path, password_data)
assert os.path.exists(password_path)
def test_load_password_file(password_manager):
pm, _, password_path = password_manager
password_data = {
"email": "1234567",
"Facebook": "Meta1234",
"Youtube": "CS50_",
"Instagram": "Professor"
}
pm.create_password_file(password_path, password_data)
pm.load_password_file(password_path)
assert len(pm.password_dictionary) == len(password_data)
def test_add_password(password_manager):
pm, _, password_path = password_manager
site = "Twitter"
password = "Twitter123"
pm.add_password(site, password)
with open(password_path, 'r') as f:
lines = f.readlines()
last_line = lines[-1]
stored_site, encrypted_password = last_line.strip().split(":")
decrypted_password = Fernet(pm.key).decrypt(encrypted_password.encode()).decode()
assert stored_site == site
assert decrypted_password == password