def test_does_not_get_device_address_if_desired_address_provided( self, mock_get_days, mock_get_address): mock_get_days.return_value = ["Monday"] request = MyCityRequestDataModel() request.session_attributes[ intent_constants.CURRENT_ADDRESS_KEY] = "10 Main Street Boston MA" get_trash_day_info(request) mock_get_address.assert_not_called()
def on_intent(mycity_request): """ If the event type is "request" and the request type is "IntentRequest", this function is called to execute the logic associated with the provided intent and build a response. Checks for required session_attributes when applicable. :param mycity_request: MyCityRequestDataModel object with request_type IntentRequest :return: MyCityRequestDataModel object corresponding to the intent_name :raises: ValueError """ logger.debug('MyCityRequestDataModel received:' + mycity_request.get_logger_string()) if "Address" in mycity_request.intent_variables \ and "value" in mycity_request.intent_variables["Address"]: # Some of our intents have an associated address value. # Capture that into session data here set_address_in_session(mycity_request) if "Zipcode" in mycity_request.intent_variables \ and "value" in mycity_request.intent_variables["Zipcode"]: set_zipcode_in_session(mycity_request) # session_attributes = session.get("attributes", {}) if mycity_request.intent_name == "GetAddressIntent": return get_address_from_session(mycity_request) elif mycity_request.intent_name == "TrashDayIntent": return get_trash_day_info(mycity_request) elif mycity_request.intent_name == "SnowParkingIntent": return get_snow_emergency_parking_intent(mycity_request) elif mycity_request.intent_name == "CrimeIncidentsIntent": return get_crime_incidents_intent(mycity_request) elif mycity_request.intent_name == "FoodTruckIntent": return get_nearby_food_trucks(mycity_request) elif mycity_request.intent_name == "GetAlertsIntent": return get_alerts_intent(mycity_request) elif mycity_request.intent_name == "AMAZON.HelpIntent": return get_help_response(mycity_request) elif mycity_request.intent_name == "AMAZON.StopIntent" or \ mycity_request.intent_name == "AMAZON.CancelIntent" or \ mycity_request.intent_name == "AMAZON.NavigateHomeIntent": return handle_session_end_request(mycity_request) elif mycity_request.intent_name == "FeedbackIntent": return submit_feedback(mycity_request) elif mycity_request.intent_name == "AMAZON.FallbackIntent": return fallback_intent(mycity_request) elif mycity_request.intent_name == "LatestThreeOneOne": return get_311_requests(mycity_request) elif mycity_request.intent_name == "InclementWeatherIntent": return get_inclement_weather_alert(mycity_request) elif mycity_request.intent_name == "FarmersMarketIntent": return get_farmers_markets_today(mycity_request) elif mycity_request.intent_name == "CoronavirusUpdateIntent": return get_coronovirus_update(mycity_request) else: raise ValueError("Invalid intent")
def test_does_not_require_boston_address_if_desired_address_provided(self, mock_get_days, mock_get_address): device_address_request = MyCityRequestDataModel() device_address_request.session_attributes[ intent_constants.CURRENT_ADDRESS_KEY] \ = "10 Main Street New York NY" mock_get_address.return_value = device_address_request, True mock_get_days.return_value = ["Monday"] request = MyCityRequestDataModel() request.session_attributes[intent_constants.CURRENT_ADDRESS_KEY] = "10 Main Street Boston MA" result = get_trash_day_info(request) self.assertTrue("Monday" in result.output_speech)
def test_requests_user_supplied_address_when_no_device_address_set( self, mock_get_address): mock_get_address.return_value = (MyCityRequestDataModel(), True) request = MyCityRequestDataModel() response = get_trash_day_info(request) self.assertEqual("Address", response.card_title)
def test_requests_device_address_permission(self, mock_get_address): mock_get_address.return_value = (MyCityRequestDataModel(), False) request = MyCityRequestDataModel() response = get_trash_day_info(request) self.assertTrue( "read::alexa:device:all:address" in response.card_permissions)
def test_provided_address_must_be_in_city(self, mock_get_days): mock_get_days.return_value = ["Monday"] request = MyCityRequestDataModel() request.session_attributes[intent_constants.CURRENT_ADDRESS_KEY] = "10 Main Street New York, NY" result = get_trash_day_info(request) self.assertFalse("Monday" in result.output_speech)
def test_provided_address_misunderstood(self): expected_text = speech_constants.ADDRESS_NOT_UNDERSTOOD request = MyCityRequestDataModel() request.session_attributes[intent_constants.CURRENT_ADDRESS_KEY] = "wayne street" result = get_trash_day_info(request) self.assertTrue(expected_text in result.output_speech)