From c3220f0f073d23450e26b37831aaee854d50bf54 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Thu, 28 May 2020 11:13:10 -0400 Subject: [PATCH] include new testserver test for paging model whose item name has an x-ms-client-name --- package.json | 2 +- .../AcceptanceTests/asynctests/test_paging.py | 8 +++ test/azure/AcceptanceTests/test_paging.py | 5 ++ .../_paging_operations_async.py | 59 ++++++++++++++++++ .../Paging/paging/models/__init__.py | 3 + .../Paging/paging/models/_models.py | 23 +++++++ .../Paging/paging/models/_models_py3.py | 26 ++++++++ .../paging/operations/_paging_operations.py | 60 +++++++++++++++++++ 8 files changed, 185 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5617c6fbf55..62ca7a27e00 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "devDependencies": { "@autorest/autorest": "^3.0.0", "@azure-tools/extension": "^3.0.249", - "@microsoft.azure/autorest.testserver": "^2.10.38" + "@microsoft.azure/autorest.testserver": "^2.10.40" }, "files": [ "autorest/**/*.py", diff --git a/test/azure/AcceptanceTests/asynctests/test_paging.py b/test/azure/AcceptanceTests/asynctests/test_paging.py index cb9dfb5fb49..a2282186e12 100644 --- a/test/azure/AcceptanceTests/asynctests/test_paging.py +++ b/test/azure/AcceptanceTests/asynctests/test_paging.py @@ -223,3 +223,11 @@ async def test_get_multiple_pages_lro(client): assert len(page1.values) == 1 assert page1.values[0].properties.id == 1 assert page1.next_link.endswith("paging/multiple/page/2") + +@pytest.mark.asyncio +async def test_item_name_with_xms_client_name(client): + pages = client.paging.get_paging_model_with_item_name_with_xms_client_name() + items = [] + async for item in pages: + items.append(item) + assert len(items) == 1 diff --git a/test/azure/AcceptanceTests/test_paging.py b/test/azure/AcceptanceTests/test_paging.py index 1df4b4bced0..05f4709ba09 100644 --- a/test/azure/AcceptanceTests/test_paging.py +++ b/test/azure/AcceptanceTests/test_paging.py @@ -170,3 +170,8 @@ def test_get_multiple_pages_lro(client): assert len(page1.values) == 1 assert page1.values[0].properties.id == 1 assert page1.next_link.endswith("paging/multiple/page/2") + +def test_item_name_with_xms_client_name(client): + pages = client.paging.get_paging_model_with_item_name_with_xms_client_name() + items = [i for i in pages] + assert len(items) == 1 diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py index 6c969876e16..c37af9831ca 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/aio/operations_async/_paging_operations_async.py @@ -1070,3 +1070,62 @@ def get_long_running_output(pipeline_response): else: polling_method = polling return await async_poller(self._client, raw_result, get_long_running_output, polling_method) get_multiple_pages_lro.metadata = {'url': '/paging/multiple/lro'} # type: ignore + + @distributed_trace + def get_paging_model_with_item_name_with_xms_client_name( + self, + **kwargs + ) -> AsyncIterable["models.ProductResultValueWithXMSClientName"]: + """A paging operation that returns a paging model whose item name is is overriden by x-ms-client- + name 'indexes'. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProductResultValueWithXMSClientName or the result of cls(response) + :rtype: ~azure.core.async_paging.AsyncItemPaged[~paging.models.ProductResultValueWithXMSClientName] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResultValueWithXMSClientName"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.get_paging_model_with_item_name_with_xms_client_name.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + async def extract_data(pipeline_response): + deserialized = self._deserialize('ProductResultValueWithXMSClientName', pipeline_response) + list_of_elem = deserialized.indexes + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, AsyncList(list_of_elem) + + async def get_next(next_link=None): + request = prepare_request(next_link) + + 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) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return AsyncItemPaged( + get_next, extract_data + ) + get_paging_model_with_item_name_with_xms_client_name.metadata = {'url': '/paging/itemNameWithXMSClientName'} # type: ignore diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py index 7b47cf9c471..865518351bf 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/__init__.py @@ -18,6 +18,7 @@ from ._models_py3 import ProductProperties from ._models_py3 import ProductResult from ._models_py3 import ProductResultValue + from ._models_py3 import ProductResultValueWithXMSClientName except (SyntaxError, ImportError): from ._models import CustomParameterGroup # type: ignore from ._models import OdataProductResult # type: ignore @@ -30,6 +31,7 @@ from ._models import ProductProperties # type: ignore from ._models import ProductResult # type: ignore from ._models import ProductResultValue # type: ignore + from ._models import ProductResultValueWithXMSClientName # type: ignore from ._auto_rest_paging_test_service_enums import ( OperationResultStatus, @@ -47,5 +49,6 @@ 'ProductProperties', 'ProductResult', 'ProductResultValue', + 'ProductResultValueWithXMSClientName', 'OperationResultStatus', ] diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py index 9f3232171bb..34d9c17d658 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models.py @@ -275,3 +275,26 @@ def __init__( super(ProductResultValue, self).__init__(**kwargs) self.value = kwargs.get('value', None) self.next_link = kwargs.get('next_link', None) + + +class ProductResultValueWithXMSClientName(msrest.serialization.Model): + """ProductResultValueWithXMSClientName. + + :param indexes: + :type indexes: list[~paging.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'indexes': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(ProductResultValueWithXMSClientName, self).__init__(**kwargs) + self.indexes = kwargs.get('indexes', None) + self.next_link = kwargs.get('next_link', None) diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py index 8bffe0e249f..54edeb96bc6 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/models/_models_py3.py @@ -311,3 +311,29 @@ def __init__( super(ProductResultValue, self).__init__(**kwargs) self.value = value self.next_link = next_link + + +class ProductResultValueWithXMSClientName(msrest.serialization.Model): + """ProductResultValueWithXMSClientName. + + :param indexes: + :type indexes: list[~paging.models.Product] + :param next_link: + :type next_link: str + """ + + _attribute_map = { + 'indexes': {'key': 'values', 'type': '[Product]'}, + 'next_link': {'key': 'nextLink', 'type': 'str'}, + } + + def __init__( + self, + *, + indexes: Optional[List["Product"]] = None, + next_link: Optional[str] = None, + **kwargs + ): + super(ProductResultValueWithXMSClientName, self).__init__(**kwargs) + self.indexes = indexes + self.next_link = next_link diff --git a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py index 32c705d15ab..e228bf9585d 100644 --- a/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py +++ b/test/azure/Expected/AcceptanceTests/Paging/paging/operations/_paging_operations.py @@ -1089,3 +1089,63 @@ def get_long_running_output(pipeline_response): else: polling_method = polling return LROPoller(self._client, raw_result, get_long_running_output, polling_method) begin_get_multiple_pages_lro.metadata = {'url': '/paging/multiple/lro'} # type: ignore + + @distributed_trace + def get_paging_model_with_item_name_with_xms_client_name( + self, + **kwargs # type: Any + ): + # type: (...) -> Iterable["models.ProductResultValueWithXMSClientName"] + """A paging operation that returns a paging model whose item name is is overriden by x-ms-client- + name 'indexes'. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: An iterator like instance of either ProductResultValueWithXMSClientName or the result of cls(response) + :rtype: ~azure.core.paging.ItemPaged[~paging.models.ProductResultValueWithXMSClientName] + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop('cls', None) # type: ClsType["models.ProductResultValueWithXMSClientName"] + error_map = {404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop('error_map', {})) + + def prepare_request(next_link=None): + if not next_link: + # Construct URL + url = self.get_paging_model_with_item_name_with_xms_client_name.metadata['url'] # type: ignore + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + else: + url = next_link + query_parameters = {} # type: Dict[str, Any] + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = 'application/json' + + # Construct and send request + request = self._client.get(url, query_parameters, header_parameters) + return request + + def extract_data(pipeline_response): + deserialized = self._deserialize('ProductResultValueWithXMSClientName', pipeline_response) + list_of_elem = deserialized.indexes + if cls: + list_of_elem = cls(list_of_elem) + return deserialized.next_link or None, iter(list_of_elem) + + def get_next(next_link=None): + request = prepare_request(next_link) + + 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) + raise HttpResponseError(response=response, error_format=ARMErrorFormat) + + return pipeline_response + + return ItemPaged( + get_next, extract_data + ) + get_paging_model_with_item_name_with_xms_client_name.metadata = {'url': '/paging/itemNameWithXMSClientName'} # type: ignore