-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_test.py
65 lines (51 loc) · 1.72 KB
/
app_test.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
"""
:: MediZen :: Recommendation API ::
Flask API tests, written with Unittest and Pytest.
"""
import unittest
from app import app
class AppTest(unittest.TestCase):
"""
Test app by running:
python -m unittest app_test.py
or:
python -m pytest
--------------
Happy testing!
"""
def set_up(self):
self.app = app.test_client()
def test_get_8_recommendations_succeeds(self):
rv = self.app.get(
(
"/rec/8/sativa,energetic,talkative,"
"euphoric,creative,focused,spicy,tangy,sweet"
)
)
self.assertEqual(rv.status, "200 OK")
self.assertEqual(
rv.data, b"""[696,942,1228,1335,1953,2120,1761,523]""",
)
def test_get_5_recommendations_succeeds(self):
rv = self.app.get(
"""/rec/5/hybrid,euphoric,energetic,creative,woody,earthy"""
)
self.assertEqual(rv.status, "200 OK")
self.assertEqual(rv.data, b"""[736,1585,873,2310,23]""")
def test_get_5_recommendations_without_filters_404(self):
rv = self.app.get("""/rec/5""")
self.assertEqual(rv.status, "404 NOT FOUND")
def test_get_recommendations_without_result_count_404(self):
rv = self.app.get("""/rec""")
self.assertEqual(rv.status, "404 NOT FOUND")
def test_get_strains_succeeds(self):
rv = self.app.get("/strains")
assert rv.status == "200 OK"
assert b"hybrid" in rv.data
assert b"100-Og" in rv.data
assert b"Earthy,Sweet,Citrus" in rv.data
def test_404(self):
rv = self.app.get("/strainz")
self.assertEqual(rv.status, "404 NOT FOUND")
if __name__ == "__main__":
unittest.main()