-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_credentials.py
executable file
·101 lines (80 loc) · 3.3 KB
/
test_credentials.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import unittest
from models import Credentials
import pyperclip
class TestCredentials(unittest.TestCase):
'''
main test class for the credentials class
'''
def setUp(self):
'''
Method that creates a credentials object for testing
'''
self.new_credentials = Credentials("jane","medium.com", "x")
def test_init(self):
'''
test if object is instantiated correctly
'''
self.assertEqual(self.new_credentials.user_name, "jane")
self.assertEqual(self.new_credentials.app_name, "medium.com")
self.assertEqual(self.new_credentials.app_password, "x")
def test_save_credentials(self):
'''
Test if credentials are saved in the credentials list
'''
self.new_credentials.save_credentials()
self.assertEqual(len(Credentials.credentials_list),1)
def tearDown(self):
'''
teardown method to clean up after test runs
'''
Credentials.credentials_list = []
#test cases for class methods
def test_multiple_credentials(self):
'''
test to check if the program can save multiple credentials object in the credentials_list
'''
self.new_credentials.save_credentials()
test_credentials = Credentials("john","dribble.com", "y")
test_credentials.save_credentials()
self.assertEqual(len(Credentials.credentials_list),2)
def test_delete_credential(self):
'''
test if the application can delete an application credentials object in credentials list
'''
self.new_credentials.save_credentials()
test_credentials = Credentials("john","dribble.com", "y")
test_credentials.save_credentials()
self.new_credentials.delete_credentials() #delete credentials
self.assertEqual(len(Credentials.credentials_list),1)
def test_contact_exists(self):
'''
test to check if contact exists method works
'''
self.new_credentials.save_credentials()
test_credentials = Credentials("john","dribble.com", "y")
test_credentials.save_credentials()
credentials_exists = Credentials.credentials_exists("dribble.com")
self.assertTrue(credentials_exists)
def test_find_contact_by_name(self):
'''
test to check if we can find an application credential by name and display data
'''
self.new_credentials.save_credentials()
test_credentials = Credentials("john","dribble.com", "y")
test_credentials.save_credentials()
found_password = Credentials.find_by_app_name("dribble.com")
self.assertEqual(found_password, test_credentials.app_password)
def test_display_all_credentials(self):
'''
test if application can list all credentials saved
'''
self.assertEqual(Credentials.display_credentials(), Credentials.credentials_list)
def test_copy_password(self):
'''
test to confirm that the application can copy the found password on the clipboard
'''
self.new_credentials.save_credentials()
Credentials.copy_password("medium.com")
self.assertEqual(self.new_credentials.app_password,pyperclip.paste())
if __name__ == "__main__":
unittest.main()