From 88ade2b69eebe934a2af2bb8126a73086660d9bc Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Wed, 13 Dec 2023 14:17:35 +0200 Subject: [PATCH 1/4] Add location questions to endline survey --- yal/endline_terms_and_conditions.py | 46 +++++++++++++- yal/tests/states_dictionary.md | 2 + yal/tests/test_endline_terms_and_condition.py | 60 +++++++++++++++++-- 3 files changed, 100 insertions(+), 8 deletions(-) diff --git a/yal/endline_terms_and_conditions.py b/yal/endline_terms_and_conditions.py index e649ac23..f976c44a 100644 --- a/yal/endline_terms_and_conditions.py +++ b/yal/endline_terms_and_conditions.py @@ -38,7 +38,7 @@ async def state_start_terms(self): "❓ You can skip any questions you don’t want to answer." " To try improve South Africa’s sexual health we need to " "ask a number of questions that may be sensitive; for instance," - " we ask about sexual behaviours,
sexual orientation and health" + " we ask about sexual behaviours,sexual orientation and health" " status, among other topics.", "", "🔒 You’ve seen and agreed to the BWise privacy policy." @@ -242,7 +242,7 @@ async def state_household_number_of_people(self): async def next_state(choice: Choice): if choice.value == "eight_more": return "state_household_number_of_people_eight_or_more" - return "state_submit_terms_and_conditions_endline" + return "state_location_province_endline" return WhatsAppListState( self, @@ -295,7 +295,7 @@ async def state_household_number_of_people_eight_or_more(self): question=question, error=error, choices=choices, - next="state_submit_terms_and_conditions_endline", + next="state_location_province_endline", button="Choose Option", ) @@ -332,6 +332,46 @@ async def state_set_reminder_timer(self): next=None, ) + async def state_location_province_endline(self): + question = "*What province do you live in?*" + + return WhatsAppListState( + self, + question=question, + button="Province", + choices=[ + Choice("EC", "Eastern Cape"), + Choice("FS", "Freestate"), + Choice("GT", "Gauteng"), + Choice("NL", "Kwazulu-Natal"), + Choice("LP", "Limpopo"), + Choice("MP", "Mpumalanga"), + Choice("NC", "Northern Cape"), + Choice("NW", "North-West"), + Choice("WC", "Western Cape"), + Choice("skip", "Skip question"), + ], + next="state_location_area_type_endline", + error=self._(get_generic_error()), + ) + + async def state_location_area_type_endline(self): + question = "*What type of area are you living in?*" + + return WhatsAppListState( + self, + question=question, + button="Area type", + choices=[ + Choice("traditional", "Traditional/chiefdom"), + Choice("urban", "Urban/town"), + Choice("farm", "Farm/rural"), + Choice("dont_understand", "I don't understand"), + ], + next="state_submit_terms_and_conditions_endline", + error=self._(get_generic_error()), + ) + async def state_submit_terms_and_conditions_endline(self): msisdn = normalise_phonenumber(self.inbound.from_addr) whatsapp_id = msisdn.lstrip(" + ") diff --git a/yal/tests/states_dictionary.md b/yal/tests/states_dictionary.md index b72e7d5e..8db6b506 100644 --- a/yal/tests/states_dictionary.md +++ b/yal/tests/states_dictionary.md @@ -254,6 +254,8 @@ | state_survey_validation | TRUE | Text | TRUE | endline survey catch all validation | | state_household_number_of_people | TRUE | Text | TRUE | Endline number of peopleing living in househould | | state_household_number_of_people_eight_or_more | TRUE | Text | TRUE | Endline number of peopleing living in househould if more than 8 people | +| state_location_province_endline | TRUE | Text | TRUE | Endline user province | +| state_location_area_type_endline | TRUE | Text | TRUE | Endline user area type | | state_notification_no_submit | FALSE | | | Updates opted_in with False | | state_notification_yes_submit | FALSE | | | Updates opted_in with True | | state_notification_yes_submit_done | TRUE | Text | TRUE | Displays success message and asks user what they want to do next | diff --git a/yal/tests/test_endline_terms_and_condition.py b/yal/tests/test_endline_terms_and_condition.py index c9ed7f36..d606c7cf 100644 --- a/yal/tests/test_endline_terms_and_condition.py +++ b/yal/tests/test_endline_terms_and_condition.py @@ -119,8 +119,9 @@ 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_household_number_of_people") + tester.setup_state("state_location_area_type_endline") await tester.user_input("1") + tester.assert_state("state_survey_question") assert len(rapidpro_mock.tstate.requests) == 3 request = rapidpro_mock.tstate.requests[0] @@ -133,10 +134,10 @@ async def test_state_submit_terms_and_conditions_accept( 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.* 😎"]) + # message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) - tester.assert_message(message) - tester.assert_state("state_survey_question") + # tester.assert_message(message) + tester.assert_state("state_location_province_endline") @pytest.mark.asyncio @@ -164,7 +165,56 @@ async def test_state_household_number_of_people_eight_or_more( ): tester.setup_state("state_household_number_of_people_eight_or_more") await tester.user_input("5") + # message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) + + # tester.assert_message(message) + tester.assert_state("state_location_province_endline") + + +@pytest.mark.asyncio +async def test_state_location_province_endline(tester: AppTester, rapidpro_mock): + tester.setup_state("state_household_number_of_people_eight_or_more") + await tester.user_input("5") + + tester.assert_state("state_location_province_endline") + tester.assert_message( + "*What province do you live in?*", + list_items=[ + "Eastern Cape", + "Freestate", + "Gauteng", + "Kwazulu-Natal", + "Limpopo", + "Mpumalanga", + "Northern Cape", + "North-West", + "Western Cape", + "Skip question", + ], + ) + + await tester.user_input("5") + tester.assert_state("state_location_area_type_endline") + +@pytest.mark.asyncio +async def test_state_location_area_type_endline(tester: AppTester, rapidpro_mock): + tester.setup_state("state_location_province_endline") + await tester.user_input("1") + + tester.assert_state("state_location_area_type_endline") + tester.assert_message( + "*What type of area are you living in?*", + list_items=[ + "Traditional/chiefdom", + "Urban/town", + "Farm/rural", + "I don't understand", + ], + ) + + await tester.user_input("1") + tester.assert_state("state_survey_question") + message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) tester.assert_message(message) - tester.assert_state("state_survey_question") From 9f6f08a5157c418c4b1c4dd1786f89455d48c4bb Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Wed, 13 Dec 2023 14:18:48 +0200 Subject: [PATCH 2/4] fix space --- yal/endline_terms_and_conditions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yal/endline_terms_and_conditions.py b/yal/endline_terms_and_conditions.py index f976c44a..36db565b 100644 --- a/yal/endline_terms_and_conditions.py +++ b/yal/endline_terms_and_conditions.py @@ -38,7 +38,7 @@ async def state_start_terms(self): "❓ You can skip any questions you don’t want to answer." " To try improve South Africa’s sexual health we need to " "ask a number of questions that may be sensitive; for instance," - " we ask about sexual behaviours,sexual orientation and health" + " we ask about sexual behaviours, sexual orientation and health" " status, among other topics.", "", "🔒 You’ve seen and agreed to the BWise privacy policy." From 5895e865913ea66cd491a7da116cdf3d69a4f5df Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Wed, 13 Dec 2023 14:21:59 +0200 Subject: [PATCH 3/4] remove comments --- yal/tests/test_endline_terms_and_condition.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/yal/tests/test_endline_terms_and_condition.py b/yal/tests/test_endline_terms_and_condition.py index d606c7cf..01cf9248 100644 --- a/yal/tests/test_endline_terms_and_condition.py +++ b/yal/tests/test_endline_terms_and_condition.py @@ -134,9 +134,7 @@ async def test_state_submit_terms_and_conditions_accept( 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_location_province_endline") @@ -165,9 +163,7 @@ async def test_state_household_number_of_people_eight_or_more( ): tester.setup_state("state_household_number_of_people_eight_or_more") await tester.user_input("5") - # message = "\n".join(["◼️◽️◽️◽️", "-----", "", "*I'm my own boss.* 😎"]) - # tester.assert_message(message) tester.assert_state("state_location_province_endline") From 737fdec54e85b3b0f4682eafa98b19f60576e585 Mon Sep 17 00:00:00 2001 From: Erik Harding Date: Wed, 13 Dec 2023 14:23:40 +0200 Subject: [PATCH 4/4] formatting --- yal/tests/test_endline_terms_and_condition.py | 1 + 1 file changed, 1 insertion(+) diff --git a/yal/tests/test_endline_terms_and_condition.py b/yal/tests/test_endline_terms_and_condition.py index 01cf9248..dcc757e4 100644 --- a/yal/tests/test_endline_terms_and_condition.py +++ b/yal/tests/test_endline_terms_and_condition.py @@ -192,6 +192,7 @@ async def test_state_location_province_endline(tester: AppTester, rapidpro_mock) await tester.user_input("5") tester.assert_state("state_location_area_type_endline") + @pytest.mark.asyncio async def test_state_location_area_type_endline(tester: AppTester, rapidpro_mock): tester.setup_state("state_location_province_endline")