Skip to content

Commit

Permalink
Merge pull request #634 from praekeltfoundation/YAL-933-yal-whatsapp-…
Browse files Browse the repository at this point in the history
…bot-prd-27-key-error

Check if service finder is active to show it on ask a question
  • Loading branch information
Buhle79 authored Jun 27, 2023
2 parents b9cdea4 + ceeac95 commit 597aace
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
22 changes: 17 additions & 5 deletions yal/askaquestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
[
Expand All @@ -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):
Expand Down
22 changes: 21 additions & 1 deletion yal/tests/test_askaquestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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": ""},
Expand Down

0 comments on commit 597aace

Please sign in to comment.