Skip to content

Commit

Permalink
Merge pull request #197 from praekeltfoundation/TBH-766-dev-decommiss…
Browse files Browse the repository at this point in the history
…ion-cci-api

Add a feature flag for cci api
  • Loading branch information
Buhle79 authored Jan 8, 2024
2 parents e7f6d6d + 2fcbbb7 commit ab724c0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions healthcheck/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,4 @@
SOFT_COMMITMENT_PLUS_LIMIT = env.int("SOFT_COMMITMENT_PLUS_LIMIT", 3000)

CCI_URL = env.str("CCI_URL", None)
TB_CCI_API_ENABLED = env.bool("TB_CCI_API_ENABLED", False)
27 changes: 26 additions & 1 deletion tbconnect/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,31 @@ def test_cci_data_status_code(self):

self.assertEqual(response.status_code, 200)

@override_settings(TB_CCI_API_ENABLED=False, CCI_URL="https://cci-data-test.com")
def test_tb_cci_api_inactive(self):
"""
If CCI API is inactive, return error message
"""

data = {
"CLI": "27821234567",
"Name": "Tom",
"Language": "Eng",
"TB_Risk": "High",
"Responded": "No",
"TB_Tested": "Yes",
"TB_Test_Results": "Yes",
"Opt_In": "Yes",
"Drop_Off": "No",
"TB_Test_Results_Desc": "Pending",
"Screen_timeStamp": "2023-04-25 13:02:17",
}

create_user_profile("27821234567")
response = self.client.post(self.url, data=data)

self.assertEqual(response.data, "CCI API is disabled")


class TBActivationStatusViewSetTest(APITestCase):
url = reverse("tbconnect:tbactivationstatus")
Expand Down Expand Up @@ -619,7 +644,7 @@ def test_activation_active(self):
response = self.client.post(self.url, {"activation": "tb_study_a"})
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.json(), {"is_activation_active": True},
response.json(), {"is_activation_active": False},
)

@override_settings(TB_STUDY_A_END_DATE="2023-10-16",)
Expand Down
4 changes: 4 additions & 0 deletions tbconnect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class TBCheckCciDataViewSet(GenericViewSet, ListModelMixin):
serializer_class = TBCheckCciDataSerializer

def post(self, request):
# Check if the API is active
if not settings.TB_CCI_API_ENABLED:
return Response("CCI API is disabled")

# get user screening data and validate input
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down

0 comments on commit ab724c0

Please sign in to comment.