forked from brandon-rhodes/fopnp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_test.py
46 lines (31 loc) · 948 Bytes
/
_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
"""Check that a server works.
Run the service under test (which should be another Python module in
this directory) like:
$ gunicorn -b '' timeapp_raw:app
"""
import requests
def display(r):
print((r.status_code, r.headers['Content-Type'], r.text))
if __name__ == '__main__':
# Wrong method
r = requests.post('http://localhost:8000/')
display(r)
assert r.status_code == 501
# Wrong hostname
r = requests.get('http://localhost:8000/')
display(r)
assert r.status_code == 404
# Wrong path
r = requests.get('http://127.0.0.1:8000/foo')
display(r)
assert r.status_code == 404
r = requests.get('http://127.0.0.1:8000/foo/')
display(r)
assert r.status_code == 404
# Right path
r = requests.get('http://127.0.0.1:8000/')
display(r)
assert r.status_code == 200
r = requests.get('http://127.0.0.1:8000/?abc=123')
display(r)
assert r.status_code == 200