-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_healthcheck.py
More file actions
37 lines (28 loc) · 1.18 KB
/
test_healthcheck.py
File metadata and controls
37 lines (28 loc) · 1.18 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
from rest_framework.test import APITestCase
class HealthCheckTest(APITestCase):
def test_healthcheck_liveness(self):
# GET and HEAD (no auth required)
url = '/healthz'
resp = self.client.get(url)
self.assertContains(resp, "OK", status_code=200)
resp = self.client.head(url)
self.assertEqual(resp.status_code, 200)
def test_healthcheck_liveness_invalid(self):
url = '/healthz'
for method in ('put', 'post', 'patch', 'delete'):
resp = getattr(self.client, method)(url)
# method not allowed
self.assertEqual(resp.status_code, 405)
def test_healthcheck_readiness(self):
# GET and HEAD (no auth required)
url = '/readiness'
resp = self.client.get(url)
self.assertContains(resp, "OK", status_code=200)
resp = self.client.head(url)
self.assertEqual(resp.status_code, 200)
def test_healthcheck_readiness_invalid(self):
url = '/readiness'
for method in ('put', 'post', 'patch', 'delete'):
resp = getattr(self.client, method)(url)
# method not allowed
self.assertEqual(resp.status_code, 405)