forked from benevolentprof/inf1340_2014_asst2
/
test_papers.py
239 lines (197 loc) · 10.9 KB
/
test_papers.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
""" Module to test papers.py """
__author__ = 'Amy Kwan, Jessica Mann, Susan Sim'
__email__ = "amykwan.cma@gmail.com, jessmann74@gmail.com, ses@drsusansim.org"
__copyright__ = "2014 AKJMSM"
__license__ = "MIT License"
__status__ = "v8"
# imports one per line
import pytest
from papers import decide
def test_basic():
"""
Basic tests to tests provided to test for: accepting returning citizens,
for traveller's who are on the watchlist and should be flagged to
secondary, and for traveller's who should be flagged to quarantine.
"""
assert decide("test_returning_citizen.json", "watchlist.json",
"countries.json") == ["Accept", "Accept"]
assert decide("test_watchlist.json", "watchlist.json",
"countries.json") == ["Secondary"]
assert decide("test_quarantine.json", "watchlist.json",
"countries.json") == ["Quarantine"]
def test_quarantine():
"""
Inputs a watchlist JSON file, a countries JSON file,
and a JSON file with entry records of
travellers who should all be quarantined.
Included cases: whether their entry records are complete/correct;
whether the traveller is in transit, visiting or from KAN;
whether or not their visa is valid; and whether or not
the traveller is on the watchlist.
"""
assert decide("test_JSON_files/test_01.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_02.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_03.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_04.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_05.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_06.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_07.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_08.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_09.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_10.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_11.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_12.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_13.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_14.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_15.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_16.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_17.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_18.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_19.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_20.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_21.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_22.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_23.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_24.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_25.json",
"watchlist.json", "countries.json") == ["Quarantine"]
assert decide("test_JSON_files/test_26.json",
"watchlist.json", "countries.json") == ["Quarantine"]
def test_secondary():
"""
Inputs a watchlist JSON file, a countries JSON file, and a JSON file
with entry records of travellers who should all be "Secondary";
(i.e., who are on the watchlist).
Included cases: whether traveller is in transit or visiting with valid or
invalid visa, or in transit or visiting from a country with no visa needed.
"""
assert decide("test_JSON_files/test_27.json",
"watchlist.json", "countries.json") == ["Secondary"]
assert decide("test_JSON_files/test_31.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_33.json",
"watchlist.json", "countries.json") == ["Secondary"]
assert decide("test_JSON_files/test_35.json",
"watchlist.json", "countries.json") == ["Secondary"]
assert decide("test_JSON_files/test_37.json",
"watchlist.json", "countries.json") == ["Secondary"]
def test_accept():
"""
Inputs a watchlist JSON file, a countries JSON file, and a JSON file
with entry records of travellers who should all be accepted.
Included cases: whether the traveller is in transit, or visiting with
visa required and visa is valid, in transit or visiting with no visa
required, or traveller is from KAN.
Also includes tests of fields with both upper and lower case values.
"""
assert decide("test_JSON_files/test_28.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_32.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_34.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_38.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_39.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_lower_case.json",
"watchlist.json", "countries.json") == ["Accept"]
assert decide("test_JSON_files/test_upper_case.json",
"watchlist.json", "countries.json") == ["Accept"]
def test_reject():
"""
Inputs a watchlist JSON file, a countries JSON file, and a JSON file with
entry records of travellers who should all be rejected.
Included cases: incomplete or incorrect entry records whether traveller is
in transit, visiting or from KAN; whether or not a visa is required but
out of date range, wrong code length or not present; and whether or not
the traveller is on a the watchlist.
Also includes tests for entry records where birthdays are future dated
or earlier than 150 years ago (assumption is no one is older than this
age), missing keys and/or values, invalidly formatted dates or passport
numbers, and countries that are not on the country list.
"""
assert decide("test_JSON_files/test_29.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_30.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_36.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_40.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_41.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_42.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_43.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_44.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_45.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_46.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_47.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_48.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_49.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_50.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_51.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_52.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_dates.json", "watchlist.json",
"countries.json") == ["Reject", "Reject", "Reject",
"Reject", "Reject", "Reject"]
assert decide("test_JSON_files/test_invalid_country.json",
"watchlist.json", "countries.json") == ["Reject"]
assert decide("test_JSON_files/test_missing_entry_pairs.json",
"watchlist.json", "countries.json") == ["Reject",
"Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject"]
assert decide("test_JSON_files/test_missing_keys.json",
"watchlist.json", "countries.json") == ["Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject"]
assert decide("test_JSON_files/test_missing_values.json",
"watchlist.json", "countries.json") == ["Reject",
"Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject",
"Reject", "Reject"]
def test_files():
"""
Function to raise error if file is not found.
"""
with pytest.raises(FileNotFoundError):
decide("test_returning_citizen.json", "", "countries.json")