-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2097 from onaio/2053-health-check-endpoint
Add `service_health` view function
- Loading branch information
Showing
9 changed files
with
135 additions
and
5 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
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 |
---|---|---|
|
@@ -108,6 +108,7 @@ editor | |
ei | ||
end | ||
enketo | ||
f | ||
fag | ||
faq | ||
|
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,40 @@ | ||
import json | ||
from django.http import HttpRequest | ||
from django.db.utils import DatabaseError | ||
from mock import patch | ||
|
||
from onadata.apps.main.tests.test_base import TestBase | ||
from onadata.apps.main.views import service_health | ||
|
||
|
||
class TestServiceHealthView(TestBase): | ||
def test_service_health(self): | ||
""" | ||
Test that the `service_health` view function | ||
works as expected: | ||
1. Returns a 200 when secondary services are healthy | ||
2. Returns a 500 when a secondary service is not available | ||
""" | ||
req = HttpRequest() | ||
resp = service_health(req) | ||
|
||
self.assertEqual(resp.status_code, 200) | ||
self.assertEqual( | ||
json.loads(resp.content.decode('utf-8')), | ||
{ | ||
'default-Database': 'OK', | ||
'Cache-Service': 'OK' | ||
}) | ||
|
||
with patch('onadata.apps.main.views.XForm') as xform_mock: | ||
xform_mock.objects.using().first.side_effect = DatabaseError( | ||
'Some database error') | ||
resp = service_health(req) | ||
|
||
self.assertEqual(resp.status_code, 500) | ||
self.assertEqual( | ||
json.loads(resp.content.decode('utf-8')), | ||
{ | ||
'default-Database': 'Degraded state; Some database error', | ||
'Cache-Service': 'OK' | ||
}) |
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
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
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
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
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
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