From 0f7615fad2684f88cd404b50fd2286aa35b1a8ba Mon Sep 17 00:00:00 2001 From: Hlamalani Date: Tue, 8 Aug 2023 15:52:24 +0200 Subject: [PATCH] add new locus questions --- yal/endline_terms_and_conditions.py | 93 +++++++++++++++++++ yal/tests/states_dictionary.md | 2 + yal/tests/test_endline_terms_and_condition.py | 58 +++++++++++- 3 files changed, 150 insertions(+), 3 deletions(-) diff --git a/yal/endline_terms_and_conditions.py b/yal/endline_terms_and_conditions.py index c75ec1ea..2290730d 100644 --- a/yal/endline_terms_and_conditions.py +++ b/yal/endline_terms_and_conditions.py @@ -193,6 +193,99 @@ async def state_monthly_household_income_endline(self): ] ) ) + return ChoiceState( + self, + question=question, + error=error, + choices=choices, + next="state_household_number_of_people", + ) + + async def state_household_number_of_people(self): + choices = [ + Choice("one", self._("Just me")), + Choice("two", self._("Two people")), + Choice("three", self._("Three people")), + Choice("four", self._("Four people")), + Choice("five", self._("Five people")), + Choice("six", self._("Six people")), + Choice("seven", self._("Seven people")), + Choice("eight_more", self._("Eight or more")), + Choice("rather", "Rather not say"), + Choice("skip_question", self._("Skip question")), + ] + + question = self._( + "\n".join( + [ + "*How many people (including yourself) live in the household now?" + " Don’t forget to include babies.*", + "", + "(If you’re unsure - this counts as anyone sleeping the house" + "4 nights in the past week).", + ] + ) + ) + error = self._( + "\n".join( + [ + "*Oops. We did not understand your answer*", + "Please respond with the *number* of an option below", + "", + "How many people (including yourself) live in the household now?", + ] + ) + ) + + next = "state_submit_terms_and_conditions_endline" + + if choices[0].value == "eight_more": + next = "state_household_number_of_people_more" + + return ChoiceState( + self, + question=question, + error=error, + choices=choices, + next=next, + ) + + async def state_household_number_of_people_eight_or_more(self): + choices = [ + Choice("eight", self._("Including me")), + Choice("nine", self._("Nine people")), + Choice("ten", self._("Ten people")), + Choice("eleven", self._("Eleven people")), + Choice("twelve", self._("Twelve people")), + Choice("thirteen", self._("Thirteen people")), + Choice("fourteen", self._("Fourteen people")), + Choice("fifteen", self._("Fifteen people")), + Choice("rather", "Rather not say"), + Choice("skip_question", self._("Skip question")), + ] + + question = self._( + "\n".join( + [ + "*Okay - you said there are 8 or more people in your household.*", + "*How many people (including yourself) live in the household now?" + " Don’t forget to include babies.*", + "(If you’re unsure - this counts as anyone sleeping the house" + "4 nights in the past week).", + ] + ) + ) + error = self._( + "\n".join( + [ + "*Oops. We did not understand your answer*", + "Please respond with the *number* of an option below", + "", + "How many people (including yourself) live in the household now?", + ] + ) + ) + return ChoiceState( self, question=question, diff --git a/yal/tests/states_dictionary.md b/yal/tests/states_dictionary.md index b9bbb631..a7cce65b 100644 --- a/yal/tests/states_dictionary.md +++ b/yal/tests/states_dictionary.md @@ -252,6 +252,8 @@ | state_remind_tomorrow | TRUE | Text | TRUE | Lets the user know we will remind them tomorrow, asks the user if they would like to go to the mainmenu | | state_reminder_not_interested | True | Text | TRUE | Lets the user know that they will no longer be prt of the study | | state_survey_validation | True | Text | TRUE | endline survey catch all validation | + state_household_number_of_people | False | Text | Endline number of peopleing living in househould | +| state_household_number_of_people_eight_or_more | False | Text | Endline number of peopleing living in househould if more than 8 people | ### Service finder flow diff --git a/yal/tests/test_endline_terms_and_condition.py b/yal/tests/test_endline_terms_and_condition.py index 7a8ca44c..81ab7fd6 100644 --- a/yal/tests/test_endline_terms_and_condition.py +++ b/yal/tests/test_endline_terms_and_condition.py @@ -78,9 +78,29 @@ async def test_state_monthly_household_income_endline(tester: AppTester, rapidpr tester.setup_state("state_monthly_household_income_endline") await tester.user_input("1") - tester.assert_state("state_survey_question") + tester.assert_state("state_household_number_of_people") + + message = "\n".join( + [ + "*How many people (including yourself) live in the household now?" + " Don’t forget to include babies.*", + "", + "(If you’re unsure - this counts as anyone sleeping the house" + "4 nights in the past week).", + "1. Just me", + "2. Two people", + "3. Three people", + "4. Four people", + "5. Five people", + "6. Six people", + "7. Seven people", + "8. Eight or more", + "9. Rather not say", + "10. Skip question", + ] + ) + tester.assert_message(message) - message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) tester.assert_message(message) @@ -111,7 +131,7 @@ async def test_state_accept_consent_reminder(tester: AppTester, rapidpro_mock): async def test_state_submit_terms_and_conditions_accept( tester: AppTester, rapidpro_mock ): - tester.setup_state("state_monthly_household_income_endline") + tester.setup_state("state_household_number_of_people") await tester.user_input("1") assert len(rapidpro_mock.tstate.requests) == 3 @@ -119,3 +139,35 @@ async def test_state_submit_terms_and_conditions_accept( assert json.loads(request.body.decode("utf-8")) == { "fields": {"endline_terms_accepted": "True"}, } + + +@pytest.mark.asyncio +async def test_state_household_number_of_people(tester: AppTester, rapidpro_mock): + tester.setup_state("state_household_number_of_people") + await tester.user_input("2") + message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) + + tester.assert_message(message) + tester.assert_state("state_survey_question") + + +@pytest.mark.asyncio +async def test_state_household_number_of_people_more(tester: AppTester, rapidpro_mock): + tester.setup_state("state_household_number_of_people") + await tester.user_input("7") + message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) + + tester.assert_message(message) + tester.assert_state("state_survey_question") + + +@pytest.mark.asyncio +async def test_state_household_number_of_people_eight_or_more( + tester: AppTester, rapidpro_mock +): + tester.setup_state("state_household_number_of_people_eight_or_more") + await tester.user_input("1") + message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) + + tester.assert_message(message) + tester.assert_state("state_survey_question")