From ceeac95d6aad62b93a5648e536282f432270a8ce Mon Sep 17 00:00:00 2001 From: Buhle Date: Tue, 27 Jun 2023 09:48:32 +0200 Subject: [PATCH] Check if service finder is active to show it on ask a question --- yal/askaquestion.py | 22 +++++++++++++++++----- yal/tests/test_askaquestion.py | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/yal/askaquestion.py b/yal/askaquestion.py index 316c2a82..3eb4688d 100644 --- a/yal/askaquestion.py +++ b/yal/askaquestion.py @@ -464,9 +464,24 @@ async def state_no_question_not_answered(self): async def state_no_question_not_answered_thank_you(self): choices = [ - Choice("clinic", self._("Find a clinic")), Choice("counsellor", self._("Talk to a counsellor")), ] + + next = { + "counsellor": PleaseCallMeApplication.START_STATE, + } + + if (await rapidpro.check_if_service_finder_active()).lower() == "true": + choices = [ + Choice("clinic", self._("Find a clinic")), + Choice("counsellor", self._("Talk to a counsellor")), + ] + + next = { + "clinic": ServiceFinderApplication.START_STATE, + "counsellor": PleaseCallMeApplication.START_STATE, + } + question = self._( "\n".join( [ @@ -490,10 +505,7 @@ async def state_no_question_not_answered_thank_you(self): question=question, choices=choices, error=self._(get_generic_error()), - next={ - "clinic": ServiceFinderApplication.START_STATE, - "counsellor": PleaseCallMeApplication.START_STATE, - }, + next=next, ) async def state_handle_list_timeout(self): diff --git a/yal/tests/test_askaquestion.py b/yal/tests/test_askaquestion.py index 73ea2d3f..e9230786 100644 --- a/yal/tests/test_askaquestion.py +++ b/yal/tests/test_askaquestion.py @@ -120,6 +120,26 @@ def update_contact(request): tstate.requests.append(request) return response.json({}, status=200) + @app.route("/api/v2/globals.json", methods=["GET"]) + def check_if_service_finder_active(request): + tstate.requests.append(request) + assert request.args.get("key") == "service_finder_active" + return response.json( + { + "next": None, + "previous": None, + "results": [ + { + "key": "service_finder_active", + "name": "Survice Finder Active", + "value": "True", + "modified_on": "2023-05-30T07:34:06.216776Z", + } + ], + }, + status=200, + ) + async with run_sanic(app) as server: url = config.RAPIDPRO_URL config.RAPIDPRO_URL = f"http://{server.host}:{server.port}" @@ -625,7 +645,7 @@ async def test_state_handle_timeout_handles_type_1_no(tester: AppTester, rapidpr tester.setup_state("state_handle_timeout_response") await tester.user_input("no, I'm good") - assert len(rapidpro_mock.tstate.requests) == 4 + assert len(rapidpro_mock.tstate.requests) == 5 request = rapidpro_mock.tstate.requests[1] assert json.loads(request.body.decode("utf-8")) == { "fields": {"feedback_survey_sent": "", "feedback_timestamp": ""},