def test_lambda_handler_invocation(self): mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler) mock_request_handler.can_handle.return_value = True mock_response = Response() mock_response.output_speech = "test output speech" mock_request_handler.handle.return_value = mock_response self.sb.add_request_handler(request_handler=mock_request_handler) mock_request_envelope_payload = { "context": { "System": { "application": { "applicationId": "test" } } } } self.sb.skill_id = "test" lambda_handler = self.sb.lambda_handler() response_envelope = lambda_handler(event=mock_request_envelope_payload, context=None) assert response_envelope["version"] == RESPONSE_FORMAT_VERSION, ( "Response Envelope from lambda handler invocation has version " "different than expected") assert response_envelope["userAgent"] == user_agent_info( sdk_version=__version__, custom_user_agent=None ), ("Response Envelope from lambda handler invocation has user agent " "info different than expected") assert response_envelope["response"][ "outputSpeech"] == "test output speech", ( "Response Envelope from lambda handler invocation has incorrect " "response than built by skill")
def test_should_append_additional_user_agent_using_userAgentManager(self): additional_user_agent = "test_string" sdk_user_agent = user_agent_info(sdk_version=__version__) mock_request_handler = mock.MagicMock(spec=AbstractRequestHandler) mock_request_handler.can_handle.return_value = True mock_response = Response() mock_request_handler.handle.return_value = mock_response self.sb.add_request_handler(request_handler=mock_request_handler) mock_request_envelope_payload = { "context": { "System": { "application": { "applicationId": "test" } } } } self.sb.skill_id = "test" lambda_handler = self.sb.lambda_handler() UserAgentManager.register_component( component_name=additional_user_agent) response_envelope = lambda_handler(event=mock_request_envelope_payload, context=None) self.assertEqual( "{} {}".format(additional_user_agent, sdk_user_agent), response_envelope["userAgent"], "Response envelope doesn't have correct user agent when adding " "using UserAgentManager")
def __init__(self): # type: () -> None """The ResponseFactory has property Response with all parameters initialized to None. """ self.response = Response( output_speech=None, card=None, reprompt=None, directives=None, should_end_session=None)
def test_skill_invoke_non_empty_response_in_response_envelope(self): mock_request_envelope = RequestEnvelope() mock_response = Response() self.mock_handler_adapter.supports.return_value = True self.mock_handler_adapter.execute.return_value = mock_response skill_config = self.create_skill_config() skill = Skill(skill_configuration=skill_config) response_envelope = skill.invoke( request_envelope=mock_request_envelope, context=None) assert response_envelope.response == mock_response, ( "Skill invocation returned incorrect response from " "request dispatch")
def handle(self, handler_input): # type: (HandlerInput) -> Response slots = handler_input.request_envelope.request.intent.slots session_attr = handler_input.attributes_manager.session_attributes sentence = slots['Value'].value reprompt = 'launched' in session_attr if 'initialized' not in session_attr: spoinit() session_attr['initialized'] = None ssml = ssmlify(sentence) if reprompt: reprompt = PlainTextOutputSpeech( text='Would you like to do another?') else: reprompt = None plain_text = spoonerify(sentence) return Response(SsmlOutputSpeech(ssml=ssml), SimpleCard("Spoonerism Maker", plain_text), should_end_session=True)