From feafc89594c75d5a75b05b66dea6c3cebc053134 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 9 Nov 2020 14:45:04 -0500 Subject: [PATCH 1/2] add tests --- .../asynctests/test_xms_error.py | 7 +++ .../vanilla/AcceptanceTests/test_xms_error.py | 6 +++ .../aio/operations/_pet_operations.py | 53 ++++++++++++++++++ .../operations/_pet_operations.py | 54 +++++++++++++++++++ 4 files changed, 120 insertions(+) diff --git a/test/vanilla/AcceptanceTests/asynctests/test_xms_error.py b/test/vanilla/AcceptanceTests/asynctests/test_xms_error.py index 4cfeaceb7f6..2074e9b5adf 100644 --- a/test/vanilla/AcceptanceTests/asynctests/test_xms_error.py +++ b/test/vanilla/AcceptanceTests/asynctests/test_xms_error.py @@ -97,3 +97,10 @@ async def test_do_something_error(self, client): with pytest.raises(ResourceNotFoundError) as excinfo: await client.pet.do_something("fetch") + + @pytest.mark.asyncio + async def test_error_deserialization_with_param_name_models(self, client): + with pytest.raises(HttpResponseError) as excinfo: + await client.pet.has_models_param() + assert isinstance(excinfo.value.model, PetSadError) + assert excinfo.value.status_code == 500 diff --git a/test/vanilla/AcceptanceTests/test_xms_error.py b/test/vanilla/AcceptanceTests/test_xms_error.py index f53dede41e6..cf0f68baf5c 100644 --- a/test/vanilla/AcceptanceTests/test_xms_error.py +++ b/test/vanilla/AcceptanceTests/test_xms_error.py @@ -92,6 +92,12 @@ def test_do_something_error(self, client): with pytest.raises(ResourceNotFoundError) as excinfo: client.pet.do_something("fetch") + def test_error_deserialization_with_param_name_models(self, client): + with pytest.raises(HttpResponseError) as excinfo: + client.pet.has_models_param() + assert isinstance(excinfo.value.model, PetSadError) + assert excinfo.value.status_code == 500 + def test_models(self): from xmserrorresponse.models import Animal diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py index ef8c0f6df66..48cedc530a7 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py @@ -153,3 +153,56 @@ async def do_something( return deserialized do_something.metadata = {'url': '/errorStatusCodes/Pets/doSomething/{whatAction}'} # type: ignore + + @distributed_trace_async + async def has_models_param( + self, + models: Optional[str] = "value1", + **kwargs + ) -> None: + """Ensure you can correctly deserialize the returned PetActionError and deserialization doesn't + conflict with the input param name 'models'. + + :param models: Make sure model deserialization doesn't conflic with this param name, which has + input name 'models'. Use client default value in call. + :type models: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 500: lambda response: HttpResponseError(response=response, model=self._deserialize(self.models.PetActionError, response)), + } + error_map.update(kwargs.pop('error_map', {})) + accept = "application/json" + + # Construct URL + url = self.has_models_param.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if models is not None: + query_parameters['models'] = self._serialize.query("models", models, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(self.models.PetActionError, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + has_models_param.metadata = {'url': '/errorStatusCodes/Pets/hasModelsParam'} # type: ignore diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py index fcd2fa6921e..9e6d5fc8e25 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py @@ -159,3 +159,57 @@ def do_something( return deserialized do_something.metadata = {'url': '/errorStatusCodes/Pets/doSomething/{whatAction}'} # type: ignore + + @distributed_trace + def has_models_param( + self, + models="value1", # type: Optional[str] + **kwargs # type: Any + ): + # type: (...) -> None + """Ensure you can correctly deserialize the returned PetActionError and deserialization doesn't + conflict with the input param name 'models'. + + :param models: Make sure model deserialization doesn't conflic with this param name, which has + input name 'models'. Use client default value in call. + :type models: str + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType[None] + error_map = { + 401: ClientAuthenticationError, + 404: ResourceNotFoundError, + 409: ResourceExistsError, + 500: lambda response: HttpResponseError(response=response, model=self._deserialize(self.models.PetActionError, response)), + } + error_map.update(kwargs.pop('error_map', {})) + accept = "application/json" + + # Construct URL + url = self.has_models_param.metadata['url'] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + if models is not None: + query_parameters['models'] = self._serialize.query("models", models, 'str') + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') + + request = self._client.post(url, query_parameters, header_parameters) + pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize(self.models.PetActionError, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + has_models_param.metadata = {'url': '/errorStatusCodes/Pets/hasModelsParam'} # type: ignore From 4dcff4b3510c6728f2cc751222954252e7ea207c Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 10 Nov 2020 17:47:17 -0500 Subject: [PATCH 2/2] regen --- .../aio/operations/_pet_operations.py | 53 ------------------ .../operations/_pet_operations.py | 54 ------------------- 2 files changed, 107 deletions(-) diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py index 48cedc530a7..ef8c0f6df66 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/aio/operations/_pet_operations.py @@ -153,56 +153,3 @@ async def do_something( return deserialized do_something.metadata = {'url': '/errorStatusCodes/Pets/doSomething/{whatAction}'} # type: ignore - - @distributed_trace_async - async def has_models_param( - self, - models: Optional[str] = "value1", - **kwargs - ) -> None: - """Ensure you can correctly deserialize the returned PetActionError and deserialization doesn't - conflict with the input param name 'models'. - - :param models: Make sure model deserialization doesn't conflic with this param name, which has - input name 'models'. Use client default value in call. - :type models: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) - :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType[None] - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 500: lambda response: HttpResponseError(response=response, model=self._deserialize(self.models.PetActionError, response)), - } - error_map.update(kwargs.pop('error_map', {})) - accept = "application/json" - - # Construct URL - url = self.has_models_param.metadata['url'] # type: ignore - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - if models is not None: - query_parameters['models'] = self._serialize.query("models", models, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.post(url, query_parameters, header_parameters) - pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(self.models.PetActionError, response) - raise HttpResponseError(response=response, model=error) - - if cls: - return cls(pipeline_response, None, {}) - - has_models_param.metadata = {'url': '/errorStatusCodes/Pets/hasModelsParam'} # type: ignore diff --git a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py index 9e6d5fc8e25..fcd2fa6921e 100644 --- a/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/XmsErrorResponse/xmserrorresponse/operations/_pet_operations.py @@ -159,57 +159,3 @@ def do_something( return deserialized do_something.metadata = {'url': '/errorStatusCodes/Pets/doSomething/{whatAction}'} # type: ignore - - @distributed_trace - def has_models_param( - self, - models="value1", # type: Optional[str] - **kwargs # type: Any - ): - # type: (...) -> None - """Ensure you can correctly deserialize the returned PetActionError and deserialization doesn't - conflict with the input param name 'models'. - - :param models: Make sure model deserialization doesn't conflic with this param name, which has - input name 'models'. Use client default value in call. - :type models: str - :keyword callable cls: A custom type or function that will be passed the direct response - :return: None, or the result of cls(response) - :rtype: None - :raises: ~azure.core.exceptions.HttpResponseError - """ - cls = kwargs.pop('cls', None) # type: ClsType[None] - error_map = { - 401: ClientAuthenticationError, - 404: ResourceNotFoundError, - 409: ResourceExistsError, - 500: lambda response: HttpResponseError(response=response, model=self._deserialize(self.models.PetActionError, response)), - } - error_map.update(kwargs.pop('error_map', {})) - accept = "application/json" - - # Construct URL - url = self.has_models_param.metadata['url'] # type: ignore - - # Construct parameters - query_parameters = {} # type: Dict[str, Any] - if models is not None: - query_parameters['models'] = self._serialize.query("models", models, 'str') - - # Construct headers - header_parameters = {} # type: Dict[str, Any] - header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - - request = self._client.post(url, query_parameters, header_parameters) - pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) - response = pipeline_response.http_response - - if response.status_code not in [200]: - map_error(status_code=response.status_code, response=response, error_map=error_map) - error = self._deserialize(self.models.PetActionError, response) - raise HttpResponseError(response=response, model=error) - - if cls: - return cls(pipeline_response, None, {}) - - has_models_param.metadata = {'url': '/errorStatusCodes/Pets/hasModelsParam'} # type: ignore