-
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.
custom base url with different host templates across multiapi versions (
#719)
- Loading branch information
1 parent
e1a9789
commit e5c551f
Showing
50 changed files
with
1,929 additions
and
19 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
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
52 changes: 52 additions & 0 deletions
52
test/multiapi/AcceptanceTests/asynctests/test_multiapi_custom_base_url.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,52 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# 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 multiapicustombaseurl.aio import MultiapiCustomBaseUrlServiceClient | ||
|
||
@pytest.fixture | ||
@async_generator | ||
async def client(credential, authentication_policy, api_version): | ||
|
||
async with MultiapiCustomBaseUrlServiceClient( | ||
endpoint="http://localhost:3000", | ||
api_version=api_version, | ||
credential=credential, | ||
authentication_policy=authentication_policy | ||
) as client: | ||
await yield_(client) | ||
|
||
class TestMultiapiCustomBaseUrl(object): | ||
|
||
@pytest.mark.parametrize('api_version', ["1.0.0"]) | ||
@pytest.mark.asyncio | ||
async def test_custom_base_url_version_one(self, client): | ||
await client.test(id=1) | ||
|
||
@pytest.mark.parametrize('api_version', ["2.0.0"]) | ||
@pytest.mark.asyncio | ||
async def test_custom_base_url_version_two(self, client): | ||
await client.test(id=2) |
48 changes: 48 additions & 0 deletions
48
test/multiapi/AcceptanceTests/test_multiapi_custom_base_url.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,48 @@ | ||
# -------------------------------------------------------------------------- | ||
# | ||
# 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 multiapicustombaseurl import MultiapiCustomBaseUrlServiceClient | ||
|
||
@pytest.fixture | ||
def client(credential, authentication_policy, api_version): | ||
|
||
with MultiapiCustomBaseUrlServiceClient( | ||
endpoint="http://localhost:3000", | ||
api_version=api_version, | ||
credential=credential, | ||
authentication_policy=authentication_policy | ||
) as client: | ||
yield client | ||
|
||
class TestMultiapiCustomBaseUrl(object): | ||
|
||
@pytest.mark.parametrize('api_version', ["1.0.0"]) | ||
def test_custom_base_url_version_one(self, client): | ||
client.test(id=1) | ||
|
||
@pytest.mark.parametrize('api_version', ["2.0.0"]) | ||
def test_custom_base_url_version_two(self, client): | ||
client.test(id=2) |
16 changes: 16 additions & 0 deletions
16
...multiapi/Expected/AcceptanceTests/MultiapiCustomBaseUrl/multiapicustombaseurl/__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,16 @@ | ||
# 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 ._multiapi_custom_base_url_service_client import MultiapiCustomBaseUrlServiceClient | ||
__all__ = ['MultiapiCustomBaseUrlServiceClient'] | ||
|
||
try: | ||
from ._patch import patch_sdk # type: ignore | ||
patch_sdk() | ||
except ImportError: | ||
pass |
68 changes: 68 additions & 0 deletions
68
...pi/Expected/AcceptanceTests/MultiapiCustomBaseUrl/multiapicustombaseurl/_configuration.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,68 @@ | ||
# 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 Any | ||
|
||
from azure.core.configuration import Configuration | ||
from azure.core.pipeline import policies | ||
|
||
from ._version import VERSION | ||
|
||
|
||
class MultiapiCustomBaseUrlServiceClientConfiguration(Configuration): | ||
"""Configuration for MultiapiCustomBaseUrlServiceClient. | ||
Note that all parameters used to create this instance are saved as instance | ||
attributes. | ||
:param credential: Credential needed for the client to connect to Azure. | ||
:type credential: ~azure.core.credentials.TokenCredential | ||
:param endpoint: Pass in https://localhost:3000. | ||
:type endpoint: str | ||
""" | ||
|
||
def __init__( | ||
self, | ||
credential, # type: "TokenCredential" | ||
endpoint, # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
if credential is None: | ||
raise ValueError("Parameter 'credential' must not be None.") | ||
if endpoint is None: | ||
raise ValueError("Parameter 'endpoint' must not be None.") | ||
super(MultiapiCustomBaseUrlServiceClientConfiguration, self).__init__(**kwargs) | ||
|
||
self.credential = credential | ||
self.endpoint = endpoint | ||
self.credential_scopes = [] | ||
self.credential_scopes.extend(kwargs.pop('credential_scopes', [])) | ||
kwargs.setdefault('sdk_moniker', 'multiapicustombaseurl/{}'.format(VERSION)) | ||
self._configure(**kwargs) | ||
|
||
def _configure( | ||
self, | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) | ||
self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) | ||
self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) | ||
self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) | ||
self.http_logging_policy = kwargs.get('http_logging_policy') or policies.HttpLoggingPolicy(**kwargs) | ||
self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) | ||
self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) | ||
self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) | ||
self.authentication_policy = kwargs.get('authentication_policy') | ||
if not self.credential_scopes and not self.authentication_policy: | ||
raise ValueError("You must provide either credential_scopes or authentication_policy as kwargs") | ||
if self.credential and not self.authentication_policy: | ||
self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) |
Oops, something went wrong.