-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support and tests for anything (#946)
- Loading branch information
1 parent
6f54c97
commit 6b12df5
Showing
28 changed files
with
1,072 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,9 +27,9 @@ contact [[email protected]](mailto:[email protected]) with any additio | |
pass-thru: | ||
- model-deduplicator | ||
- subset-reducer | ||
version: ^3.1.0 | ||
version: ~3.3.0 | ||
use-extension: | ||
"@autorest/modelerfour": ^4.15.456 | ||
"@autorest/modelerfour": ~4.19.1 | ||
|
||
modelerfour: | ||
group-parameters: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
|
||
__all__ = [ | ||
"AzureKeyCredentialSchema", | ||
"AnySchema", | ||
"BaseModel", | ||
"BaseSchema", | ||
"CodeModel", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import pytest | ||
from async_generator import yield_, async_generator | ||
from anything.aio import AnythingClient | ||
|
||
@pytest.fixture | ||
@async_generator | ||
async def client(): | ||
async with AnythingClient(base_url="http://localhost:3000") as client: | ||
await yield_(client) | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_string(client): | ||
assert await client.get_string() == 'anything' | ||
|
||
@pytest.mark.asyncio | ||
async def test_put_string(client): | ||
await client.put_string(input="anything") | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_object(client): | ||
assert await client.get_object() == {"message": "An object was successfully returned"} | ||
|
||
@pytest.mark.asyncio | ||
async def test_put_object(client): | ||
await client.put_object({'foo': 'bar'}) | ||
|
||
@pytest.mark.asyncio | ||
async def test_get_array(client): | ||
assert await client.get_array() == ['foo', 'bar'] | ||
|
||
@pytest.mark.asyncio | ||
async def test_put_array(client): | ||
await client.put_array(['foo', 'bar']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# | ||
# The MIT License (MIT) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the ""Software""), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
# | ||
# -------------------------------------------------------------------------- | ||
import pytest | ||
from anything import AnythingClient | ||
|
||
@pytest.fixture | ||
def client(): | ||
with AnythingClient(base_url="http://localhost:3000") as client: | ||
yield client | ||
|
||
def test_get_string(client): | ||
assert client.get_string() == 'anything' | ||
|
||
def test_put_string(client): | ||
client.put_string(input="anything") | ||
|
||
def test_get_object(client): | ||
assert client.get_object() == {"message": "An object was successfully returned"} | ||
|
||
def test_put_object(client): | ||
client.put_object({'foo': 'bar'}) | ||
|
||
def test_get_array(client): | ||
assert client.get_array() == ['foo', 'bar'] | ||
|
||
def test_put_array(client): | ||
client.put_array(['foo', 'bar']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
test/vanilla/Expected/AcceptanceTests/Anything/anything/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._anything_client import AnythingClient | ||
from ._version import VERSION | ||
|
||
__version__ = VERSION | ||
__all__ = ["AnythingClient"] | ||
|
||
try: | ||
from ._patch import patch_sdk # type: ignore | ||
|
||
patch_sdk() | ||
except ImportError: | ||
pass |
72 changes: 72 additions & 0 deletions
72
test/vanilla/Expected/AcceptanceTests/Anything/anything/_anything_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# 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 TYPE_CHECKING | ||
|
||
from azure.core import PipelineClient | ||
from msrest import Deserializer, Serializer | ||
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any, Dict, Optional | ||
|
||
from azure.core.pipeline.transport import HttpRequest, HttpResponse | ||
|
||
from ._configuration import AnythingClientConfiguration | ||
from .operations import AnythingClientOperationsMixin | ||
|
||
|
||
class AnythingClient(AnythingClientOperationsMixin): | ||
"""Service client for testing basic anything types. Those schemas without types can be anything: primitive, object, array. | ||
:param str base_url: Service URL | ||
""" | ||
|
||
def __init__( | ||
self, | ||
base_url=None, # type: Optional[str] | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
if not base_url: | ||
base_url = "http://localhost:3000" | ||
self._config = AnythingClientConfiguration(**kwargs) | ||
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) | ||
|
||
client_models = {} # type: Dict[str, Any] | ||
self._serialize = Serializer(client_models) | ||
self._serialize.client_side_validation = False | ||
self._deserialize = Deserializer(client_models) | ||
|
||
def _send_request(self, http_request, **kwargs): | ||
# type: (HttpRequest, Any) -> HttpResponse | ||
"""Runs the network request through the client's chained policies. | ||
:param http_request: The network request you want to make. Required. | ||
:type http_request: ~azure.core.pipeline.transport.HttpRequest | ||
:keyword bool stream: Whether the response payload will be streamed. Defaults to True. | ||
:return: The response of your network call. Does not do error handling on your response. | ||
:rtype: ~azure.core.pipeline.transport.HttpResponse | ||
""" | ||
http_request.url = self._client.format_url(http_request.url) | ||
stream = kwargs.pop("stream", True) | ||
pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) | ||
return pipeline_response.http_response | ||
|
||
def close(self): | ||
# type: () -> None | ||
self._client.close() | ||
|
||
def __enter__(self): | ||
# type: () -> AnythingClient | ||
self._client.__enter__() | ||
return self | ||
|
||
def __exit__(self, *exc_details): | ||
# type: (Any) -> None | ||
self._client.__exit__(*exc_details) |
Oops, something went wrong.