Skip to content

Commit

Permalink
feat: Add onadata version to the status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankApiyo committed Feb 23, 2024
1 parent e8290d5 commit 952731b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion onadata/apps/main/tests/test_service_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from onadata.apps.main.tests.test_base import TestBase
from onadata.apps.main.views import service_health
import onadata


class TestServiceHealthView(TestBase):
Expand All @@ -20,7 +21,11 @@ def test_service_health(self):
self.assertEqual(resp.status_code, 200)
self.assertEqual(
json.loads(resp.content.decode("utf-8")),
{"default-Database": "OK", "Cache-Service": "OK"},
{
"default-Database": "OK",
"Cache-Service": "OK",
"onadata-version": onadata.__version__,
},
)

sql_statement_with_error = "SELECT id FROM non_existent_table limit 1;"
Expand All @@ -30,6 +35,7 @@ def test_service_health(self):
self.assertEqual(resp.status_code, 500)
response_json = json.loads(resp.content.decode("utf-8"))
self.assertEqual(response_json["Cache-Service"], "OK")
self.assertEqual(response_json["onadata-version"], onadata.__version__)
self.assertEqual(
response_json["default-Database"][:111],
(
Expand Down
7 changes: 6 additions & 1 deletion onadata/apps/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
set_profile_data,
)
from onadata.libs.utils.viewer_tools import get_enketo_urls, get_form
import onadata

# pylint: disable=invalid-name
User = get_user_model()
Expand Down Expand Up @@ -1576,6 +1577,11 @@ def service_health(request):
else:
service_statuses["Cache-Service"] = "OK"

if onadata.__version__:
service_statuses["onadata-version"] = onadata.__version__
else:
service_statuses["onadata-version"] = "Unable to find onadata version"

return JsonResponse(
service_statuses,
status=HTTPStatus.INTERNAL_SERVER_ERROR if service_degraded else HTTPStatus.OK,
Expand All @@ -1599,7 +1605,6 @@ def username_list(request):

# pylint: disable=too-few-public-methods
class OnaAuthorizationView(AuthorizationView):

"""
Overrides the AuthorizationView provided by oauth2_provider
and adds the user to the context
Expand Down

0 comments on commit 952731b

Please sign in to comment.