Ejemplo n.º 1
0
    async def test_validate_location_google_places_error(self):
        """
        Errors should be retried 3 times
        """
        base.actions.actions.config.GOOGLE_PLACES_API_KEY = "test_key"
        form = HealthCheckProfileForm()
        form.places_lookup = utils.AsyncMock()
        form.places_lookup.side_effect = Exception()

        tracker = self.get_tracker_for_text_slot_with_message(
            "location",
            "Cape Town",
        )

        dispatcher = CollectingDispatcher()
        events = await form.validate(dispatcher, tracker, {})
        assert events == [
            SlotSet("location", None),
        ]

        [message] = dispatcher.messages
        assert message["template"] == "utter_incorrect_location"

        assert form.places_lookup.call_count == 3

        base.actions.actions.config.GOOGLE_PLACES_API_KEY = None
Ejemplo n.º 2
0
    async def test_validate_location_google_places(self):
        """
        If there's are google places API credentials, then do a lookup
        """
        base.actions.actions.config.GOOGLE_PLACES_API_KEY = "test_key"
        form = HealthCheckProfileForm()
        form.places_lookup = utils.AsyncMock()
        form.places_lookup.return_value = {
            "formatted_address": "Cape Town, South Africa",
            "geometry": {
                "location": {
                    "lat": 1.23,
                    "lng": 4.56
                }
            },
        }

        tracker = self.get_tracker_for_text_slot_with_message(
            "location",
            "Cape Town",
        )

        events = await form.validate(CollectingDispatcher(), tracker, {})
        assert events == [
            SlotSet("location", "Cape Town, South Africa"),
            SlotSet("city_location_coords", "+01.23+004.56/"),
        ]

        base.actions.actions.config.GOOGLE_PLACES_API_KEY = None
    async def test_assign_study_b_arm(self):
        """
        Should set the sart time
        """
        action = ActionStartTriage()
        dispatcher = CollectingDispatcher()

        action.call_event_store = utils.AsyncMock()
        action.call_event_store.return_value = {
            "msisdn": "+27820001001",
            "source": "WhatsApp",
            "timestamp": "2022-03-09T07:33:29.046948Z",
            "created_by": "whatsapp-healthcheck",
        }
        events = await action.run(
            dispatcher,
            Tracker("27820001001", {}, {}, [], False, None, {}, "action_listen",),
            {},
        )
        assert SlotSet("start_time", "2022-03-09T07:33:29.046948Z") in events
    async def test_assign_study_b_arm(self, mock_env_studyb):
        """
        Should set the study b arm
        """
        action = ActionAssignStudyBArm()
        dispatcher = CollectingDispatcher()

        action.call_event_store = utils.AsyncMock()
        action.call_event_store.return_value = {
            "msisdn": "+27820001001",
            "source": "WhatsApp",
            "timestamp": "2022-03-09T07:33:29.046948Z",
            "created_by": "whatsapp-healthcheck",
            "province": "ZA-GT",
            "study_b_arm": "T1",
        }
        events = await action.run(
            dispatcher,
            Tracker(
                "27820001001",
                {
                    "first_name": "test first",
                    "last_name": "test last",
                    "destination": "campus",
                    "province": "gt",
                    "reason": "student",
                },
                {},
                [],
                False,
                None,
                {},
                "action_listen",
            ),
            {},
        )
        assert SlotSet("study_b_arm", "T1") in events
Ejemplo n.º 5
0
    async def test_validate_location_google_places_no_results(self):
        """
        If there are no results, then display error message and ask again
        """
        base.actions.actions.config.GOOGLE_PLACES_API_KEY = "test_key"
        form = HealthCheckProfileForm()
        form.places_lookup = utils.AsyncMock()
        form.places_lookup.return_value = None

        tracker = self.get_tracker_for_text_slot_with_message(
            "location",
            "Cape Town",
        )

        dispatcher = CollectingDispatcher()
        events = await form.validate(dispatcher, tracker, {})
        assert events == [
            SlotSet("location", None),
        ]

        [message] = dispatcher.messages
        assert message["template"] == "utter_incorrect_location"

        base.actions.actions.config.GOOGLE_PLACES_API_KEY = None