-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_router.py
33 lines (29 loc) · 1.15 KB
/
test_router.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
from fastapi import status
from fastapi.testclient import TestClient
def test_read_root(client: TestClient):
response = client.get("/")
assert response.status_code == status.HTTP_200_OK
result = response.json()
assert result['title'] == "Record Cleaner Service"
def test_maintenance(client: TestClient):
# Enable maintenance mode.
response = client.post(
'/maintenance',
json={'mode': True, 'message': 'Service off'}
)
assert response.status_code == status.HTTP_200_OK
assert response.json() == {'mode': True, 'message': 'Service off'}
# Confirm routes disabled.
response = client.get('/users')
assert response.status_code == status.HTTP_503_SERVICE_UNAVAILABLE
assert response.json() == {'message': 'Service off'}
# Disable maintenance mode.
response = client.post(
'/maintenance',
json={'mode': False, 'message': 'Service on'}
)
assert response.status_code == status.HTTP_200_OK
assert response.json() == {'mode': False, 'message': 'Service on'}
# Confirm routes enabled.
response = client.get('/users')
assert response.status_code == status.HTTP_200_OK