diff --git a/package.json b/package.json index 2f43c1de285..97ad1a3d9a1 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "devDependencies": { "@autorest/autorest": "^3.0.0", - "@microsoft.azure/autorest.testserver": "^3.0.9" + "@microsoft.azure/autorest.testserver": "^3.0.15" }, "files": [ "autorest/**/*.py", diff --git a/test/vanilla/AcceptanceTests/asynctests/test_required_optional.py b/test/vanilla/AcceptanceTests/asynctests/test_required_optional.py index 70190c43a94..b825c635992 100644 --- a/test/vanilla/AcceptanceTests/asynctests/test_required_optional.py +++ b/test/vanilla/AcceptanceTests/asynctests/test_required_optional.py @@ -30,6 +30,7 @@ import sys import isodate import os +import io from datetime import date, datetime, timedelta from os.path import dirname, pardir, join, realpath @@ -138,3 +139,20 @@ async def test_post_required_class(self, client): with pytest.raises(ValidationError): await client.explicit.post_required_class_property(None) + + @pytest.mark.asyncio + async def test_explict_put_optional_binary_body(self, client): + await client.explicit.put_optional_binary_body() + + @pytest.mark.asyncio + async def test_explict_put_required_binary_body(self, client): + test_string = "Upload file test case" + test_bytes = bytearray(test_string, encoding='utf-8') + result = io.BytesIO() + with io.BytesIO(test_bytes) as stream_data: + await client.explicit.put_required_binary_body(stream_data) + + + @pytest.mark.asyncio + async def test_implicit_put_optional_binary_body(self, client): + await client.implicit.put_optional_binary_body() \ No newline at end of file diff --git a/test/vanilla/AcceptanceTests/test_required_optional.py b/test/vanilla/AcceptanceTests/test_required_optional.py index 2d71ee16f80..399f53c531b 100644 --- a/test/vanilla/AcceptanceTests/test_required_optional.py +++ b/test/vanilla/AcceptanceTests/test_required_optional.py @@ -29,6 +29,7 @@ import sys import isodate import os +import io from datetime import date, datetime, timedelta from os.path import dirname, pardir, join, realpath @@ -135,3 +136,15 @@ def test_models(self): else: from requiredoptional.models._models import Error as ErrorPy2 assert Error == ErrorPy2 + + def test_explict_put_optional_binary_body(self, client): + client.explicit.put_optional_binary_body() + + def test_explict_put_required_binary_body(self, client): + test_string = "Upload file test case" + test_bytes = bytearray(test_string, encoding='utf-8') + with io.BytesIO(test_bytes) as stream_data: + client.explicit.put_required_binary_body(stream_data) + + def test_implicit_put_optional_binary_body(self, client): + client.implicit.put_optional_binary_body() diff --git a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_explicit_operations.py b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_explicit_operations.py index 96cb1806f86..432248419ab 100644 --- a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_explicit_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_explicit_operations.py @@ -5,7 +5,7 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar +from typing import Any, Callable, Dict, Generic, IO, List, Optional, TypeVar import warnings from azure.core.exceptions import ( @@ -47,6 +47,94 @@ def __init__(self, client, config, serializer, deserializer) -> None: self._deserialize = deserializer self._config = config + @distributed_trace_async + async def put_optional_binary_body(self, body_parameter: Optional[IO] = None, **kwargs) -> None: + """Test explicitly optional body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_optional_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_optional_binary_body.metadata = {"url": "/reqopt/explicit/optional/binary-body"} # type: ignore + + @distributed_trace_async + async def put_required_binary_body(self, body_parameter: IO, **kwargs) -> None: + """Test explicitly required body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_required_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_required_binary_body.metadata = {"url": "/reqopt/explicit/required/binary-body"} # type: ignore + @distributed_trace_async async def post_required_integer_parameter(self, body_parameter: int, **kwargs) -> None: """Test explicitly required integer. Please put null and the client library should throw before diff --git a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_implicit_operations.py b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_implicit_operations.py index b3a1d60c090..8b33740eae4 100644 --- a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_implicit_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/aio/operations/_implicit_operations.py @@ -5,7 +5,7 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -from typing import Any, Callable, Dict, Generic, Optional, TypeVar +from typing import Any, Callable, Dict, Generic, IO, Optional, TypeVar import warnings from azure.core.exceptions import ( @@ -223,6 +223,50 @@ async def put_optional_body(self, body_parameter: Optional[str] = None, **kwargs put_optional_body.metadata = {"url": "/reqopt/implicit/optional/body"} # type: ignore + @distributed_trace_async + async def put_optional_binary_body(self, body_parameter: Optional[IO] = None, **kwargs) -> None: + """Test implicitly optional body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_optional_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_optional_binary_body.metadata = {"url": "/reqopt/implicit/optional/binary-body"} # type: ignore + @distributed_trace_async async def get_required_global_path(self, **kwargs) -> None: """Test implicitly required path parameter. diff --git a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_explicit_operations.py b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_explicit_operations.py index 23542cae9ab..1f6a636fd98 100644 --- a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_explicit_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_explicit_operations.py @@ -23,7 +23,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar + from typing import Any, Callable, Dict, Generic, IO, List, Optional, TypeVar T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -51,6 +51,104 @@ def __init__(self, client, config, serializer, deserializer): self._deserialize = deserializer self._config = config + @distributed_trace + def put_optional_binary_body( + self, + body_parameter=None, # type: Optional[IO] + **kwargs # type: Any + ): + # type: (...) -> None + """Test explicitly optional body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_optional_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_optional_binary_body.metadata = {"url": "/reqopt/explicit/optional/binary-body"} # type: ignore + + @distributed_trace + def put_required_binary_body( + self, + body_parameter, # type: IO + **kwargs # type: Any + ): + # type: (...) -> None + """Test explicitly required body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_required_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_required_binary_body.metadata = {"url": "/reqopt/explicit/required/binary-body"} # type: ignore + @distributed_trace def post_required_integer_parameter( self, diff --git a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_implicit_operations.py b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_implicit_operations.py index 3b309501a57..093d433caf9 100644 --- a/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_implicit_operations.py +++ b/test/vanilla/Expected/AcceptanceTests/RequiredOptional/requiredoptional/operations/_implicit_operations.py @@ -23,7 +23,7 @@ if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, Optional, TypeVar + from typing import Any, Callable, Dict, Generic, IO, Optional, TypeVar T = TypeVar("T") ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -247,6 +247,55 @@ def put_optional_body( put_optional_body.metadata = {"url": "/reqopt/implicit/optional/body"} # type: ignore + @distributed_trace + def put_optional_binary_body( + self, + body_parameter=None, # type: Optional[IO] + **kwargs # type: Any + ): + # type: (...) -> None + """Test implicitly optional body parameter. + + :param body_parameter: + :type body_parameter: IO + :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} + error_map.update(kwargs.pop("error_map", {})) + content_type = kwargs.pop("content_type", "application/octet-stream") + accept = "application/json" + + # Construct URL + url = self.put_optional_binary_body.metadata["url"] # type: ignore + + # Construct parameters + query_parameters = {} # type: Dict[str, Any] + + # Construct headers + header_parameters = {} # type: Dict[str, Any] + header_parameters["Content-Type"] = self._serialize.header("content_type", content_type, "str") + header_parameters["Accept"] = self._serialize.header("accept", accept, "str") + + body_content_kwargs = {} # type: Dict[str, Any] + body_content_kwargs["stream_content"] = body_parameter + request = self._client.put(url, query_parameters, header_parameters, **body_content_kwargs) + 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.failsafe_deserialize(_models.Error, response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + put_optional_binary_body.metadata = {"url": "/reqopt/implicit/optional/binary-body"} # type: ignore + @distributed_trace def get_required_global_path( self, **kwargs # type: Any