def setUp(self): self.request_envelope = RequestEnvelope() self.context = Context() self.system = SystemState() self.user = User() self.device = Device() self.person = Person()
def setUp(self): self.test_locale = "foo_locale" self.test_request_type = "LaunchRequest" self.test_dialog_state = DialogState.COMPLETED self.test_intent_name = "foo_intent" self.test_slot_name = "foo_slot" self.test_slot_value = "foo_slot_value" self.test_slot = Slot(name=self.test_slot_name, value=self.test_slot_value) self.test_api_access_token = "foo_api_access_token" self.test_access_token = "foo_account_linking_access_token" self.test_device_id = "foo_device_id" self.test_supported_interfaces = SupportedInterfaces( display=DisplayInterface(template_version="test_template", markup_version="test_markup")) self.test_new_session = False self.test_launch_request = LaunchRequest(locale=self.test_locale) self.test_intent_request = IntentRequest( dialog_state=self.test_dialog_state, intent=Intent(name=self.test_intent_name, slots={ self.test_slot_name: Slot(name=self.test_slot_name, value=self.test_slot_value) })) self.test_request_envelope = RequestEnvelope( session=Session(new=self.test_new_session), context=Context( system=SystemState(user=User( access_token=self.test_access_token), api_access_token=self.test_api_access_token, device=Device(device_id=self.test_device_id, supported_interfaces=self. test_supported_interfaces))))
def get_context_data(self): """ Creates a context according to the skill_settings Returns: (Context) the context """ context = Context(SystemState(application=self.application, user=self.user, device=Device(self.skill_settings.device_id, self.skill_settings.supported_interfaces), api_endpoint=self.skill_settings.api_endpoint, api_access_token=str(uuid.uuid4())), AudioPlayerState(player_activity=PlayerActivity.IDLE)) return context
def test_skill_invoke_throw_exception_when_skill_id_doesnt_match(self): skill_config = self.create_skill_config() skill_config.skill_id = "123" mock_request_envelope = RequestEnvelope(context=Context( system=SystemState(application=Application( application_id="test")))) skill = Skill(skill_configuration=skill_config) with self.assertRaises(AskSdkException) as exc: skill.invoke(request_envelope=mock_request_envelope, context=None) assert "Skill ID Verification failed" in str(exc.exception), ( "Skill invocation didn't throw verification error when Skill ID " "doesn't match Application ID")
def test_skill_invoke_set_service_client_factory_if_api_client_provided( self): session = Session() mock_request_envelope = RequestEnvelope(context=Context( system=SystemState(application=Application(application_id="test"), api_access_token="test_api_access_token", api_endpoint="test_api_endpoint")), session=session) self.mock_handler_adapter.supports.return_value = True self.mock_handler_adapter.execute.return_value = None skill_config = self.create_skill_config() skill_config.skill_id = "test" skill_config.api_client = "test_api_client" skill = CustomSkill(skill_configuration=skill_config) skill.invoke(request_envelope=mock_request_envelope, context=None) called_args, called_kwargs = self.mock_request_mapper.get_request_handler_chain.call_args test_handler_input = called_args[0] assert test_handler_input.service_client_factory is not None, ( "Service Client Factory not initialized when api client is " "provided in skill configuration, " "during skill invocation") assert test_handler_input.service_client_factory.api_configuration.api_client == "test_api_client", ( "Api Client value in Service Client Factory different than the " "one provided in skill configuration") assert test_handler_input.service_client_factory.api_configuration.authorization_value == \ "test_api_access_token", ("Api Access Token value in Service " "Client Factory different than the one " "present " "in request envelope") assert test_handler_input.service_client_factory.api_configuration.api_endpoint == \ "test_api_endpoint", ("Api Endpoint value in Service Client " "Factory different than the one present " "in request envelope")
def test_skill_invoke_pass_session_attributes_to_response_envelope(self): mock_request_envelope = RequestEnvelope( context=Context(system=SystemState(application=Application( application_id="test"))), session=Session(attributes={"foo": "bar"})) self.mock_handler_adapter.supports.return_value = True self.mock_handler_adapter.execute.return_value = None skill_config = self.create_skill_config() skill_config.skill_id = "test" skill = CustomSkill(skill_configuration=skill_config) response_envelope = skill.invoke( request_envelope=mock_request_envelope, context=None) assert response_envelope.session_attributes is not None, ( "Session Attributes are not propagated from Request Envelope " "session to Response Envelope, " "during skill invocation") assert response_envelope.session_attributes["foo"] == "bar", ( "Invalid Session Attributes propagated from Request Envelope " "session to Response Envelope, " "during skill invocation")