-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcredential_test.py
115 lines (89 loc) · 3.87 KB
/
credential_test.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import unittest
import pyperclip
from credential import Credential
class credential_test(unittest.TestCase):
"""
Test class that defines test cases for the credential class behaviours
Args:
unittest.TestCase: TestCase class that helps in creating test cases
"""
def setUp(self):
"""
set up method to run each test case
"""
self.new_profile = Credential ("github", "Sarah", "[email protected]", "password")
def test_init(self):
"""
test init to test if the object is initialized properly
"""
self.assertTrue(self.new_profile.profile_name, "github")
self.assertTrue(self.new_profile.profile_username, "Sarah")
self.assertTrue(self.new_profile.profile_email,"[email protected]")
self.assertTrue(self.new_profile.profile_password)
def test_create_new_profile(self):
"""
test_create_new_profile to test if a new object can be saved
"""
self.new_profile.save_profile()
self.assertEqual(len(Credential.profile_list), 1)
def tearDown(self):
"""
teardown method that does clean up after each test case has run
"""
Credential.profile_list = []
def test_create_multiple_profiles(self):
"""
test_create_multiple_profiles to test if multiple objects can be saved
"""
self.new_profile.save_profile()
test_profile = Credential("facebook", "Marion", "[email protected]")
test_profile.save_profile()
self.assertEqual(len(Credential.profile_list), 2)
def test_profile_exist(self):
"""
test_profile_exist to check if there is another matching or similar profile
"""
test_profile1 = Credential("twitter", "Marion", "[email protected]")
test_profile1.save_profile()
profile = test_profile1.check_profile_exist("twitter", "Marion", "[email protected]")
self.assertTrue(profile)
def test_search_profile(self):
"""
test_search_profile to test if a user can be able to search for a profile_email
"""
test_profile1 = Credential("twitter", "Marion", "[email protected]")
test_profile1.save_profile()
search_result = test_profile1.search_profile("twitter")
self.assertEqual(test_profile1, search_result)
def test_delete_profile(self):
"""
test_delete_profile to test if a user can delete a specific profile
"""
test_profile1 = Credential("twitter", "Marion", "[email protected]")
test_profile1.save_profile()
test_profile1.delete_profile()
self.assertEqual(len(Credential.profile_list), 0)
# def test_display_all_profiles(self):
# """
# test_display_all_profiles to test if a user can view all their profiles
# """
# self.assertEqual(Credential.display_profiles(), Credential.profile_list)
def test_copy_credentials(self):
"""
test copy_credentials to test if a user can be able to copy an item to the clipboard
"""
test_profile1 = Credential("twitter","Marion","[email protected]","testPassword")
test_profile1.save_profile()
Credential.copy_credentials("twitter")
self.assertEqual(test_profile1.profile_password,pyperclip.paste())
def test_generate_random_password(self):
"""
test_generate_random_password to test if a user can generate a random password with a set length
"""
test_profile1 = Credential("Marion","[email protected]")
generated_password = test_profile1.generate_random_password
test_profile1.profile_password = generated_password
test_profile1.save_profile()
self.assertTrue(test_profile1.profile_password)
if __name__ == "__main__":
unittest.main()