forked from Code-Platoon-Assignments/django-school-api-II
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
200 lines (184 loc) · 7 KB
/
tests.py
File metadata and controls
200 lines (184 loc) · 7 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
from django.test import TestCase
from .models import Student
from django.core.exceptions import ValidationError
from django.db import IntegrityError
# Create your tests here.
## PART I
class Test_student(TestCase):
def test_001_student_with_improper_good_student_field(self):
try:
new_student = Student.objects.create(
name="John W. Watson",
student_email="thisIsAnEmail@school.com",
personal_email="thisIsAnEmail@gmail.com",
locker_number=13,
locker_combination="12-33-44",
good_student=None,
)
new_student.full_clean()
self.fail()
except IntegrityError as e:
# print(e)
self.assertIn(
'null value in column "good_student" of relation "student_app_student" violates not-null constraint',
str(e),
)
def test_002_student_with_improper_email_fields(self):
try:
new_student = Student.objects.create(
name="John W. Watson",
student_email="thisIsNotAnEmail",
personal_email=False,
locker_number=13,
locker_combination="23-33-44",
good_student=True,
)
new_student.full_clean()
self.fail()
except ValidationError as e:
# print(e.message_dict)
self.assert_(
"student_email" in e.message_dict and "personal_email" in e.message_dict
)
def test_003_student_with_improper_locker_number_fields(self):
try:
new_student = Student.objects.create(
name="John W. Watson",
student_email="thisIsAnEmail@school.com",
personal_email="thisIsAnEmail@gmail.com",
locker_number="None",
locker_combination="23-33-44",
good_student=True,
)
new_student.full_clean()
self.fail()
except Exception as e:
# print(e)
self.assert_(
"Field 'locker_number' expected a number but got 'None'" in str(e)
)
def test_004_student_with_improper_locker_combination_fields(self):
try:
new_student = Student.objects.create(
name="John W. Watson",
student_email="thisIsAnEmail@school.com",
personal_email="thisIsAnEmail@gmail.com",
locker_number=13,
locker_combination=None,
good_student=True,
)
new_student.full_clean()
self.fail()
except IntegrityError as e:
# print(e)
self.assert_('null value in column "locker_combination" ' in str(e))
def test_005_student_with_improper_name_field(self):
try:
new_student = Student.objects.create(
name=None,
student_email="thisIsAnEmail@school.com",
personal_email="thisIsAnEmail@gmail.com",
locker_number=13,
locker_combination="12-12-12",
good_student=True,
)
new_student.full_clean()
self.fail()
except Exception as e:
# print(e)
self.assert_('null value in column "name" ' in str(e))
def test_006_student_with_proper_fields(self):
new_student = Student.objects.create(
name="John W. Wally",
student_email="john@school.com",
personal_email="john@gmail.com",
locker_number=13,
locker_combination="12-12-12",
good_student=True,
)
new_student.full_clean()
self.assertIsNotNone(new_student)
# PART II
def test_007_student_with_repeated_student_email(self):
try:
Student.objects.create(
name="Johnny H. Harris",
student_email="thisIsMyEmail@school.com",
personal_email="myOtherEmail@gmail.com",
locker_number=119,
locker_combination="11-11-11",
good_student=False,
)
new_student = Student.objects.create(
name="Johnny H. Harris",
student_email="thisIsMyEmail@school.com",
personal_email="myEmail@gmail.com",
locker_number=109,
locker_combination="11-11-11",
good_student=False,
)
new_student.full_clean()
self.fail()
except IntegrityError as e:
# print("\n\n\n", e, "\n\n\n")
self.assert_(
'duplicate key value violates unique constraint "student_app_student_student_email'
in str(e)
)
def test_008_student_with_repeated_personal_email(self):
try:
Student.objects.create(
name="Johnny H. Harris",
student_email="thisIsMyOtherEmail@school.com",
personal_email="myEmail@gmail.com",
locker_number=119,
locker_combination="11-11-11",
good_student=False,
)
new_student = Student.objects.create(
name="Johnny H. Harris",
student_email="thisIsMyEmail@school.com",
personal_email="myEmail@gmail.com",
locker_number=109,
locker_combination="11-11-11",
good_student=False,
)
new_student.full_clean()
self.fail()
except IntegrityError as e:
# print("\n\n\n", e, "\n\n\n")
self.assert_(
'duplicate key value violates unique constraint "student_app_student_personal_email'
in str(e)
)
def test_009_student_with_repeated_locker_number(self):
try:
Student.objects.create(
name="Johnny H. Harris",
student_email="IsmyOEmail@school.com",
personal_email="otIsMyEmail@gmail.com",
locker_number=108,
locker_combination="11-11-11",
good_student=False,
)
new_student = Student.objects.create(
name="Johnny H. Harris",
student_email="IsyEmail@school.com",
personal_email="tIsMyEmail@gmail.com",
locker_number=108,
locker_combination="11-11-11",
good_student=False,
)
new_student.full_clean()
self.fail()
except IntegrityError as e:
# print(e)
self.assert_("student_app_student_locker_number" in str(e))
def test_010_student_utilizing_default_values(self):
new_student = Student.objects.create(
name="Maverick H. Macconnel",
student_email="mav@school.com",
personal_email="mav@gmail.com",
)
new_student.full_clean()
self.assertIsNotNone(new_student)