-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_user.py
More file actions
executable file
·70 lines (59 loc) · 2.05 KB
/
test_user.py
File metadata and controls
executable file
·70 lines (59 loc) · 2.05 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
61
62
63
64
65
66
67
68
69
70
import unittest
from user import User
class TestUser(unittest.TestCase):
"""
Test class that defines test cases for the user class behaviours
Args:
unittest.Testcase: TestCase class that helps in creating test cases
"""
def setUp(self):
'''
Set up method to run before each test cases.
'''
self.new_user = User("Denise","Wanjiru","DensTheLion","!@#$")
def tearDown(self):
'''
tearDown method that does clean up after each test case has run.
'''
User.user_list = []
def test_init(self):
'''
Test case to see if objects are initialized properly
'''
self.assertEqual(self.new_user.first_name,"Denise")
self.assertEqual(self.new_user.last_name,"Wanjiru")
self.assertEqual(self.new_user.username,"DensTheLion")
self.assertEqual(self.new_user.password,"!@#$")
def test_save_user(self):
'''
Test case to test if the user object is saved into
the user list
'''
self.new_user.save_user()
self.assertEqual(len(User.user_list),1)
def test_save_multiple_users(self):
'''
Test case to test if we can save multiple users to the user list
'''
self.new_user.save_user()
second_user = User("Lan","Mac","LaMa","1234")
second_user.save_user()
self.assertEqual(len(User.user_list),2)
def test_find_my_account(self):
"""
Test case to find a users account by username and password
"""
self.new_user.save_user()
second_user = User("Lan","Mac","LaMa","1234")
second_user.save_user()
found_user = User.find_user("LaMa","1234")
self.assertEqual(found_user.first_name,second_user.first_name)
def test_user_exists(self):
"""
Test case to find if the user really exists
"""
self.new_user.save_user()
user_exist = User.user_exists("DensTheLion","!@#$")
self.assertTrue(user_exist)
if __name__ == '__main__':
unittest.main()