-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_validation.py
More file actions
119 lines (108 loc) · 3.98 KB
/
test_validation.py
File metadata and controls
119 lines (108 loc) · 3.98 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
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
116
117
118
119
import parameterized
import rest_framework.status
import rest_framework.test
import business.models
import business.tests.auth.base
class InvalidCompanyRegistrationTestCase(
business.tests.auth.base.BaseBusinessAuthTestCase,
):
def test_duplicate_email_registration(self):
business.models.Company.objects.create_company(
name=self.valid_data['name'],
email=self.valid_data['email'],
password=self.valid_data['password'],
)
self.assertTrue(
business.models.Company.objects.filter(
email=self.valid_data['email'],
).exists(),
)
response = self.client.post(
self.signup_url,
self.valid_data,
format='json',
)
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_409_CONFLICT,
)
@parameterized.parameterized.expand(
[
('short_password_1', 'easypwd'),
('short_password_2', 'Ar1@!$'),
('no_digits', 'PasswordWithoutDigits'),
('no_special_chars', 'PasswordWithoutSpecial1'),
('common_phrase', 'whereismymoney777'),
('missing_uppercase', 'lowercase123$'),
('missing_lowercase', 'UPPERCASE123$'),
('non_ascii', 'Päss123$!AAd'),
('emoji', '😎werY!!*Dj3sd'),
],
)
def test_invalid_password_cases(self, _, invalid_password):
test_data = {**self.valid_data, 'password': invalid_password}
response = self.client.post(self.signup_url, test_data, format='json')
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
f'Failed for password: {invalid_password}',
)
@parameterized.parameterized.expand(
[
('domain_missing_dot', 'a@b'),
('domain_missing_dot', 'test@dom'),
('missing_local_part', '@domain.com'),
('missing_at_symbol', 'missing.at.sign'),
('multiple_at_symbols', 'double@@at.com'),
],
)
def test_invalid_email_cases(self, _, invalid_email):
test_data = {**self.valid_data, 'email': invalid_email}
response = self.client.post(self.signup_url, test_data, format='json')
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
f'Failed for email: {invalid_email}',
)
def test_short_company_name(self):
test_data = {**self.valid_data, 'name': 'A'}
response = self.client.post(self.signup_url, test_data, format='json')
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
)
class InvalidCompanyAuthenticationTestCase(
business.tests.auth.base.BaseBusinessAuthTestCase,
):
@parameterized.parameterized.expand(
[
('missing_password', {'email': 'valid@example.com'}, 'password'),
('missing_email', {'password': 'any'}, 'email'),
('empty_data', {}, ['email', 'password']),
],
)
def test_missing_required_fields(self, case_name, data, expected_fields):
response = self.client.post(self.signin_url, data, format='json')
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_400_BAD_REQUEST,
)
def test_signin_invalid_password(self):
business.models.Company.objects.create_company(
email=self.valid_data['email'],
name=self.valid_data['name'],
password=self.valid_data['password'],
)
data = {
'email': self.valid_data['email'],
'password': 'SuperInvalidPassword2000!',
}
response = self.client.post(
self.signin_url,
data,
format='json',
)
self.assertEqual(
response.status_code,
rest_framework.status.HTTP_401_UNAUTHORIZED,
)