From 74ea73b3b6a03fd9cb735fb8c1fb2bd961faab54 Mon Sep 17 00:00:00 2001 From: Govinda Raju Date: Wed, 18 Dec 2019 19:35:26 -0800 Subject: [PATCH] Adding User-Agent and updating model definitions Updated ask-sdk-model-runtime test cases to use UnitTest framework --- ask-sdk-model-runtime/CHANGELOG.rst | 6 + .../ask_sdk_model_runtime/__init__.py | 3 +- .../ask_sdk_model_runtime/__version__.py | 2 +- .../ask_sdk_model_runtime/utils.py | 39 +++ .../tests/unit/test_api_client.py | 46 ++-- .../tests/unit/test_base_service_client.py | 130 +++++----- .../tests/unit/test_lwa_client.py | 80 +++---- .../tests/unit/test_serialize.py | 224 +++++++++--------- .../tests/unit/test_utils.py | 50 ++++ ask-smapi-model/CHANGELOG.rst | 8 +- .../ask_smapi_model/__version__.py | 2 +- .../skill_management_service_client.py | 87 ++++++- .../v1/skill/manifest/__init__.py | 1 + .../alexa_presentation_html_interface.py | 106 +++++++++ .../v1/skill/manifest/audio_interface.py | 2 +- .../v1/skill/manifest/interface.py | 11 +- .../v1/skill/manifest/video_app_interface.py | 2 +- .../v1/skill/simulations/__init__.py | 2 +- .../{invocations.py => invocation.py} | 4 +- .../v1/skill/simulations/simulation_result.py | 10 +- 20 files changed, 563 insertions(+), 252 deletions(-) create mode 100644 ask-sdk-model-runtime/ask_sdk_model_runtime/utils.py create mode 100644 ask-sdk-model-runtime/tests/unit/test_utils.py create mode 100644 ask-smapi-model/ask_smapi_model/v1/skill/manifest/alexa_presentation_html_interface.py rename ask-smapi-model/ask_smapi_model/v1/skill/simulations/{invocations.py => invocation.py} (98%) diff --git a/ask-sdk-model-runtime/CHANGELOG.rst b/ask-sdk-model-runtime/CHANGELOG.rst index 0e94f68..c081062 100644 --- a/ask-sdk-model-runtime/CHANGELOG.rst +++ b/ask-sdk-model-runtime/CHANGELOG.rst @@ -6,3 +6,9 @@ CHANGELOG --- * Initial release of alexa sdk model runtime. + +1.0.1 +----- + +* Adding User-Agent functionality support to set custom user agent values. +* Updated all Unit tests to Python UnitTest framework. \ No newline at end of file diff --git a/ask-sdk-model-runtime/ask_sdk_model_runtime/__init__.py b/ask-sdk-model-runtime/ask_sdk_model_runtime/__init__.py index bd94317..9b4e61e 100644 --- a/ask-sdk-model-runtime/ask_sdk_model_runtime/__init__.py +++ b/ask-sdk-model-runtime/ask_sdk_model_runtime/__init__.py @@ -28,4 +28,5 @@ from .serializer import DefaultSerializer, Serializer from .exceptions import ( ServiceException, SerializationException, ApiClientException) -from .service_client_response import ServiceClientResponse \ No newline at end of file +from .service_client_response import ServiceClientResponse +from .utils import user_agent_info \ No newline at end of file diff --git a/ask-sdk-model-runtime/ask_sdk_model_runtime/__version__.py b/ask-sdk-model-runtime/ask_sdk_model_runtime/__version__.py index 4c85284..c274178 100644 --- a/ask-sdk-model-runtime/ask_sdk_model_runtime/__version__.py +++ b/ask-sdk-model-runtime/ask_sdk_model_runtime/__version__.py @@ -21,7 +21,7 @@ 'Authentication Configuration etc that is used by the SDK ' 'models.') __url__ = 'https://github.com/alexa/alexa-apis-for-python' -__version__ = '1.0.0' +__version__ = '1.0.1' __author__ = 'Alexa Skills Kit' __author_email__ = 'ask-sdk-dynamic@amazon.com' __license__ = 'Apache 2.0' diff --git a/ask-sdk-model-runtime/ask_sdk_model_runtime/utils.py b/ask-sdk-model-runtime/ask_sdk_model_runtime/utils.py new file mode 100644 index 0000000..f5dfd94 --- /dev/null +++ b/ask-sdk-model-runtime/ask_sdk_model_runtime/utils.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights +# Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the +# License. +# +import sys + +def user_agent_info(sdk_version, custom_user_agent): + # type: (str, str) -> str + """Return the user agent info along with the SDK and Python + Version information. + + :param sdk_version: Version of the SDK being used. + :type sdk_version: str + :param custom_user_agent: Custom User Agent string provided by + the developer. + :type custom_user_agent: str + :return: User Agent Info string + :rtype: str + """ + python_version = ".".join(str(x) for x in sys.version_info[0:3]) + user_agent = "ask-python-model/{} Python/{}".format( + sdk_version, python_version) + if custom_user_agent is None: + return user_agent + else: + return user_agent + " " + custom_user_agent \ No newline at end of file diff --git a/ask-sdk-model-runtime/tests/unit/test_api_client.py b/ask-sdk-model-runtime/tests/unit/test_api_client.py index 8a458ff..d6b4382 100644 --- a/ask-sdk-model-runtime/tests/unit/test_api_client.py +++ b/ask-sdk-model-runtime/tests/unit/test_api_client.py @@ -41,10 +41,10 @@ def test_convert_null_header_tuples_to_dict(self): test_headers_list = None expected_headers_dict = {} - assert self.test_api_client._convert_list_tuples_to_dict( - test_headers_list) == expected_headers_dict, ( + self.assertEqual(self.test_api_client._convert_list_tuples_to_dict( + test_headers_list), expected_headers_dict, ( "DefaultApiClient failed to convert null headers list to empty " - "dict object") + "dict object")) def test_convert_header_tuples_to_dict(self): test_headers_list = [ @@ -53,20 +53,20 @@ def test_convert_header_tuples_to_dict(self): expected_headers_dict = { "header_1": "test_1, test_3", "header_2": "test_2"} - assert self.test_api_client._convert_list_tuples_to_dict( - test_headers_list) == expected_headers_dict, ( + self.assertEqual(self.test_api_client._convert_list_tuples_to_dict( + test_headers_list), expected_headers_dict, ( "DefaultApiClient failed to convert header list of tuples to " "dictionary format needed for http " - "request call") + "request call")) def test_convert_null_header_dict_to_tuples(self): test_headers_dict = None expected_headers_list = [] - assert self.test_api_client._convert_dict_to_list_tuples( - test_headers_dict) == expected_headers_list, ( + self.assertEqual(self.test_api_client._convert_dict_to_list_tuples( + test_headers_dict), expected_headers_list, ( "DefaultApiClient failed to convert null headers dict to empty " - "list object") + "list object")) def test_convert_header_dict_to_tuples(self): test_headers_dict = { @@ -76,11 +76,11 @@ def test_convert_header_dict_to_tuples(self): ("header_1", "test_1"), ("header_1", "test_3"), ("header_2", "test_2"), ("header_3", "test_4")] - assert set(self.test_api_client._convert_dict_to_list_tuples( - test_headers_dict)) == set( + self.assertEqual(set(self.test_api_client._convert_dict_to_list_tuples( + test_headers_dict)), set( expected_headers_list), ( "DefaultApiClient failed to convert headers dict to list of " - "tuples format for ApiClientResponse") + "tuples format for ApiClientResponse")) def test_resolve_valid_http_method(self): with mock.patch("requests.get", @@ -104,7 +104,7 @@ def test_resolve_invalid_http_method_throw_exception(self): with self.assertRaises(ApiClientException) as exc: self.test_api_client.invoke(test_invalid_method_request) - assert "Invalid request method: GET_TEST" in str(exc.exception) + self.assertIn("Invalid request method: GET_TEST", str(exc.exception)) def test_invoke_http_method_throw_exception(self): with mock.patch("requests.get", @@ -112,7 +112,7 @@ def test_invoke_http_method_throw_exception(self): with self.assertRaises(ApiClientException) as exc: self.test_api_client.invoke(self.valid_request) - assert "Error executing the request: test exception" in str(exc.exception) + self.assertIn("Error executing the request: test exception", str(exc.exception)) def test_api_client_invoke_with_method_headers_processed(self): self.valid_request.headers = [ @@ -131,21 +131,21 @@ def test_api_client_invoke_with_method_headers_processed(self): side_effect=lambda *args, **kwargs: test_response): actual_response = self.test_api_client.invoke(self.valid_request) - assert set(actual_response.headers) == set([ + self.assertEqual(set(actual_response.headers), set([ ("response_header_1", "test_1"), ("response_header_1", "test_3"), ("response_header_2", "test_2"), ("response_header_3", "test_4")]), ( "Response headers from client doesn't match with the " - "expected headers") + "expected headers")) - assert actual_response.status_code == 400, ( + self.assertEqual(actual_response.status_code, 400, ( "Status code from client response doesn't match with the " - "expected response status code") + "expected response status code")) - assert actual_response.body == "test response body", ( + self.assertEqual(actual_response.body, "test response body", ( "Body from client response doesn't match with the expected " - "response body") + "response body")) def test_api_client_invoke_with_http_url_throw_error(self): test_invalid_url_scheme_request = ApiClientRequest( @@ -157,7 +157,7 @@ def test_api_client_invoke_with_http_url_throw_error(self): with self.assertRaises(ApiClientException) as exc: self.test_api_client.invoke(test_invalid_url_scheme_request) - assert "Requests against non-HTTPS endpoints are not allowed." in str(exc.exception) + self.assertIn("Requests against non-HTTPS endpoints are not allowed.", str(exc.exception)) def test_api_client_invoke_with_http_case_sensitive_url_throw_error(self): test_invalid_url_scheme_request = ApiClientRequest( @@ -169,7 +169,7 @@ def test_api_client_invoke_with_http_case_sensitive_url_throw_error(self): with self.assertRaises(ApiClientException) as exc: self.test_api_client.invoke(test_invalid_url_scheme_request) - assert "Requests against non-HTTPS endpoints are not allowed." in str(exc.exception) + self.assertIn("Requests against non-HTTPS endpoints are not allowed.", str(exc.exception)) def test_api_client_invoke_with_no_url_schema_throw_error(self): test_invalid_url_scheme_request = ApiClientRequest( @@ -181,7 +181,7 @@ def test_api_client_invoke_with_no_url_schema_throw_error(self): with self.assertRaises(ApiClientException) as exc: self.test_api_client.invoke(test_invalid_url_scheme_request) - assert "Requests against non-HTTPS endpoints are not allowed." in str(exc.exception) + self.assertIn("Requests against non-HTTPS endpoints are not allowed.", str(exc.exception)) def test_api_client_send_request_with_raw_data_serialized_for_json_content( self): diff --git a/ask-sdk-model-runtime/tests/unit/test_base_service_client.py b/ask-sdk-model-runtime/tests/unit/test_base_service_client.py index 5d5d6f5..598a473 100644 --- a/ask-sdk-model-runtime/tests/unit/test_base_service_client.py +++ b/ask-sdk-model-runtime/tests/unit/test_base_service_client.py @@ -12,10 +12,12 @@ # the specific language governing permissions and limitations under the License. # import six +import unittest from pytest import raises -from ask_sdk_model_runtime import (ApiClient, ApiClientResponse, ApiConfiguration, - BaseServiceClient, Serializer, ServiceException, ServiceClientResponse) +from ask_sdk_model_runtime import ( + ApiClient, ApiClientResponse, ApiConfiguration, + BaseServiceClient, Serializer, ServiceException, ServiceClientResponse) if six.PY3: from unittest import mock @@ -61,7 +63,7 @@ def service_client_null_serializer(): return BaseServiceClient(api_configuration=api_configuration) -class TestBaseServiceClient(object): +class TestBaseServiceClient(unittest.TestCase): def test_invoke_build_url_with_path_when_endpoint_path_passed( self): mocked_api_client = MockedApiClient() @@ -76,8 +78,8 @@ def test_invoke_build_url_with_path_when_endpoint_path_passed( header_params=[], path_params={},response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint and path passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint and path passed") def test_invoke_build_url_with_no_duplicate_slash_path_when_endpoint_path_has_slash(self): endpoint = "http://test.com/" @@ -90,8 +92,8 @@ def test_invoke_build_url_with_no_duplicate_slash_path_when_endpoint_path_has_sl header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint and path with duplicate slash passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint and path with duplicate slash passed") def test_invoke_build_url_with_query_params( self): @@ -107,8 +109,22 @@ def test_invoke_build_url_with_query_params( query_params=query_params, header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path and query parameters passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path and query parameters passed") + + def test_invoke_build_url_with_query_params_list_container(self): + endpoint = "http://test.com/" + path = "/v1/x/y/" + query_params = [("filter", ["test_filter_1", "test_filter_2"])] + expected = "http://test.com/v1/x/y/?filter=test_filter_1&filter=test_filter_2" + + mocked_base_service_client_api_client_empty_response = MockedBaseServiceClient.empty_response() + mocked_base_service_client_api_client_empty_response.invoke( + method="GET", endpoint=endpoint, path=path, query_params=query_params, header_params=[], path_params={}, + response_definitions=[], body=None, response_type=None) + + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected, \ + "Build URL failed when endpoint, path and query parameters containing list of values passed") def test_invoke_build_url_with_query_params_special_chars( self): @@ -124,8 +140,8 @@ def test_invoke_build_url_with_query_params_special_chars( query_params=query_params, header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path and query parameters containing special characters passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path and query parameters containing special characters passed") def test_invoke_build_url_with_query_params_static_content( self): @@ -140,8 +156,8 @@ def test_invoke_build_url_with_query_params_static_content( query_params=query_params, header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path and query parameters containing static content passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path and query parameters containing static content passed") def test_invoke_build_url_with_path_params_interpolated( self): @@ -159,8 +175,8 @@ def test_invoke_build_url_with_path_params_interpolated( header_params=[], path_params=path_params, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path and path parameters passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path and path parameters passed") def test_invoke_build_url_with_path_params_containing_special_chars_interpolated( self): @@ -178,8 +194,8 @@ def test_invoke_build_url_with_path_params_containing_special_chars_interpolated header_params=[], path_params=path_params, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path and path parameters containing special characters passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path and path parameters containing special characters passed") def test_invoke_build_url_with_path_params_with_path_ending_in_slash( self): @@ -193,8 +209,8 @@ def test_invoke_build_url_with_path_params_with_path_ending_in_slash( header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert mocked_base_service_client_api_client_empty_response._api_client.request.url == expected,\ - "Build URL failed when endpoint, path with ending slash passed" + self.assertEqual(mocked_base_service_client_api_client_empty_response._api_client.request.url, expected,\ + "Build URL failed when endpoint, path with ending slash passed") def test_invoke_serializes_body_when_passed(self): mocked_api_client = MockedApiClient() @@ -226,7 +242,7 @@ def test_invoke_serializes_body_not_run_for_null_body(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert not mocked_serializer.serialize.called, "Invoke called serializer for null body" + self.assertNotEqual(mocked_serializer.serialize.called, "Invoke called serializer for null body") def test_invoke_api_client_throws_exception(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -244,11 +260,11 @@ def test_invoke_api_client_throws_exception(self): query_params=[], header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert str(exc.value) == "Call to service failed: test exception", \ - "Service exception not raised during base service client invoke when api client invoke raises" - assert exc.value.status_code == 500, ( + self.assertEqual(str(exc.value), "Call to service failed: test exception", \ + "Service exception not raised during base service client invoke when api client invoke raises") + self.assertEqual(exc.value.status_code, 500, ( "Service exception raised during base service client invoke has different status code than expected, " - "when api client invoke raises") + "when api client invoke raises")) def test_invoke_serializes_response_if_present(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -273,7 +289,7 @@ def test_invoke_serializes_response_if_present(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=fake_response_type) - assert response.body == "deserialized_payload", "Response from api client not deserialized by base service client" + self.assertEqual(response.body, "deserialized_payload", "Response from api client not deserialized by base service client") mocked_serializer.deserialize.assert_called_with(payload=fake_response.body, obj_type=fake_response_type), \ "Base service client called deserialize on Response from api client with wrong values" @@ -298,10 +314,10 @@ def test_invoke_return_api_response_for_no_content_response(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=fake_response_type) - assert response.body is None, "Base service client returns invalid response when status code is 204" - assert response.status_code == 204, "Base service client returns invalid status code" - assert not mocked_serializer.deserialize.called, ( - "Base service client invoke method deserialized no content response body") + self.assertIsNone(response.body, "Base service client returns invalid response when status code is 204") + self.assertEqual(response.status_code, 204, "Base service client returns invalid status code") + self.assertIsNot(mocked_serializer.deserialize.called, ( + "Base service client invoke method deserialized no content response body")) def test_invoke_return_full_api_response(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -327,9 +343,9 @@ def test_invoke_return_full_api_response(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=fake_response_type) - assert response.body == "deserialized_payload", ("Base service client returns invalid api response when status code is 204") - assert response.headers == "test_headers", ("Base service client return invalid api response with null headers") - assert response.status_code == 200, ("Base service client return invalid api response with null status_code") + self.assertEqual(response.body, "deserialized_payload", ("Base service client returns invalid api response when status code is 204")) + self.assertEqual(response.headers, "test_headers", ("Base service client return invalid api response with null headers")) + self.assertEqual(response.status_code, 200, ("Base service client return invalid api response with null status_code")) def test_invoke_return_api_response_with_none_body(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -353,12 +369,12 @@ def test_invoke_return_api_response_with_none_body(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=fake_response_type) - assert response.body is None, ("Base service client returns invalid api response when status code is 204") - assert response.headers == "test_headers", ("Base service client return invalid api response with null headers") - assert response.status_code == 204, ("Base service client return invalid api response with null status_code") + self.assertIsNone(response.body, ("Base service client returns invalid api response when status code is 204")) + self.assertEqual(response.headers, "test_headers", ("Base service client return invalid api response with null headers")) + self.assertEqual(response.status_code, 204, ("Base service client return invalid api response with null status_code")) - assert not mocked_serializer.deserialize.called, ( - "Base service client invoke method deserialized no content response body") + self.assertIsNot(mocked_serializer.deserialize.called, ( + "Base service client invoke method deserialized no content response body")) def test_invoke_throw_exception_if_no_definitions_provided_for_unsuccessful_response(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -379,12 +395,12 @@ def test_invoke_throw_exception_if_no_definitions_provided_for_unsuccessful_resp query_params=[], header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert str(exc.value) == "Unknown error", ( + self.assertEqual(str(exc.value), "Unknown error", ( "Service exception not raised during base service client invoke when response is unsuccessful and " - "no response definitions provided") - assert exc.value.status_code == 450, ( + "no response definitions provided")) + self.assertEqual(exc.value.status_code, 450, ( "Service exception raised during base service client invoke has different status code than expected, " - "when response is unsuccessful and no response definitions provided") + "when response is unsuccessful and no response definitions provided")) def test_invoke_throw_exception_with_matched_definition_for_unsuccessful_response(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -418,14 +434,14 @@ def test_invoke_throw_exception_with_matched_definition_for_unsuccessful_respons response_definitions=fake_response_definitions, body=None, response_type=None) - assert str(exc.value) == "test exception with definition 1", ( + self.assertEqual(str(exc.value), "test exception with definition 1", ( "Incorrect service exception raised during base service client invoke when response is unsuccessful and " - "matching response definitions provided") + "matching response definitions provided")) mocked_serializer.deserialize.assert_called_with( payload=fake_response.body, obj_type="test_definition_1") - assert str(exc.value.body) == "deserialized_error_body", ( + self.assertEqual(str(exc.value.body), "deserialized_error_body", ( "Service exception raised during base service client invoke, when response is unsuccessful, " - "has different body that expected response") + "has different body that expected response")) def test_invoke_throw_exception_with_no_matched_definition_for_unsuccessful_response(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -457,15 +473,15 @@ def test_invoke_throw_exception_with_no_matched_definition_for_unsuccessful_resp response_definitions=fake_response_definitions, body=None, response_type=None) - assert str(exc.value) == "Unknown error", ( + self.assertEqual(str(exc.value), "Unknown error", ( "Incorrect service exception raised during base service client invoke when response is unsuccessful and " - "no matching response definitions found") - assert str(exc.value.body) == "test_body", ( + "no matching response definitions found")) + self.assertEqual(str(exc.value.body), "test_body", ( "Service exception raised during base service client invoke, when response is unsuccessful, " - "has different body that expected response") - assert exc.value.status_code == 485, ( + "has different body that expected response")) + self.assertEqual(exc.value.status_code, 485, ( "Service exception raised during base service client invoke, when response is unsuccessful, " - "has different status code that expected response") + "has different status code that expected response")) def test_invoke_raises_value_error_with_none_api_client(self): endpoint = "http://test.com" @@ -478,9 +494,9 @@ def test_invoke_raises_value_error_with_none_api_client(self): header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert str(exc.value) == 'API client is None', ( + self.assertEqual(str(exc.value), 'API client is None', ( "Base Service Client was initialized with no api client" - ) + )) def test_invoke_raises_value_error_with_none_serializer( self): @@ -494,9 +510,9 @@ def test_invoke_raises_value_error_with_none_serializer( header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert str(exc.value) == 'Serializer is None', ( + self.assertEqual(str(exc.value), 'Serializer is None', ( "Base Service Client was initialized with no serializer" - ) + )) def test_invoke_throw_exception_if_no_response_status_code(self): mocked_serializer = mock.MagicMock(spec=Serializer) @@ -518,6 +534,6 @@ def test_invoke_throw_exception_if_no_response_status_code(self): query_params=[], header_params=[], path_params={}, response_definitions=[], body=None, response_type=None) - assert str(exc.value) == "Invalid Response, no status code", ( + self.assertEqual(str(exc.value), "Invalid Response, no status code", ( "Service exception raised during base service client invoke, when response is unsuccessful, " - "has no status code") \ No newline at end of file + "has no status code")) \ No newline at end of file diff --git a/ask-sdk-model-runtime/tests/unit/test_lwa_client.py b/ask-sdk-model-runtime/tests/unit/test_lwa_client.py index 6cf68a9..b7a47b4 100644 --- a/ask-sdk-model-runtime/tests/unit/test_lwa_client.py +++ b/ask-sdk-model-runtime/tests/unit/test_lwa_client.py @@ -16,6 +16,7 @@ # License. # import six +import unittest from dateutil import tz import datetime @@ -47,17 +48,17 @@ def empty_response(self): return fake_response -class TestBaseServiceClient(object): +class TestBaseServiceClient(unittest.TestCase): def test_lwa_client_init_no_auth_config_throw_exception(self): with raises(ValueError) as exc: lwa_client = LwaClient( api_configuration=ApiConfiguration(), authentication_configuration=None) - assert str(exc.value) == ( + self.assertEqual(str(exc.value), ( "authentication_configuration must be provided"), ( "LwaClient Initialization didn't throw exception if a null " - "Authentication Configuration is passed") + "Authentication Configuration is passed")) def test_get_access_token_for_null_scope_throw_exception(self): test_lwa_client = LwaClient( @@ -67,9 +68,9 @@ def test_get_access_token_for_null_scope_throw_exception(self): with raises(ValueError) as exc: test_lwa_client.get_access_token_for_scope(scope=None) - assert str(exc.value) == "scope must be provided", ( + self.assertEqual(str(exc.value), "scope must be provided", ( "LWA Client get access token call didn't throw exception if a " - "null scope is passed") + "null scope is passed")) def test_get_access_token_retrieve_from_cache(self): test_lwa_client = LwaClient( @@ -88,9 +89,9 @@ def test_get_access_token_retrieve_from_cache(self): actual_token_value = test_lwa_client.get_access_token_for_scope( scope=test_scope) - assert expected_token_value == actual_token_value, ( + self.assertEqual(expected_token_value, actual_token_value, ( "LWA Client get access token call didn't retrieve unexpired " - "scoped access token from cache when available") + "scoped access token from cache when available")) def test_get_access_token_cache_miss_api_call_success(self): mocked_api_client = MockedApiClient() @@ -127,23 +128,23 @@ def test_get_access_token_cache_miss_api_call_success(self): actual_token_value = test_lwa_client.get_access_token_for_scope( scope=test_scope) - assert expected_token_value == actual_token_value, ( - "LWA Client get access token call didn't retrieve scoped access token") + self.assertEqual(expected_token_value, actual_token_value, ( + "LWA Client get access token call didn't retrieve scoped access token")) actual_token_expiry = test_lwa_client._scoped_token_cache[ test_scope].expiry - assert (local_now + datetime.timedelta( - seconds=10)) == actual_token_expiry, ( + self.assertEqual((local_now + datetime.timedelta( + seconds=10)), actual_token_expiry, ( "LWA Client get access token call cached wrong access token " - "expiry date") - - assert mocked_api_client.request.headers == expected_headers, ( - "LWA Client get access token called API with wrong headers") - assert mocked_api_client.request.method == expected_request_method, ( - "LWA Client get access token called API with wrong HTTP method") - assert mocked_api_client.request.url == expected_request_url, ( - "LWA Client get access token called API with wrong HTTP URL") + "expiry date")) + + self.assertEqual(mocked_api_client.request.headers, expected_headers, ( + "LWA Client get access token called API with wrong headers")) + self.assertEqual(mocked_api_client.request.method, expected_request_method, ( + "LWA Client get access token called API with wrong HTTP method")) + self.assertEqual(mocked_api_client.request.url, expected_request_url, ( + "LWA Client get access token called API with wrong HTTP URL")) mocked_serializer.serialize.assert_called_with(expected_request_body) def test_get_access_token_for_smapi_cache_miss_api_call_success( @@ -187,25 +188,24 @@ def test_get_access_token_for_smapi_cache_miss_api_call_success( mock_date.now.return_value = local_now actual_token_value = test_lwa_client.get_access_token_from_refresh_token() - assert expected_token_value == actual_token_value, ( + self.assertEqual(expected_token_value, actual_token_value, ( "LWA Client get access token call didn't retrieve unexpired " - "scoped access token from cache when available") + "scoped access token from cache when available")) actual_token_expiry = test_lwa_client._scoped_token_cache[ refresh_access_token].expiry - assert (local_now + datetime.timedelta( - seconds=10)) == actual_token_expiry, ( + self.assertEqual((local_now + datetime.timedelta( + seconds=10)), actual_token_expiry, ( "LWA Client get access token call cached wrong access token " - "expiry date") - - assert mocked_api_client.request.headers == expected_headers, ( - "LWA Client get access token called API with wrong headers") - assert mocked_api_client.request.method == expected_request_method, ( - "LWA Client get access token called API with wrong HTTP method") - assert mocked_api_client.request.url == expected_request_url, ( - "LWA Client get access tokbbr" - "en called API with wrong HTTP URL") + "expiry date")) + + self.assertEqual(mocked_api_client.request.headers, expected_headers, ( + "LWA Client get access token called API with wrong headers")) + self.assertEqual(mocked_api_client.request.method, expected_request_method, ( + "LWA Client get access token called API with wrong HTTP method")) + self.assertEqual(mocked_api_client.request.url, expected_request_url, ( + "LWA Client get access token called API with wrong HTTP URL")) mocked_serializer.serialize.assert_called_with(expected_request_body) @@ -241,13 +241,13 @@ def test_get_access_token_for_default_endpoint_api_success( actual_token_value = test_lwa_client.get_access_token_for_scope( scope=test_scope) - assert expected_token_value == actual_token_value, ( + self.assertEqual(expected_token_value, actual_token_value, ( "LWA Client get access token call didn't retrieve scoped access " - "token when a custom endpoint is passed") + "token when a custom endpoint is passed")) - assert mocked_api_client.request.url == expected_request_url, ( + self.assertEqual(mocked_api_client.request.url, expected_request_url, ( "LWA Client get access token called API with wrong HTTP URL, " - "when a custom endpoint is passed") + "when a custom endpoint is passed")) def test_get_access_token_api_call_fails_throws_exception( self): @@ -274,9 +274,9 @@ def test_get_access_token_api_call_fails_throws_exception( _actual_token_value = test_lwa_client.get_access_token_for_scope( scope=test_scope) - assert "Bad Request" in str(exc.value), ( + self.assertIn("Bad Request", str(exc.value), ( "LWA Client get access token threw unknown exception when " - "the LWA API call failed with an known exception") + "the LWA API call failed with an known exception")) def test_get_access_token_for_null_lwa_response_throw_exception( @@ -297,7 +297,7 @@ def test_get_access_token_for_null_lwa_response_throw_exception( with raises(ValueError) as exc: test_lwa_client.get_access_token_for_scope(scope=test_scope) - assert str(exc.value) == "Invalid response from LWA Client " \ + self.assertEqual(str(exc.value), "Invalid response from LWA Client " \ "generate access token call", ( "LWA Client get access token call didn't throw exception if a " - "generate access token returns None ") \ No newline at end of file + "generate access token returns None ")) \ No newline at end of file diff --git a/ask-sdk-model-runtime/tests/unit/test_serialize.py b/ask-sdk-model-runtime/tests/unit/test_serialize.py index 208e2c4..57adfd4 100644 --- a/ask-sdk-model-runtime/tests/unit/test_serialize.py +++ b/ask-sdk-model-runtime/tests/unit/test_serialize.py @@ -45,57 +45,57 @@ def setUp(self): def test_none_obj_serialization(self): test_obj = None - assert self.test_serializer.serialize(test_obj) is None, \ - "Default Serializer serialized None object incorrectly" + self.assertIsNone(self.test_serializer.serialize(test_obj), \ + "Default Serializer serialized None object incorrectly") def test_primitive_obj_serialization(self): test_obj = "test" - assert self.test_serializer.serialize(test_obj) == test_obj, \ - "Default Serializer serialized str object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), test_obj, \ + "Default Serializer serialized str object incorrectly") test_obj = 123 - assert self.test_serializer.serialize(test_obj) == test_obj, \ - "Default Serializer serialized int object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), test_obj, \ + "Default Serializer serialized int object incorrectly") test_obj = u"test" - assert self.test_serializer.serialize(test_obj) == test_obj, \ - "Default Serializer serialized unicode object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), test_obj, \ + "Default Serializer serialized unicode object incorrectly") test_obj = b"test" - assert self.test_serializer.serialize(test_obj) == test_obj, \ - "Default Serializer serialized bytes object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), test_obj, \ + "Default Serializer serialized bytes object incorrectly") test_obj = False - assert self.test_serializer.serialize(test_obj) == test_obj, \ - "Default Serializer serialized bool object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), test_obj, \ + "Default Serializer serialized bool object incorrectly") def test_list_obj_serialization(self): test_obj_inst = data.ModelTestObject2(int_var=123) test_list_obj = ["test", 123, test_obj_inst] expected_list = ["test", 123, {"var4Int": 123}] - assert self.test_serializer.serialize(test_list_obj) == expected_list, \ - "Default Serializer serialized list object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_list_obj), expected_list, \ + "Default Serializer serialized list object incorrectly") def test_tuple_obj_serialization(self): test_obj_inst = data.ModelTestObject2(int_var=123) test_tuple_obj = ("test", 123, test_obj_inst) expected_tuple = ("test", 123, {"var4Int": 123}) - assert self.test_serializer.serialize(test_tuple_obj) == expected_tuple, \ - "Default Serializer serialized tuple object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_tuple_obj), expected_tuple, \ + "Default Serializer serialized tuple object incorrectly") def test_datetime_obj_serialization(self): test_obj = datetime.datetime(2018, 1, 1, 10, 20, 30) expected_datetime = "2018-01-01T10:20:30" - assert self.test_serializer.serialize(test_obj) == expected_datetime, \ - "Default Serializer serialized datetime object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), expected_datetime, \ + "Default Serializer serialized datetime object incorrectly") def test_date_obj_serialization(self): test_obj = datetime.date(2018, 1, 1) expected_date = "2018-01-01" - assert self.test_serializer.serialize(test_obj) == expected_date, \ - "Default Serializer serialized datetime object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj), expected_date, \ + "Default Serializer serialized datetime object incorrectly") def test_dict_obj_serialization(self): test_obj_inst = data.ModelTestObject2(int_var=123) @@ -112,8 +112,8 @@ def test_dict_obj_serialization(self): }, "test_int": 123, } - assert self.test_serializer.serialize(test_dict_obj) == expected_dict, \ - "Default Serializer serialized dict object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_dict_obj), expected_dict, \ + "Default Serializer serialized dict object incorrectly") def test_model_obj_serialization(self): test_model_obj_2 = data.ModelTestObject2(int_var=123) @@ -128,8 +128,8 @@ def test_model_obj_serialization(self): "var4Int": 123 } } - assert self.test_serializer.serialize(test_model_obj_1) == expected_serialized_obj, \ - "Default Serializer serialized model object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_model_obj_1), expected_serialized_obj, \ + "Default Serializer serialized model object incorrectly") def test_model_obj_without_attrmap_serialization(self): test_obj_inst = data.ModelTestObject3(str_var="test", int_var=123) @@ -137,8 +137,8 @@ def test_model_obj_without_attrmap_serialization(self): "str_var": "test", "int_var": 123 } - assert self.test_serializer.serialize(test_obj_inst) == expected_dict, \ - "Default Serializer serialized object without attribute_map incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj_inst), expected_dict, \ + "Default Serializer serialized object without attribute_map incorrectly") def test_model_obj_with_incomplete_attrmap_serialization(self): test_obj_inst = data.ModelTestObject4(str_var="test", float_var=3.14) @@ -146,8 +146,8 @@ def test_model_obj_with_incomplete_attrmap_serialization(self): "str_var": "test", "floatingValue": 3.14 } - assert self.test_serializer.serialize(test_obj_inst) == expected_dict, \ - "Default Serializer serialized object with incomplete attribute map incorrectly" + self.assertEqual(self.test_serializer.serialize(test_obj_inst), expected_dict, \ + "Default Serializer serialized object with incomplete attribute map incorrectly") def test_enum_obj_serialization(self): test_model_obj_2 = data.ModelTestObject2(int_var=123) @@ -165,32 +165,32 @@ def test_enum_obj_serialization(self): "var4Int": 123 } } - assert self.test_serializer.serialize(test_model_obj_1) == expected_serialized_obj, \ - "Default Serializer serialized enum object incorrectly" + self.assertEqual(self.test_serializer.serialize(test_model_obj_1), expected_serialized_obj, \ + "Default Serializer serialized enum object incorrectly") def test_decimal_obj_without_decimals_serialization(self): test_decimal_obj = decimal.Decimal(10) expected_obj = 10 actual_obj = self.test_serializer.serialize(test_decimal_obj) - assert actual_obj == expected_obj, ( + self.assertEqual(actual_obj, expected_obj, ( "Default Serializer serialized decimal object containing no " - "decimals incorrectly") - assert type(actual_obj) == int, ( + "decimals incorrectly")) + self.assertEqual(type(actual_obj), int, ( "Default Serializer serialized decimal object containing no " - "decimals to incorrect type") + "decimals to incorrect type")) def test_decimal_obj_with_decimals_serialization(self): test_decimal_obj = decimal.Decimal(10.5) expected_obj = 10.5 actual_obj = self.test_serializer.serialize(test_decimal_obj) - assert actual_obj == expected_obj, ( + self.assertEqual(actual_obj, expected_obj, ( "Default Serializer serialized decimal object containing " - "decimals incorrectly") - assert type(actual_obj) == float, ( + "decimals incorrectly")) + self.assertEqual(type(actual_obj), float, ( "Default Serializer serialized decimal object containing " - "decimals to incorrect type") + "decimals to incorrect type")) class TestDeserialization(unittest.TestCase): @@ -200,45 +200,45 @@ def setUp(self): def test_none_obj_deserialization(self): test_payload = None test_obj_type = str - assert self.test_serializer.deserialize( - test_payload, test_obj_type) is None, \ - "Default Serializer deserialized None object incorrectly" + self.assertIsNone(self.test_serializer.deserialize( + test_payload, test_obj_type), "Default " + "Serializer deserialized None object incorrectly") def test_str_obj_deserialization(self): test_payload = "test" test_obj_type = str with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, \ - "Default Serializer deserialized string object incorrectly" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, \ + "Default Serializer deserialized string object incorrectly") def test_unicode_obj_deserialization(self): test_payload = u"√" test_obj_type = unicode_type with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == u"\u221a", \ - "Default Serializer deserialized unicode string object incorrectly" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), u"\u221a", \ + "Default Serializer deserialized unicode string object incorrectly") def test_int_obj_deserialization(self): test_payload = 123 test_obj_type = int with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, \ - "Default Serializer deserialized int object incorrectly" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, \ + "Default Serializer deserialized int object incorrectly") def test_long_obj_deserialization(self): test_payload = 123 test_obj_type = long_type with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == long_type(test_payload), \ - "Default Serializer deserialized long object incorrectly" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), long_type(test_payload), \ + "Default Serializer deserialized long object incorrectly") def test_primitive_obj_deserialization_raising_unicode_exception(self): test_serializer = DefaultSerializer() @@ -251,9 +251,9 @@ def test_primitive_obj_deserialization_raising_unicode_exception(self): test_obj_type = mocked_primitive_type with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert test_serializer.deserialize( - test_payload, test_obj_type) == u"\u221a", \ - "Default Serializer deserialized primitive type which raises UnicodeEncodeError incorrectly" + self.assertEqual(test_serializer.deserialize( + test_payload, test_obj_type), u"\u221a", \ + "Default Serializer deserialized primitive type which raises UnicodeEncodeError incorrectly") def test_primitive_obj_deserialization_raising_type_error(self): test_serializer = DefaultSerializer() @@ -265,9 +265,9 @@ def test_primitive_obj_deserialization_raising_type_error(self): test_obj_type = mocked_primitive_type with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, \ - "Default Serializer deserialized primitive type which raises TypeError incorrectly" + self.assertEqual(test_serializer.deserialize( + test_payload, test_obj_type), test_payload, \ + "Default Serializer deserialized primitive type which raises TypeError incorrectly") def test_primitive_obj_deserialization_raising_value_error(self): test_payload = "test" @@ -278,8 +278,8 @@ def test_primitive_obj_deserialization_raising_value_error(self): mock_json_loader.return_value = test_payload self.test_serializer.deserialize(test_payload, test_obj_type) - assert "Failed to parse test into 'int' object" in str(exc.exception), \ - "Default Serializer didn't throw SerializationException when invalid primitive type is deserialized" + self.assertIn("Failed to parse test into 'int' object", str(exc.exception), \ + "Default Serializer didn't throw SerializationException when invalid primitive type is deserialized") def test_datetime_obj_serialization(self): # payload in iso8601 format @@ -289,8 +289,8 @@ def test_datetime_obj_serialization(self): expected_obj = datetime.datetime(2018, 1, 1, 10, 20, 30) with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize(test_payload, test_obj_type) == expected_obj, \ - "Default Serializer deserialized datetime object incorrectly" + self.assertEqual(self.test_serializer.deserialize(test_payload, test_obj_type), expected_obj, \ + "Default Serializer deserialized datetime object incorrectly") def test_date_obj_serialization(self): # payload in iso8601 format @@ -300,8 +300,8 @@ def test_date_obj_serialization(self): expected_obj = datetime.date(2018, 1, 1) with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize(test_payload, test_obj_type) == expected_obj, \ - "Default Serializer deserialized date object incorrectly" + self.assertEqual(self.test_serializer.deserialize(test_payload, test_obj_type), expected_obj, \ + "Default Serializer deserialized date object incorrectly") def test_datetime_obj_deserialization_raising_value_error(self): test_payload = "abc-wx-yzT25:80:90" @@ -312,8 +312,8 @@ def test_datetime_obj_deserialization_raising_value_error(self): mock_json_loader.return_value = test_payload self.test_serializer.deserialize(test_payload, test_obj_type) - assert "Failed to parse abc-wx-yzT25:80:90 into 'datetime' object" in str(exc.exception), \ - "Default Serializer didn't throw SerializationException when invalid datetime type is deserialized" + self.assertIn("Failed to parse abc-wx-yzT25:80:90 into 'datetime' object", str(exc.exception), \ + "Default Serializer didn't throw SerializationException when invalid datetime type is deserialized") def test_datetime_obj_deserialization_raising_import_error(self): test_payload = "abc-wx-yzT25:80:90" @@ -323,9 +323,9 @@ def test_datetime_obj_deserialization_raising_import_error(self): mock_json_loader.return_value = test_payload with mock.patch('dateutil.parser.parse') as parse_class: parse_class.side_effect = ImportError - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, \ - "Default Serializer didn't return datetime correctly for import errors" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, \ + "Default Serializer didn't return datetime correctly for import errors") parse_class.assert_called_once_with(test_payload) def test_obj_type_deserialization(self): @@ -334,9 +334,9 @@ def test_obj_type_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, \ - "Default Serializer deserialization of object returned other than the object itself" + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, \ + "Default Serializer deserialization of object returned other than the object itself") def test_native_type_mapping_deserialization(self): test_payload = "test" @@ -344,10 +344,10 @@ def test_native_type_mapping_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, ( + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, ( "Default Serializer deserialization of object with object_type of string class under native mapping " - "not deserialized correctly") + "not deserialized correctly")) def test_polymorphic_list_obj_deserialization(self): test_payload = ["test", 123, "2018-01-01T10:20:30"] @@ -358,9 +358,9 @@ def test_polymorphic_list_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized list containing poly type object incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized list containing poly type object incorrectly")) def test_similar_list_obj_deserialization(self): test_payload = ["test", "test1", "2018-01-01T10:20:30"] @@ -369,9 +369,9 @@ def test_similar_list_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized list object containing similar type objects incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized list object containing similar type objects incorrectly")) def test_dict_obj_deserialization(self): test_payload = { @@ -382,9 +382,9 @@ def test_dict_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, ( - "Default Serializer deserialized dict object incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, ( + "Default Serializer deserialized dict object incorrectly")) def test_model_obj_deserialization(self): test_payload = { @@ -404,9 +404,9 @@ def test_model_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized model object incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized model object incorrectly")) def test_model_obj_with_additional_params_in_payload_deserialization(self): test_payload = { @@ -419,9 +419,9 @@ def test_model_obj_with_additional_params_in_payload_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized model object incorrectly when payload has additional parameters") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized model object incorrectly when payload has additional parameters")) def test_model_obj_without_attrmap_deserialization(self): test_payload = { @@ -433,9 +433,9 @@ def test_model_obj_without_attrmap_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized model object without attribute map incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized model object without attribute map incorrectly")) def test_model_obj_with_incomplete_attrmap_deserialization(self): test_payload = { @@ -447,9 +447,9 @@ def test_model_obj_with_incomplete_attrmap_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( - "Default Serializer deserialized model object with incomplete attribute map incorrectly") + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( + "Default Serializer deserialized model object with incomplete attribute map incorrectly")) def test_invalid_model_obj_deserialization(self): test_payload = { @@ -459,10 +459,10 @@ def test_invalid_model_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == test_payload, ( + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), test_payload, ( "Default Serializer didn't provide payload back when an invalid model object type " - "(without attribute map and swagger type dict) is passed") + "(without attribute map and swagger type dict) is passed")) def test_invalid_model_obj_type_deserialization(self): test_payload = { @@ -475,9 +475,9 @@ def test_invalid_model_obj_type_deserialization(self): with self.assertRaises(SerializationException) as exc: self.test_serializer.deserialize(test_payload, test_obj_type) - assert "Unable to resolve class {} from installed modules".format(test_obj_type) in str(exc.exception), ( + self.assertIn("Unable to resolve class {} from installed modules".format(test_obj_type), str(exc.exception), ( "Default Serializer didn't throw SerializationException when deserialization is called with invalid " - "object type") + "object type")) def test_invalid_json_deserialization(self): test_payload = { @@ -490,8 +490,8 @@ def test_invalid_json_deserialization(self): with self.assertRaises(SerializationException) as exc: self.test_serializer.deserialize(test_payload, test_obj_type) - assert "Couldn't parse response body" in str(exc.exception), \ - "Default Serializer didn't throw SerializationException when invalid json is deserialized" + self.assertIn("Couldn't parse response body", str(exc.exception), \ + "Default Serializer didn't throw SerializationException when invalid json is deserialized") def test_parent_model_obj_with_discriminator_deserialization(self): test_payload = { @@ -509,10 +509,10 @@ def test_parent_model_obj_with_discriminator_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( "Default Serializer deserialized model object incorrectly when object type is parent class " - "with discriminator") + "with discriminator")) def test_child_discriminator_model_obj_deserialization(self): test_payload = { @@ -530,10 +530,10 @@ def test_child_discriminator_model_obj_deserialization(self): with patch("json.loads") as mock_json_loader: mock_json_loader.return_value = test_payload - assert self.test_serializer.deserialize( - test_payload, test_obj_type) == expected_obj, ( + self.assertEqual(self.test_serializer.deserialize( + test_payload, test_obj_type), expected_obj, ( "Default Serializer deserialized model object incorrectly when object type is parent class " - "with discriminator") + "with discriminator")) def test_parent_model_obj_with_invalid_discriminator_deserialization(self): test_payload = { @@ -551,6 +551,6 @@ def test_parent_model_obj_with_invalid_discriminator_deserialization(self): with self.assertRaises(SerializationException) as exc: self.test_serializer.deserialize(test_payload, test_obj_type) - assert "Couldn't resolve object by discriminator type" in str(exc.exception), ( + self.assertIn("Couldn't resolve object by discriminator type", str(exc.exception), ( "Default Serializer didn't throw SerializationException when deserialization is called with invalid " - "discriminator type in payload and parent model") + "discriminator type in payload and parent model")) diff --git a/ask-sdk-model-runtime/tests/unit/test_utils.py b/ask-sdk-model-runtime/tests/unit/test_utils.py new file mode 100644 index 0000000..ff686e7 --- /dev/null +++ b/ask-sdk-model-runtime/tests/unit/test_utils.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights +# Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). +# You may not use this file except in compliance with the License. +# A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +# OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the +# License. +# +import sys + +from ask_sdk_model_runtime.utils import user_agent_info +from ask_sdk_model_runtime.__version__ import __version__ + + +def test_user_agent_info_with_no_custom_user_agent(): + py_major_version = str(sys.version_info.major) + py_minor_version = str(sys.version_info.minor) + py_micro_version = str(sys.version_info.micro) + + expected_user_agent = "ask-python-model/{} Python/{}.{}.{}".format( + __version__, py_major_version, py_minor_version, py_micro_version) + assert user_agent_info( + sdk_version=__version__, + custom_user_agent=None) == expected_user_agent, ( + "Incorrect User Agent info for Null custom user agent") + + +def test_user_agent_info_with_custom_user_agent(): + py_major_version = str(sys.version_info.major) + py_minor_version = str(sys.version_info.minor) + py_micro_version = str(sys.version_info.micro) + custom_user_agent = "test" + + expected_user_agent = "ask-python-model/{} Python/{}.{}.{} {}".format( + __version__, py_major_version, py_minor_version, + py_micro_version, custom_user_agent) + assert user_agent_info( + sdk_version=__version__, + custom_user_agent=custom_user_agent) == expected_user_agent, ( + "Incorrect User Agent info for custom user agent") + diff --git a/ask-smapi-model/CHANGELOG.rst b/ask-smapi-model/CHANGELOG.rst index df9e26c..b159aa0 100644 --- a/ask-smapi-model/CHANGELOG.rst +++ b/ask-smapi-model/CHANGELOG.rst @@ -5,4 +5,10 @@ CHANGELOG 1.0.0 ----- -* Initial release of ask smapi models. \ No newline at end of file +* Initial release of ask smapi models. + +1.0.1 +----- + +* Adding User-Agent functionality support to set custom user agent values. +* Updating Model definitions. \ No newline at end of file diff --git a/ask-smapi-model/ask_smapi_model/__version__.py b/ask-smapi-model/ask_smapi_model/__version__.py index 9353c85..f182018 100644 --- a/ask-smapi-model/ask_smapi_model/__version__.py +++ b/ask-smapi-model/ask_smapi_model/__version__.py @@ -14,7 +14,7 @@ __pip_package_name__ = 'ask-smapi-model' __description__ = 'The SMAPI SDK Model package provides model definitions for making Skill Management API calls.' __url__ = 'https://github.com/alexa/alexa-apis-for-python' -__version__ = '1.0.0' +__version__ = '1.0.1' __author__ = 'Alexa Skills Kit' __author_email__ = 'ask-sdk-dynamic@amazon.com' __license__ = 'Apache 2.0' diff --git a/ask-smapi-model/ask_smapi_model/services/skill_management/skill_management_service_client.py b/ask-smapi-model/ask_smapi_model/services/skill_management/skill_management_service_client.py index 4a9b5d3..417da67 100644 --- a/ask-smapi-model/ask_smapi_model/services/skill_management/skill_management_service_client.py +++ b/ask-smapi-model/ask_smapi_model/services/skill_management/skill_management_service_client.py @@ -23,6 +23,7 @@ from ask_sdk_model_runtime.api_configuration import ApiConfiguration from ask_sdk_model_runtime.service_client_response import ServiceClientResponse from ask_sdk_model_runtime.api_response import ApiResponse +from ask_sdk_model_runtime.utils import user_agent_info from ask_sdk_model_runtime.authentication_configuration import AuthenticationConfiguration from ask_sdk_model_runtime.lwa.lwa_client import LwaClient @@ -107,8 +108,8 @@ class SkillManagementServiceClient(BaseServiceClient): :param api_configuration: Instance of ApiConfiguration :type api_configuration: ask_sdk_model_runtime.api_configuration.ApiConfiguration """ - def __init__(self, api_configuration, authentication_configuration, lwa_client=None): - # type: (ApiConfiguration, AuthenticationConfiguration, LwaClient) -> None + def __init__(self, api_configuration, authentication_configuration, lwa_client=None, custom_user_agent=None): + # type: (ApiConfiguration, AuthenticationConfiguration, LwaClient, str) -> None """ :param api_configuration: Instance of :py:class:`ask_sdk_model_runtime.api_configuration.ApiConfiguration` :type api_configuration: ask_sdk_model_runtime.api_configuration.ApiConfiguration @@ -118,8 +119,12 @@ def __init__(self, api_configuration, authentication_configuration, lwa_client=N can be passed when the LwaClient configuration is different from the authentication and api configuration passed :type lwa_client: ask_sdk_model_runtime.lwa.LwaClient + :param custom_user_agent: Custom User Agent string provided by the developer. + :type custom_user_agent: str """ super(SkillManagementServiceClient, self).__init__(api_configuration) + self.user_agent = user_agent_info(sdk_version="1.0.1", custom_user_agent=custom_user_agent) + if lwa_client is None: self._lwa_service_client = LwaClient( api_configuration=ApiConfiguration( @@ -174,6 +179,7 @@ def create_catalog_upload_v1(self, catalog_id, catalog_upload_request_body, **kw if 'catalog_upload_request_body' in params: body_params = params['catalog_upload_request_body'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -254,6 +260,7 @@ def get_content_upload_by_id_v1(self, catalog_id, upload_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -332,6 +339,7 @@ def generate_catalog_upload_url_v1(self, catalog_id, generate_catalog_upload_url if 'generate_catalog_upload_url_request_body' in params: body_params = params['generate_catalog_upload_url_request_body'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -435,6 +443,7 @@ def get_isp_list_for_vendor_v1(self, vendor_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -503,6 +512,7 @@ def create_isp_for_vendor_v1(self, create_in_skill_product_request, **kwargs): if 'create_in_skill_product_request' in params: body_params = params['create_in_skill_product_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -579,6 +589,7 @@ def disassociate_isp_with_skill_v1(self, product_id, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -657,6 +668,7 @@ def associate_isp_with_skill_v1(self, product_id, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -739,6 +751,7 @@ def delete_isp_for_product_v1(self, product_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -818,6 +831,7 @@ def reset_entitlement_for_product_v1(self, product_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -897,6 +911,7 @@ def get_isp_definition_v1(self, product_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -986,6 +1001,7 @@ def update_isp_for_product_v1(self, product_id, stage, update_in_skill_product_r if 'update_in_skill_product_request' in params: body_params = params['update_in_skill_product_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1073,6 +1089,7 @@ def get_isp_associated_skills_v1(self, product_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1149,6 +1166,7 @@ def get_isp_summary_v1(self, product_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1217,6 +1235,7 @@ def delete_interaction_model_catalog_v1(self, catalog_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1288,6 +1307,7 @@ def get_interaction_model_catalog_definition_v1(self, catalog_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1367,6 +1387,7 @@ def update_interaction_model_catalog_v1(self, catalog_id, update_request, **kwar if 'update_request' in params: body_params = params['update_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1446,6 +1467,7 @@ def get_interaction_model_catalog_update_status_v1(self, catalog_id, update_requ body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1525,6 +1547,7 @@ def create_interaction_model_catalog_version_v1(self, catalog_id, catalog, **kwa if 'catalog' in params: body_params = params['catalog'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1604,6 +1627,7 @@ def delete_interaction_model_catalog_version_v1(self, catalog_id, version, **kwa body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1683,6 +1707,7 @@ def get_interaction_model_catalog_version_v1(self, catalog_id, version, **kwargs body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1766,6 +1791,7 @@ def update_interaction_model_catalog_version_v1(self, catalog_id, version, **kwa if 'catalog_update' in params: body_params = params['catalog_update'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1853,6 +1879,7 @@ def get_interaction_model_catalog_values_v1(self, catalog_id, version, **kwargs) body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -1936,6 +1963,7 @@ def list_interaction_model_catalogs_v1(self, vendor_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2007,6 +2035,7 @@ def create_interaction_model_catalog_v1(self, catalog, **kwargs): if 'catalog' in params: body_params = params['catalog'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2078,6 +2107,7 @@ def get_status_of_export_request_v1(self, export_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2159,6 +2189,7 @@ def list_skills_for_vendor_v1(self, vendor_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2228,6 +2259,7 @@ def get_import_status_v1(self, import_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2297,6 +2329,7 @@ def create_skill_package_v1(self, create_skill_with_package_request, **kwargs): if 'create_skill_with_package_request' in params: body_params = params['create_skill_with_package_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2367,6 +2400,7 @@ def create_skill_for_vendor_v1(self, create_skill_request, **kwargs): if 'create_skill_request' in params: body_params = params['create_skill_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2437,6 +2471,7 @@ def get_alexa_hosted_skill_metadata_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2515,6 +2550,7 @@ def generate_credentials_for_alexa_hosted_skill_v1(self, skill_id, hosted_skill_ if 'hosted_skill_repository_credentials_request' in params: body_params = params['hosted_skill_repository_credentials_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2586,6 +2622,7 @@ def end_beta_test_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2657,6 +2694,7 @@ def get_beta_test_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2731,6 +2769,7 @@ def create_beta_test_v1(self, skill_id, **kwargs): if 'create_test_body' in params: body_params = params['create_test_body'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2806,6 +2845,7 @@ def update_beta_test_v1(self, skill_id, **kwargs): if 'create_test_body' in params: body_params = params['create_test_body'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2876,6 +2916,7 @@ def start_beta_test_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -2955,6 +2996,7 @@ def add_testers_to_beta_test_v1(self, skill_id, testers_request, **kwargs): if 'testers_request' in params: body_params = params['testers_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3033,6 +3075,7 @@ def get_list_of_testers_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3111,6 +3154,7 @@ def remove_testers_from_beta_test_v1(self, skill_id, testers_request, **kwargs): if 'testers_request' in params: body_params = params['testers_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3189,6 +3233,7 @@ def request_feedback_from_testers_v1(self, skill_id, testers_request, **kwargs): if 'testers_request' in params: body_params = params['testers_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3268,6 +3313,7 @@ def send_reminder_to_testers_v1(self, skill_id, testers_request, **kwargs): if 'testers_request' in params: body_params = params['testers_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3350,6 +3396,7 @@ def get_certification_review_v1(self, skill_id, certification_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3426,6 +3473,7 @@ def get_certifications_list_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3495,6 +3543,7 @@ def delete_skill_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3617,6 +3666,7 @@ def get_utterance_data_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3699,6 +3749,7 @@ def import_skill_package_v1(self, update_skill_with_package_request, skill_id, * if 'update_skill_with_package_request' in params: body_params = params['update_skill_with_package_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3835,6 +3886,7 @@ def get_skill_metrics_v1(self, skill_id, start_time, end_time, period, metric, s body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3915,6 +3967,7 @@ def simulate_skill_v1(self, skill_id, simulations_api_request, **kwargs): if 'simulations_api_request' in params: body_params = params['simulations_api_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -3996,6 +4049,7 @@ def get_skill_simulation_v1(self, skill_id, simulation_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4066,6 +4120,7 @@ def get_ssl_certificates_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4143,6 +4198,7 @@ def set_ssl_certificates_v1(self, skill_id, ssl_certificate_payload, **kwargs): if 'ssl_certificate_payload' in params: body_params = params['ssl_certificate_payload'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4221,6 +4277,7 @@ def delete_skill_enablement_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4300,6 +4357,7 @@ def get_skill_enablement_status_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4379,6 +4437,7 @@ def set_skill_enablement_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4459,6 +4518,7 @@ def create_export_request_for_skill_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4545,6 +4605,7 @@ def get_isp_list_for_skill_id_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4639,6 +4700,7 @@ def profile_nlu_v1(self, profile_nlu_request, skill_id, stage, locale, **kwargs) if 'profile_nlu_request' in params: body_params = params['profile_nlu_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4725,6 +4787,7 @@ def list_private_distribution_accounts_v1(self, skill_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4812,6 +4875,7 @@ def delete_private_distribution_account_id_v1(self, skill_id, stage, id, **kwarg body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4899,6 +4963,7 @@ def set_private_distribution_account_id_v1(self, skill_id, stage, id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -4978,6 +5043,7 @@ def delete_account_linking_info_v1(self, skill_id, stage_v2, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5056,6 +5122,7 @@ def get_account_linking_info_v1(self, skill_id, stage_v2, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5146,6 +5213,7 @@ def update_account_linking_info_v1(self, skill_id, stage_v2, account_linking_req if 'account_linking_request' in params: body_params = params['account_linking_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5234,6 +5302,7 @@ def get_interaction_model_v1(self, skill_id, stage_v2, locale, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5321,6 +5390,7 @@ def get_interaction_model_metadata_v1(self, skill_id, stage_v2, locale, **kwargs body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5420,6 +5490,7 @@ def set_interaction_model_v1(self, skill_id, stage_v2, locale, interaction_model if 'interaction_model' in params: body_params = params['interaction_model'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5524,6 +5595,7 @@ def list_interaction_model_versions_v1(self, skill_id, stage_v2, locale, **kwarg body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5619,6 +5691,7 @@ def get_interaction_model_version_v1(self, skill_id, stage_v2, locale, version, body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5698,6 +5771,7 @@ def get_skill_manifest_v1(self, skill_id, stage_v2, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5790,6 +5864,7 @@ def update_skill_manifest_v1(self, skill_id, stage_v2, update_skill_request, **k if 'update_skill_request' in params: body_params = params['update_skill_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5880,6 +5955,7 @@ def submit_skill_validation_v1(self, validations_api_request, skill_id, stage, * if 'validations_api_request' in params: body_params = params['validations_api_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -5972,6 +6048,7 @@ def get_skill_validations_v1(self, skill_id, validation_id, stage, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6045,6 +6122,7 @@ def get_skill_status_v1(self, skill_id, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6120,6 +6198,7 @@ def submit_skill_for_certification_v1(self, skill_id, **kwargs): if 'submit_skill_for_certification_request' in params: body_params = params['submit_skill_for_certification_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6199,6 +6278,7 @@ def withdraw_skill_from_certification_v1(self, skill_id, withdraw_request, **kwa if 'withdraw_request' in params: body_params = params['withdraw_request'] header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6262,6 +6342,7 @@ def create_upload_url_v1(self, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6322,6 +6403,7 @@ def get_vendor_list_v1(self, **kwargs): body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False @@ -6398,6 +6480,7 @@ def get_alexa_hosted_skill_user_permissions_v1(self, vendor_id, permission, **kw body_params = None header_params.append(('Content-type', 'application/json')) + header_params.append(('User-Agent', self.user_agent)) # Response Type full_response = False diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/__init__.py b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/__init__.py index a028b1c..8ce01d5 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/__init__.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/__init__.py @@ -53,6 +53,7 @@ from .localized_music_info import LocalizedMusicInfo from .alexa_presentation_apl_interface import AlexaPresentationAplInterface from .flash_briefing_genre import FlashBriefingGenre +from .alexa_presentation_html_interface import AlexaPresentationHtmlInterface from .video_apis_locale import VideoApisLocale from .ssl_certificate_type import SSLCertificateType from .music_request import MusicRequest diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/alexa_presentation_html_interface.py b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/alexa_presentation_html_interface.py new file mode 100644 index 0000000..e988e30 --- /dev/null +++ b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/alexa_presentation_html_interface.py @@ -0,0 +1,106 @@ +# coding: utf-8 + +# +# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file +# except in compliance with the License. A copy of the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for +# the specific language governing permissions and limitations under the License. +# + +import pprint +import re # noqa: F401 +import six +import typing +from enum import Enum +from ask_smapi_model.v1.skill.manifest.interface import Interface + + +if typing.TYPE_CHECKING: + from typing import Dict, List, Optional, Union + from datetime import datetime + + +class AlexaPresentationHtmlInterface(Interface): + """ + Used to declare that the skill uses the Alexa.Presentation.HTML interface. + + + + """ + deserialized_types = { + 'object_type': 'str' + } # type: Dict + + attribute_map = { + 'object_type': 'type' + } # type: Dict + supports_multiple_types = False + + def __init__(self): + # type: () -> None + """Used to declare that the skill uses the Alexa.Presentation.HTML interface. + + """ + self.__discriminator_value = "ALEXA_PRESENTATION_HTML" # type: str + + self.object_type = self.__discriminator_value + super(AlexaPresentationHtmlInterface, self).__init__(object_type=self.__discriminator_value) + + def to_dict(self): + # type: () -> Dict[str, object] + """Returns the model properties as a dict""" + result = {} # type: Dict + + for attr, _ in six.iteritems(self.deserialized_types): + value = getattr(self, attr) + if isinstance(value, list): + result[attr] = list(map( + lambda x: x.to_dict() if hasattr(x, "to_dict") else + x.value if isinstance(x, Enum) else x, + value + )) + elif isinstance(value, Enum): + result[attr] = value.value + elif hasattr(value, "to_dict"): + result[attr] = value.to_dict() + elif isinstance(value, dict): + result[attr] = dict(map( + lambda item: (item[0], item[1].to_dict()) + if hasattr(item[1], "to_dict") else + (item[0], item[1].value) + if isinstance(item[1], Enum) else item, + value.items() + )) + else: + result[attr] = value + + return result + + def to_str(self): + # type: () -> str + """Returns the string representation of the model""" + return pprint.pformat(self.to_dict()) + + def __repr__(self): + # type: () -> str + """For `print` and `pprint`""" + return self.to_str() + + def __eq__(self, other): + # type: (object) -> bool + """Returns true if both objects are equal""" + if not isinstance(other, AlexaPresentationHtmlInterface): + return False + + return self.__dict__ == other.__dict__ + + def __ne__(self, other): + # type: (object) -> bool + """Returns true if both objects are not equal""" + return not self == other diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/audio_interface.py b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/audio_interface.py index 7b6d58e..a929f9c 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/audio_interface.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/audio_interface.py @@ -45,7 +45,7 @@ def __init__(self): """ """ - self.__discriminator_value = "AUDIO" # type: str + self.__discriminator_value = "AUDIO_PLAYER" # type: str self.object_type = self.__discriminator_value super(AudioInterface, self).__init__(object_type=self.__discriminator_value) diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/interface.py b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/interface.py index 49abeec..1142fcc 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/interface.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/interface.py @@ -39,11 +39,13 @@ class Interface(object): | ALEXA_PRESENTATION_APL: :py:class:`ask_smapi_model.v1.skill.manifest.alexa_presentation_apl_interface.AlexaPresentationAplInterface`, | - | VIDEO: :py:class:`ask_smapi_model.v1.skill.manifest.video_app_interface.VideoAppInterface`, + | VIDEO_APP: :py:class:`ask_smapi_model.v1.skill.manifest.video_app_interface.VideoAppInterface`, | | CUSTOM_INTERFACE: :py:class:`ask_smapi_model.v1.skill.manifest.custom_interface.CustomInterface`, | - | AUDIO: :py:class:`ask_smapi_model.v1.skill.manifest.audio_interface.AudioInterface`, + | ALEXA_PRESENTATION_HTML: :py:class:`ask_smapi_model.v1.skill.manifest.alexa_presentation_html_interface.AlexaPresentationHtmlInterface`, + | + | AUDIO_PLAYER: :py:class:`ask_smapi_model.v1.skill.manifest.audio_interface.AudioInterface`, | | GAME_ENGINE: :py:class:`ask_smapi_model.v1.skill.manifest.game_engine_interface.GameEngineInterface`, | @@ -63,9 +65,10 @@ class Interface(object): discriminator_value_class_map = { 'ALEXA_PRESENTATION_APL': 'ask_smapi_model.v1.skill.manifest.alexa_presentation_apl_interface.AlexaPresentationAplInterface', - 'VIDEO': 'ask_smapi_model.v1.skill.manifest.video_app_interface.VideoAppInterface', + 'VIDEO_APP': 'ask_smapi_model.v1.skill.manifest.video_app_interface.VideoAppInterface', 'CUSTOM_INTERFACE': 'ask_smapi_model.v1.skill.manifest.custom_interface.CustomInterface', - 'AUDIO': 'ask_smapi_model.v1.skill.manifest.audio_interface.AudioInterface', + 'ALEXA_PRESENTATION_HTML': 'ask_smapi_model.v1.skill.manifest.alexa_presentation_html_interface.AlexaPresentationHtmlInterface', + 'AUDIO_PLAYER': 'ask_smapi_model.v1.skill.manifest.audio_interface.AudioInterface', 'GAME_ENGINE': 'ask_smapi_model.v1.skill.manifest.game_engine_interface.GameEngineInterface', 'RENDER_TEMPLATE': 'ask_smapi_model.v1.skill.manifest.display_interface.DisplayInterface', 'GADGET_CONTROLLER': 'ask_smapi_model.v1.skill.manifest.gadget_controller_interface.GadgetControllerInterface' diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/video_app_interface.py b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/video_app_interface.py index fb78023..db90f72 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/manifest/video_app_interface.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/manifest/video_app_interface.py @@ -45,7 +45,7 @@ def __init__(self): """ """ - self.__discriminator_value = "VIDEO" # type: str + self.__discriminator_value = "VIDEO_APP" # type: str self.object_type = self.__discriminator_value super(VideoAppInterface, self).__init__(object_type=self.__discriminator_value) diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/__init__.py b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/__init__.py index 0a66f0b..61de994 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/__init__.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/__init__.py @@ -16,7 +16,6 @@ from .simulations_api_response import SimulationsApiResponse from .session_mode import SessionMode -from .invocations import Invocations from .metrics import Metrics from .alexa_execution_info import AlexaExecutionInfo from .simulations_api_request import SimulationsApiRequest @@ -28,4 +27,5 @@ from .alexa_response_content import AlexaResponseContent from .alexa_response import AlexaResponse from .simulation_result import SimulationResult +from .invocation import Invocation from .simulations_api_response_status import SimulationsApiResponseStatus diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocations.py b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocation.py similarity index 98% rename from ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocations.py rename to ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocation.py index c4df783..a73cadb 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocations.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/invocation.py @@ -28,7 +28,7 @@ from ask_smapi_model.v1.skill.simulations.metrics import Metrics -class Invocations(object): +class Invocation(object): """ :param invocation_request: @@ -112,7 +112,7 @@ def __repr__(self): def __eq__(self, other): # type: (object) -> bool """Returns true if both objects are equal""" - if not isinstance(other, Invocations): + if not isinstance(other, Invocation): return False return self.__dict__ == other.__dict__ diff --git a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/simulation_result.py b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/simulation_result.py index 8bce836..ef098b8 100644 --- a/ask-smapi-model/ask_smapi_model/v1/skill/simulations/simulation_result.py +++ b/ask-smapi-model/ask_smapi_model/v1/skill/simulations/simulation_result.py @@ -24,8 +24,8 @@ from typing import Dict, List, Optional, Union from datetime import datetime from ask_smapi_model.v1.error import Error - from ask_smapi_model.v1.skill.simulations.invocations import Invocations from ask_smapi_model.v1.skill.simulations.alexa_execution_info import AlexaExecutionInfo + from ask_smapi_model.v1.skill.simulations.invocation import Invocation class SimulationResult(object): @@ -34,14 +34,14 @@ class SimulationResult(object): :param alexa_execution_info: :type alexa_execution_info: (optional) ask_smapi_model.v1.skill.simulations.alexa_execution_info.AlexaExecutionInfo :param skill_execution_info: - :type skill_execution_info: (optional) list[ask_smapi_model.v1.skill.simulations.invocations.Invocations] + :type skill_execution_info: (optional) ask_smapi_model.v1.skill.simulations.invocation.Invocation :param error: :type error: (optional) ask_smapi_model.v1.error.Error """ deserialized_types = { 'alexa_execution_info': 'ask_smapi_model.v1.skill.simulations.alexa_execution_info.AlexaExecutionInfo', - 'skill_execution_info': 'list[ask_smapi_model.v1.skill.simulations.invocations.Invocations]', + 'skill_execution_info': 'ask_smapi_model.v1.skill.simulations.invocation.Invocation', 'error': 'ask_smapi_model.v1.error.Error' } # type: Dict @@ -53,13 +53,13 @@ class SimulationResult(object): supports_multiple_types = False def __init__(self, alexa_execution_info=None, skill_execution_info=None, error=None): - # type: (Optional[AlexaExecutionInfo], Optional[List[Invocations]], Optional[Error]) -> None + # type: (Optional[AlexaExecutionInfo], Optional[Invocation], Optional[Error]) -> None """ :param alexa_execution_info: :type alexa_execution_info: (optional) ask_smapi_model.v1.skill.simulations.alexa_execution_info.AlexaExecutionInfo :param skill_execution_info: - :type skill_execution_info: (optional) list[ask_smapi_model.v1.skill.simulations.invocations.Invocations] + :type skill_execution_info: (optional) ask_smapi_model.v1.skill.simulations.invocation.Invocation :param error: :type error: (optional) ask_smapi_model.v1.error.Error """