/
test_createuser.py
77 lines (62 loc) · 2.71 KB
/
test_createuser.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
'''
This module will handle all testing related to generating new users.
'''
import UserCreation
from UserCreation import UserCreation
from UserManager import UserManager
from Authenticator import Authenticator
import pytest
from unittest import mock
from unittest.mock import MagicMock
from io import StringIO
class TestUserCreation:
def setUp(self):
self.testing_salt = Authenticator.generate_salt()
def test_gather_user_credentials_called(self):
'''
This function will test if we are correctly calling the gather_user_creation_details.
'''
userbase = UserManager()
creator = UserCreation(userbase)
creator.gather_user_creation_details = MagicMock(return_value=False)
creator.create()
creator.gather_user_creation_details.assert_called_once()
def test_create_new_user(self):
'''
This function will test if we can correctly create a new user.
'''
userbase = UserManager()
username = "chad"
password = "password"
salt = Authenticator.generate_salt()
creator = UserCreation(userbase,username,password,salt)
creator.gather_user_creation_details = MagicMock(return_value=True)
creator.create()
assert(userbase.is_existing_user(username) == True)
def test_create_many_users(self):
'''
This test case will ensure that multiple users can be created in one session.
'''
userbase = UserManager()
usernames = ["chad","jay","dylan","ellen","pat","jon"]
passwords = ["password","hockey","cooking","teaching","painting","swimming"]
salts = [Authenticator.generate_salt()] * 6
for xx in range(0, len(usernames)):
creator = UserCreation(userbase,usernames[xx],passwords[xx],salts[xx])
creator.gather_user_creation_details = MagicMock(return_value = True)
creator.create()
assert(userbase.is_existing_user(usernames[xx]) == True)
assert(userbase.get_total_users() == len(usernames))
def test_create_duplicate_new_users(self):
'''
This test case will ensure that only 1 unique user exists per username.
'''
userbase = UserManager()
usernames = ["chad","chad"]
passwords = ["password","hockey"]
salts = [Authenticator.generate_salt()] * 2
for xx in range(0, len(usernames)):
creator = UserCreation(userbase,usernames[xx],passwords[xx],salts[xx])
creator.gather_user_creation_details = MagicMock(return_value = True)
creator.create()
assert(userbase.get_total_users() == len(usernames)-1)