From b7a6bbb3384a545155ad6bd1be68e80a098ce123 Mon Sep 17 00:00:00 2001 From: RuthShryock Date: Tue, 12 Dec 2023 15:01:52 -0500 Subject: [PATCH 1/5] adding health endpoint for kobocat --- onadata/apps/main/service_health.py | 2 ++ .../main/tests/test_service_health_minimal.py | 18 ++++++++++++++++++ onadata/apps/main/urls.py | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 onadata/apps/main/tests/test_service_health_minimal.py diff --git a/onadata/apps/main/service_health.py b/onadata/apps/main/service_health.py index ebbda26a7..1e79f76a7 100644 --- a/onadata/apps/main/service_health.py +++ b/onadata/apps/main/service_health.py @@ -48,3 +48,5 @@ def service_health(request): output, status=(500 if any_failure else 200), content_type='text/plain' ) +def service_health_minimal(request): + return HttpResponse("ok", content_type="text/plain") diff --git a/onadata/apps/main/tests/test_service_health_minimal.py b/onadata/apps/main/tests/test_service_health_minimal.py new file mode 100644 index 000000000..f57fc0d7e --- /dev/null +++ b/onadata/apps/main/tests/test_service_health_minimal.py @@ -0,0 +1,18 @@ +from django.test import TestCase +from django.urls import reverse + + +class ServiceHealthMinimalTestCase(TestCase): + url = reverse('service-health-minimal') + + def test_service_health_minimal(self): + res = self.client.get(self.url) + self.assertEqual(res.status_code, 200) + + # Check that the response content is "ok" + expected_content = 'ok' + actual_content = res.content.decode('utf-8') + self.assertEqual(actual_content, expected_content) + + # Ensure that no database queries were executed + self.assertNumQueries(0) \ No newline at end of file diff --git a/onadata/apps/main/urls.py b/onadata/apps/main/urls.py index 11869ae1d..8c575a0d1 100644 --- a/onadata/apps/main/urls.py +++ b/onadata/apps/main/urls.py @@ -11,7 +11,7 @@ from onadata.apps.api.urls import XFormListApi from onadata.apps.api.urls import XFormSubmissionApi from onadata.apps.api.urls import router, router_with_patch_list -from onadata.apps.main.service_health import service_health +from onadata.apps.main.service_health import service_health, service_health_minimal # exporting stuff from onadata.apps.viewer.views import ( @@ -38,6 +38,7 @@ re_path('^api/v1/', include(router.urls)), re_path('^api/v1/', include(router_with_patch_list.urls)), re_path(r'^service_health/$', service_health), + re_path(r'^service_health/minimal/$', service_health_minimal, name='service-health-minimal'), re_path(r'^api/', RedirectView.as_view(url='/api/v1/')), re_path(r'^api/v1', RedirectView.as_view(url='/api/v1/')), From cf46e87e9da81d03e0b55a40ae98f95ae46401eb Mon Sep 17 00:00:00 2001 From: RuthShryock Date: Tue, 12 Dec 2023 15:03:40 -0500 Subject: [PATCH 2/5] adding line --- onadata/apps/main/tests/test_service_health_minimal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/onadata/apps/main/tests/test_service_health_minimal.py b/onadata/apps/main/tests/test_service_health_minimal.py index f57fc0d7e..bb81bc28b 100644 --- a/onadata/apps/main/tests/test_service_health_minimal.py +++ b/onadata/apps/main/tests/test_service_health_minimal.py @@ -15,4 +15,5 @@ def test_service_health_minimal(self): self.assertEqual(actual_content, expected_content) # Ensure that no database queries were executed - self.assertNumQueries(0) \ No newline at end of file + self.assertNumQueries(0) + \ No newline at end of file From 33f71da080b048612a7e0251217efd6b4f211ec9 Mon Sep 17 00:00:00 2001 From: RuthShryock Date: Tue, 12 Dec 2023 16:35:36 -0500 Subject: [PATCH 3/5] switching to use path() instead of re_path() --- onadata/apps/main/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/onadata/apps/main/urls.py b/onadata/apps/main/urls.py index 8c575a0d1..995985af1 100644 --- a/onadata/apps/main/urls.py +++ b/onadata/apps/main/urls.py @@ -2,7 +2,7 @@ from django.conf import settings from django.contrib import admin -from django.urls import include, re_path +from django.urls import include, re_path, path from django.views.generic import RedirectView from django.views.i18n import JavaScriptCatalog @@ -38,7 +38,7 @@ re_path('^api/v1/', include(router.urls)), re_path('^api/v1/', include(router_with_patch_list.urls)), re_path(r'^service_health/$', service_health), - re_path(r'^service_health/minimal/$', service_health_minimal, name='service-health-minimal'), + path(r'^service_health/minimal/$', service_health_minimal, name='service-health-minimal'), re_path(r'^api/', RedirectView.as_view(url='/api/v1/')), re_path(r'^api/v1', RedirectView.as_view(url='/api/v1/')), From bef5f45bec69c2b0cc3c8820eaabbc426aae4719 Mon Sep 17 00:00:00 2001 From: RuthShryock Date: Wed, 13 Dec 2023 10:33:14 -0500 Subject: [PATCH 4/5] updating tests --- .../main/tests/test_service_health_minimal.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/onadata/apps/main/tests/test_service_health_minimal.py b/onadata/apps/main/tests/test_service_health_minimal.py index bb81bc28b..f4d49eed4 100644 --- a/onadata/apps/main/tests/test_service_health_minimal.py +++ b/onadata/apps/main/tests/test_service_health_minimal.py @@ -3,17 +3,11 @@ class ServiceHealthMinimalTestCase(TestCase): - url = reverse('service-health-minimal') + url = reverse("service-health-minimal") def test_service_health_minimal(self): - res = self.client.get(self.url) - self.assertEqual(res.status_code, 200) + with self.assertNumQueries(0): + res = self.client.get(self.url) - # Check that the response content is "ok" - expected_content = 'ok' - actual_content = res.content.decode('utf-8') - self.assertEqual(actual_content, expected_content) - - # Ensure that no database queries were executed - self.assertNumQueries(0) - \ No newline at end of file + # Check that the response content contains "ok" + self.assertContains(res, "ok") From e28448528848e047fa7359bfb36b3d84f441f13b Mon Sep 17 00:00:00 2001 From: RuthShryock Date: Thu, 8 Feb 2024 18:17:29 +0100 Subject: [PATCH 5/5] removing anchors from path() --- onadata/apps/main/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/onadata/apps/main/urls.py b/onadata/apps/main/urls.py index 995985af1..cbf7e6195 100644 --- a/onadata/apps/main/urls.py +++ b/onadata/apps/main/urls.py @@ -38,7 +38,7 @@ re_path('^api/v1/', include(router.urls)), re_path('^api/v1/', include(router_with_patch_list.urls)), re_path(r'^service_health/$', service_health), - path(r'^service_health/minimal/$', service_health_minimal, name='service-health-minimal'), + path(r'service_health/minimal/', service_health_minimal, name='service-health-minimal'), re_path(r'^api/', RedirectView.as_view(url='/api/v1/')), re_path(r'^api/v1', RedirectView.as_view(url='/api/v1/')),