-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #670 from praekeltfoundation/location-survey
Add missing loccation survey states
- Loading branch information
Showing
4 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import asyncio | ||
|
||
from vaccine.base_application import BaseApplication | ||
from vaccine.states import ( | ||
Choice, | ||
|
@@ -7,7 +9,7 @@ | |
WhatsAppListState, | ||
) | ||
from vaccine.validators import nonempty_validator | ||
from yal import rapidpro | ||
from yal import contentrepo, rapidpro | ||
from yal.askaquestion import Application as AAQApplication | ||
from yal.change_preferences import Application as ChangePreferencesApplication | ||
from yal.utils import get_generic_error, normalise_phonenumber | ||
|
@@ -75,7 +77,11 @@ async def state_location_introduction(self): | |
question=question, | ||
choices=choices, | ||
error=self._(get_generic_error()), | ||
next={"yes": "state_location_province", "no": "TODO", "question": "TODO"}, | ||
next={ | ||
"yes": "state_location_province", | ||
"no": "state_location_decline", | ||
"question": "state_send_consent_pdf", | ||
}, | ||
) | ||
|
||
async def state_location_not_invited(self): | ||
|
@@ -95,6 +101,53 @@ async def state_location_already_completed(self): | |
next=self.START_STATE, | ||
) | ||
|
||
async def state_location_decline(self): | ||
return EndState( | ||
self, | ||
self._( | ||
"That's completely okay, there are no consequences to not taking part " | ||
"in this study. Please enjoy the BWise tool and stay safe." | ||
), | ||
next=self.START_STATE, | ||
) | ||
|
||
async def state_send_consent_pdf(self): | ||
await self.worker.publish_message( | ||
self.inbound.reply( | ||
None, | ||
helper_metadata={"document": contentrepo.get_privacy_policy_url()}, | ||
) | ||
) | ||
await asyncio.sleep(1.5) | ||
return await self.go_to_state("state_location_question") | ||
|
||
async def state_location_question(self): | ||
async def _next(choice: Choice): | ||
if choice.value == "decline": | ||
return "state_location_decline" | ||
return "state_location_province" | ||
|
||
return WhatsAppButtonState( | ||
self, | ||
question=self._( | ||
"\n".join( | ||
[ | ||
"You should be able to find the answer to any questions you " | ||
"have in the consent doc we sent you. If you still have " | ||
"questions, please email [email protected]", | ||
"", | ||
"Would you like to continue?", | ||
] | ||
) | ||
), | ||
choices=[ | ||
Choice("continue", "Continue"), | ||
Choice("decline", "No, thank you"), | ||
], | ||
next=_next, | ||
error=self._(get_generic_error()), | ||
) | ||
|
||
async def state_location_province(self): | ||
async def _next(choice: Choice): | ||
if choice.value == "other": | ||
|
@@ -219,6 +272,7 @@ async def state_location_update_status(self): | |
return await self.go_to_state("state_location_end") | ||
|
||
async def state_location_end(self): | ||
# TODO: handle the don't understand branch | ||
question = self._( | ||
"\n".join( | ||
[ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,10 +136,65 @@ async def test_state_location_introduction_pending(tester: AppTester): | |
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_state_location_decline(tester: AppTester): | ||
tester.setup_state("state_location_introduction") | ||
await tester.user_input("2") | ||
|
||
tester.assert_state("state_start") | ||
tester.assert_message( | ||
"That's completely okay, there are no consequences to not taking part in this " | ||
"study. Please enjoy the BWise tool and stay safe." | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_state_location_question(tester: AppTester): | ||
tester.setup_state("state_location_introduction") | ||
await tester.user_input("3") | ||
|
||
tester.assert_state("state_location_question") | ||
tester.assert_message( | ||
"\n".join( | ||
[ | ||
"You should be able to find the answer to any questions you have in " | ||
"the consent doc we sent you. If you still have questions, please " | ||
"email [email protected]", | ||
"", | ||
"Would you like to continue?", | ||
] | ||
) | ||
) | ||
|
||
[msg] = tester.fake_worker.outbound_messages | ||
assert msg.helper_metadata == { | ||
"document": "https://contenrepo/documents/1/sample.pdf" | ||
} | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_state_location_question_continue(tester: AppTester): | ||
tester.setup_state("state_location_question") | ||
await tester.user_input("1") | ||
|
||
tester.assert_state("state_location_province") | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_state_location_question_decline(tester: AppTester): | ||
tester.setup_state("state_location_question") | ||
await tester.user_input("2") | ||
|
||
tester.assert_state("state_start") | ||
tester.assert_message( | ||
"That's completely okay, there are no consequences to not taking part in this " | ||
"study. Please enjoy the BWise tool and stay safe." | ||
) | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_state_location_province(tester: AppTester): | ||
tester.setup_state("state_location_introduction") | ||
tester.user.metadata["ejaf_location_survey_status"] = "pending" | ||
await tester.user_input("1") | ||
|
||
tester.assert_state("state_location_province") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters