forked from benevolentprof/inf1340_2014_asst2
/
test_papers.py
130 lines (112 loc) · 4.62 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
#!/usr/bin/env python3
""" Module to test papers.py """
__author__ = 'Joanna Kolbe, Olena Kit'
__email__ = "joannakolbe@gmail.com, olena.kit@mail.utoronto.ca"
__copyright__ = "2014 Joanna Kolbe, Olena Kit"
__status__ = "Prototype"
# imports one per line
import pytest
from papers import decide
# Basic tests
def test_basic():
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"]
# File not found tests
def test_files():
with pytest.raises(FileNotFoundError):
decide("", "", "")
decide("", "watchlist.json", "")
decide("", "", "countries.json")
decide("", "watchlist.json", "countries.json")
decide("test_returning_citizen.json", "", "")
decide("test_returning_citizen.json", "", "countries.json")
decide("test_returning_citizen.json", "watchlist.json", "")
decide("test_watchlist.json", "", "")
decide("test_watchlist.json", "", "countries.json")
decide("test_watchlist.json", "watchlist.json", "")
decide("test_quarantine.json", "", "")
decide("test_quarantine.json", "", "countries.json")
decide("test_quarantine.json", "watchlist.json", "")
# Incomplete file tests
def test_incomplete():
"""
Test blank entries
Index 0: Blank passport
Index 1: Blank first name
Index 2: Blank last name
Index 3: Blank birth date
Index 4: Blank home country
Index 5: Blank from country
Index 6: Blank entry reason
"""
assert decide("test_blank.json", "watchlist.json", "countries.json")\
== ["Reject", "Reject", "Reject", "Reject",
"Reject", "Reject", "Reject"]
'''
Test invalid entries
Index 0: Invalid passport
Index 1: Invalid birth date
Index 2: Invalid visa date
Index 3: Invalid visa code
'''
assert decide("test_invalid.json", "watchlist.json", "countries.json") == \
["Reject", "Reject", "Reject", "Reject"]
def test_visa():
"""
Visa tests
Index 0: Valid visa and entry is to visit
Index 1: Expired visa and entry is to visit
Index 2: Valid visa and entry is transit
Index 3: Expired visa and entry is transit
Index 4: Valid visa and entry is visit -
from and via country both require visa
Index 5: Valid visa and entry is visit - from country
requires visa and via country does not
Index 6: Valid visa and entry is visit - via country
requires visa and from country does not
"""
assert decide("test_visa.json", "watchlist.json", "countries.json") ==\
["Accept", "Reject", "Accept", "Reject", "Accept", "Accept", "Accept"]
def test_case():
"""
Case mismatch tests
Index 0: Passport, first name, last name, and country codes in uppercase
Index 1: Passport in lowercase
Index 2: First name and last name in lowercase
Index 3: Country codes in lowercase
"""
assert decide("test_case.json", "watchlist.json", "countries.json") ==\
["Secondary", "Secondary", "Secondary", "Secondary"]
def test_precedence():
"""
Precedence tests
Index 0: Quarantine over Reject - reject due to expired passport,
but quarantine due to medical advisory
Index 1: Quarantine over Secondary -secondary due to passport on watchlist,
but quarantine due to medical advisory
Index 2: Quarantine over Accept - accept due to returning to KAN,
but quarantine due to medical advisory
Index 3: Reject over Secondary - secondary due to passport on watchlist,
but reject due to blank name
Index 4: Reject over Accept - accept due to returning to KAN, but reject
due to invalid passport
Index 5: Secondary over Accept - accept due to returning to KAN,
but secondary due to passport on watchlist
"""
assert decide("test_precedence.json", "watchlist.json", "countries.json")\
== ["Quarantine", "Quarantine", "Quarantine", "Reject",
"Reject", "Secondary"]
def test_input_file():
"""
test for proper input type format
"""
with pytest.raises(TypeError):
# file does not contain a list of entries
decide("test_input_file.json", "watchlist.json", "countries.json")
with pytest.raises(TypeError):
# entries in a list are not objects
decide("test_input_file_2.json", "watchlist.json", "countries.json")