-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_alive.py
32 lines (26 loc) · 1005 Bytes
/
test_alive.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
"""
This test module tests the COHD API by making requests to cohd.io/api and checking the schema of the response JSONs and
checking the results against known values.
Intended to be run with pytest: pytest -s test_cohd_io.py
"""
from urllib.parse import urljoin
import requests
# Choose which server to test
servers = ['https://cohd.io/api',
'https://cohd-api.ci.transltr.io/api',
'https://cohd-api.test.transltr.io/api',
'https://cohd-api.transltr.io/api']
def test_alive():
""" Check the /health endpoint of each server to check that it's alive.
"""
unhealthy = False
for server in servers:
print(f'\ntest_alive: testing /health on {server}..... ')
response = requests.get(urljoin(server, '/health'), timeout=10)
if response.status_code == 200:
print('\t' + response.text)
else:
print(f'\tUNHEALTHY!')
unhealthy = True
# No server should be unhealthy
assert not unhealthy