async def test_post_risk_prompts_high_risk(self): form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = Tracker("", {}, None, [], False, None, None, None) form.send_post_risk_prompts(dispatcher, "high", tracker) assert dispatcher.messages == []
async def test_post_risk_prompts_low_risk(self): form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = Tracker("", {}, None, [], False, None, None, None) form.send_post_risk_prompts(dispatcher, "low", tracker) [prompt_low1, prompt_low2] = dispatcher.messages assert prompt_low1["template"] == "utter_tb_prompt_low_risk_1" assert prompt_low2["template"] == "utter_tb_prompt_low_risk_2"
async def test_post_risk_prompts_moderate_risk_fever(self): form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = Tracker("", {"symptoms_fever": "yes"}, None, [], False, None, None, None) form.send_post_risk_prompts(dispatcher, "moderate", tracker) [prompt_fever, prompt_moderate] = dispatcher.messages assert prompt_fever["template"] == "utter_tb_prompt_fever" assert prompt_moderate["template"] == "utter_tb_prompt_moderate"
async def test_validate_yes_no_maybe(self): """ Tests that yes no maybe slots validate correctly """ form = HealthCheckForm() for slot in ["exposure"]: tracker = self.get_tracker_for_text_slot_with_message(slot, "yes") events = await form.validate(CollectingDispatcher(), tracker, {}) assert events == [ SlotSet(slot, "yes"), ] tracker = self.get_tracker_for_text_slot_with_message(slot, "no") events = await form.validate(CollectingDispatcher(), tracker, {}) assert events == [ SlotSet(slot, "no"), ] tracker = self.get_tracker_for_text_slot_with_message( slot, "not sure") events = await form.validate(CollectingDispatcher(), tracker, {}) assert events == [ SlotSet(slot, "not sure"), ] tracker = self.get_tracker_for_text_slot_with_message( slot, "Invalid") dispatcher = CollectingDispatcher() events = await form.validate(dispatcher, tracker, {}) assert events == [ SlotSet(slot, None), ] [message] = dispatcher.messages assert message["template"] == "utter_incorrect_selection"
async def test_validate_yes_no(self): """ Tests that yes no slots validate correctly """ form = HealthCheckForm() for slot in [ "symptoms_fever", "symptoms_cough", "symptoms_sore_throat", "symptoms_difficulty_breathing", "symptoms_taste_smell", "tracing", ]: tracker = self.get_tracker_for_text_slot_with_message(slot, "yes") events = await form.validate(CollectingDispatcher(), tracker, {}) assert events == [ SlotSet(slot, "yes"), ] tracker = self.get_tracker_for_text_slot_with_message(slot, "no") events = await form.validate(CollectingDispatcher(), tracker, {}) assert events == [ SlotSet(slot, "no"), ] tracker = self.get_tracker_for_text_slot_with_message( slot, "Invalid") dispatcher = CollectingDispatcher() events = await form.validate(dispatcher, tracker, {}) assert events == [ SlotSet(slot, None), ] [message] = dispatcher.messages assert message["template"] == "utter_incorrect_selection"
def test_required_slots_end(self): """ If there are no more slots to fill, should return an empty list """ form = HealthCheckForm() tracker = utils.get_tracker_for_number_slot_with_value( form, "age", "1", { "symptoms_fever": "no", "symptoms_cough": "no", "symptoms_sore_throat": "no", "symptoms_difficulty_breathing": "no", "symptoms_taste_smell": "no", "exposure": "no", "tracing": "yes", }, ) assert form.required_slots(tracker) == []
async def test_submit_to_eventstore_study_a(self): """ Submits the data to the eventstore in the correct format """ base.actions.actions.config.EVENTSTORE_URL = "https://eventstore" base.actions.actions.config.EVENTSTORE_TOKEN = "token" respx.post( "https://eventstore/api/v5/covid19triage/", content={"profile": { "hcs_study_a_arm": "T1" }}, ) form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = utils.get_tracker_for_slot_from_intent( form, "tracing", "affirm", { "province": "wc", "age": "18-39", "symptoms_fever": "no", "symptoms_cough": "no", "symptoms_sore_throat": "yes", "symptoms_difficulty_breathing": "no", "symptoms_taste_smell": "no", "exposure": "yes", "tracing": "yes", "gender": "RATHER NOT SAY", "medical_condition": "not sure", "city_location_coords": "+1.2-3.4", "location_coords": "+3.4-1.2", "location": "Cape Town, South Africa", }, ) actions = await form.submit(dispatcher, tracker, {}) base.actions.actions.config.EVENTSTORE_URL = None base.actions.actions.config.EVENTSTORE_TOKEN = None [risk_message] = dispatcher.messages assert risk_message["template"] == "utter_risk_high" assert actions == [SlotSet("study_a_arm", "T1")]
async def test_submit_to_eventstore_retries(self): """ Should retry on HTTP failures """ base.actions.actions.config.EVENTSTORE_URL = "https://eventstore" base.actions.actions.config.EVENTSTORE_TOKEN = "token" request = respx.post("https://eventstore/api/v5/covid19triage/", status_code=500) form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = utils.get_tracker_for_slot_from_intent( form, "tracing", "affirm", { "province": "wc", "age": "18-39", "symptoms_fever": "no", "symptoms_cough": "no", "symptoms_sore_throat": "yes", "symptoms_difficulty_breathing": "no", "symptoms_taste_smell": "no", "exposure": "not sure", "tracing": "yes", "gender": "RATHER NOT SAY", "medical_condition": "not sure", "city_location_coords": "+1.2-3.4", "location_coords": "+3.4-1.2", "location": "Cape Town, South Africa", }, ) error = None try: await form.submit(dispatcher, tracker, {}) except httpx.HTTPError as e: error = e assert error assert len(request.calls) == 3 base.actions.actions.config.EVENTSTORE_URL = None base.actions.actions.config.EVENTSTORE_TOKEN = None
async def test_submit_to_eventstore(self): """ Submits the data to the eventstore in the correct format """ base.actions.actions.config.EVENTSTORE_URL = "https://eventstore" base.actions.actions.config.EVENTSTORE_TOKEN = "token" request = respx.post("https://eventstore/api/v5/covid19triage/", content={}) form = HealthCheckForm() dispatcher = CollectingDispatcher() tracker = utils.get_tracker_for_slot_from_intent( form, "tracing", "affirm", { "province": "wc", "age": "18-39", "symptoms_fever": "no", "symptoms_cough": "no", "symptoms_sore_throat": "yes", "symptoms_difficulty_breathing": "no", "symptoms_taste_smell": "no", "exposure": "not sure", "tracing": "yes", "gender": "RATHER NOT SAY", "medical_condition": "not sure", "city_location_coords": "+1.2-3.4", "location_coords": "+3.4-1.2", "location": "Cape Town, South Africa", }, ) actions = await form.submit(dispatcher, tracker, {}) assert actions == [SlotSet("study_a_arm", {})] assert request.called [(request, response)] = request.calls data = json.loads(request.stream.body) assert data.pop("deduplication_id") assert data == { "province": "ZA-WC", "age": "18-40", "fever": False, "cough": False, "sore_throat": True, "difficulty_breathing": False, "smell": False, "exposure": "not_sure", "tracing": True, "gender": "not_say", "preexisting_condition": "not_sure", "city_location": "+01.2-003.4/", "location": "+03.4-001.2/", "city": "Cape Town, South Africa", "msisdn": "+default", "risk": "moderate", "source": "WhatsApp", "data": { "cardio": None, "diabetes": None, "hypertension": None, "obesity": None, }, } base.actions.actions.config.EVENTSTORE_URL = None base.actions.actions.config.EVENTSTORE_TOKEN = None