-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app.py
More file actions
46 lines (35 loc) · 1.38 KB
/
test_app.py
File metadata and controls
46 lines (35 loc) · 1.38 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
import unittest
from app import app
class TestRelay(unittest.TestCase):
# required for app testing
app.testing = True
def test_res_ok(self):
with app.test_client() as c:
res = c.get("/restaurant")
self.assertEqual(res.status_code, 200)
# test response not_ok
def test_res_nok1(self):
with app.test_client() as c:
res = c.get()
self.assertNotEqual(res.status_code, 200)
def test_res_nok2(self):
with app.test_client(self) as c:
res = c.get("restaurant/not_a_restaurant_really")
self.assertNotEqual(res.status_code, 200)
# test json 200
def test_res_json(self):
with app.test_client(self) as c:
res = c.get("restaurant")
self.assertEqual(res.headers.get("content-type"), "application/json")
# test json Not 200
def test_res_json_err(self):
with app.test_client(self) as c:
res = c.get("restaurant/not_a_restaurant_really")
self.assertEqual(res.headers.get("content-type"), "application/json")
# test content
def test_res_content(self):
with app.test_client(self) as c:
res = c.get("restaurant")
self.assertIn(b'{\n "restaurants":', res.data)
if __name__ == "__main__":
unittest.main()