-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move health check tests to unit test (#1172)
* BB2-3081 Move health check tests to unit test
- Loading branch information
1 parent
3a78624
commit 0e64ece
Showing
2 changed files
with
157 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import json | ||
|
||
from django.test.client import Client | ||
from httmock import HTTMock, all_requests | ||
from apps.test import BaseApiTest | ||
|
||
|
||
class TestHealthchecks(BaseApiTest): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
self.url = "http://localhost" | ||
|
||
@all_requests | ||
def catchall(url, req, params): | ||
return { | ||
'status_code': 200, | ||
'content': '{"test": 1}', # bfd check looks for json for success | ||
} | ||
|
||
def test_health_external(self): | ||
self._call_health_external_endpoint(False) | ||
|
||
def test_health_external_endpoint_v2(self): | ||
self._call_health_external_endpoint(True) | ||
|
||
def _call_health_external_endpoint(self, v2=False): | ||
with HTTMock(self.catchall): | ||
response = self.client.get(self.url + "/health/external_v2" if v2 else "/health/external") | ||
self.assertEqual(response.status_code, 200) | ||
content = json.loads(response.content) | ||
msg = None | ||
try: | ||
msg = content['message'] | ||
except KeyError: | ||
pass | ||
self.assertEqual(msg, "all's well") | ||
|
||
def test_health_bfd_endpoint(self): | ||
self._call_health_bfd_endpoint(False) | ||
|
||
def test_health_bfd_endpoint_v2(self): | ||
self._call_health_bfd_endpoint(True) | ||
|
||
def _call_health_bfd_endpoint(self, v2=False): | ||
with HTTMock(self.catchall): | ||
response = self.client.get(self.url + "/health/bfd_v2" if v2 else "/health/bfd") | ||
self.assertEqual(response.status_code, 200) | ||
content = json.loads(response.content) | ||
msg = None | ||
try: | ||
msg = content['message'] | ||
except KeyError: | ||
pass | ||
self.assertEqual(msg, "all's well") | ||
|
||
def test_health_db_endpoint(self): | ||
response = self.client.get(self.url + "/health/db") | ||
self.assertEqual(response.status_code, 200) | ||
content = json.loads(response.content) | ||
msg = None | ||
try: | ||
msg = content['message'] | ||
except KeyError: | ||
pass | ||
self.assertEqual(msg, "all's well") | ||
|
||
def test_health_sls_endpoint(self): | ||
with HTTMock(self.catchall): | ||
response = self.client.get(self.url + "/health/sls") | ||
self.assertEqual(response.status_code, 200) | ||
content = json.loads(response.content) | ||
msg = None | ||
try: | ||
msg = content['message'] | ||
except KeyError: | ||
pass | ||
self.assertEqual(msg, "all's well") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters