Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add location questions to endline survey #723

Merged
merged 4 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions yal/endline_terms_and_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
)

Expand Down Expand Up @@ -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(" + ")
Expand Down
2 changes: 2 additions & 0 deletions yal/tests/states_dictionary.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
57 changes: 52 additions & 5 deletions yal/tests/test_endline_terms_and_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -133,10 +134,8 @@ 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_survey_question")
tester.assert_state("state_location_province_endline")


@pytest.mark.asyncio
Expand Down Expand Up @@ -164,7 +163,55 @@ 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")

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")
Loading