Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch up with tests #879

Merged
merged 3 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions test/vanilla/AcceptanceTests/asynctests/test_required_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
13 changes: 13 additions & 0 deletions test/vanilla/AcceptanceTests/test_required_optional.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -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,
Expand Down
Loading