Skip to content

Commit

Permalink
add parameter and versioning tests (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
iscai-msft authored May 6, 2024
1 parent 03910c8 commit a1cb0be
Show file tree
Hide file tree
Showing 508 changed files with 63,472 additions and 25 deletions.
4 changes: 2 additions & 2 deletions packages/autorest.python/autorest/codegen/models/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
self.wire_name: str = yaml_data.get("wireName", "")
self.client_name: str = self.yaml_data["clientName"]
self.optional: bool = self.yaml_data["optional"]
self.implementation: str = yaml_data.get("implementation", None)
self.location: ParameterLocation = self.yaml_data["location"]
self.client_default_value = self.yaml_data.get("clientDefaultValue", None)
self.in_docstring = self.yaml_data.get("inDocstring", True)
Expand Down Expand Up @@ -170,7 +171,7 @@ def _imports_shared(self, async_mode: bool, **_: Any) -> FileImport:
file_import = FileImport(self.code_model)
if self.optional and self.client_default_value is None:
file_import.add_submodule_import("typing", "Optional", ImportType.STDLIB)
if self.added_on:
if self.added_on and self.implementation != "Client":
file_import.add_submodule_import(
f"{'.' if async_mode else ''}.._validation",
"api_version_validation",
Expand Down Expand Up @@ -328,7 +329,6 @@ def __init__(
) -> None:
super().__init__(yaml_data, code_model, type=type)

self.implementation: str = yaml_data["implementation"]
self.skip_url_encoding: bool = self.yaml_data.get("skipUrlEncoding", False)
self.explode: bool = self.yaml_data.get("explode", False)
self.in_overriden: bool = self.yaml_data.get("inOverriden", False)
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.41.0",
"@azure-tools/typespec-autorest": "~0.41.0",
"@azure-tools/cadl-ranch-expect": "~0.13.3",
"@azure-tools/cadl-ranch-specs": "~0.33.0",
"@azure-tools/cadl-ranch-specs": "~0.33.1",
"@types/js-yaml": "~4.0.5",
"@types/mocha": "~10.0.1",
"@types/node": "^18.16.3",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Release History

## 1.0.0b1 (1970-01-01)

- Initial version
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Copyright (c) Microsoft Corporation.

MIT License

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include *.md
include LICENSE
include parameters/basic/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@


# Parameters Basic client library for Python
<!-- write necessary description of service -->

## Getting started

### Install the package

```bash
python -m pip install parameters-basic
```

#### Prequisites

- Python 3.8 or later is required to use this package.
- You need an [Azure subscription][azure_sub] to use this package.
- An existing Parameters Basic instance.

## Contributing

This project welcomes contributions and suggestions. Most contributions require
you to agree to a Contributor License Agreement (CLA) declaring that you have
the right to, and actually do, grant us the rights to use your contribution.
For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether
you need to provide a CLA and decorate the PR appropriately (e.g., label,
comment). Simply follow the instructions provided by the bot. You will only
need to do this once across all repos using our CLA.

This project has adopted the
[Microsoft Open Source Code of Conduct][code_of_conduct]. For more information,
see the Code of Conduct FAQ or contact opencode@microsoft.com with any
additional questions or comments.

<!-- LINKS -->
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[authenticate_with_token]: https://docs.microsoft.com/azure/cognitive-services/authentication?tabs=powershell#authenticate-with-an-authentication-token
[azure_identity_credentials]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#credentials
[azure_identity_pip]: https://pypi.org/project/azure-identity/
[default_azure_credential]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/identity/azure-identity#defaultazurecredential
[pip]: https://pypi.org/project/pip/
[azure_sub]: https://azure.microsoft.com/free/

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"CrossLanguagePackageId": "Parameters.Basic",
"CrossLanguageDefinitionId": {
"parameters.basic.models.SimpleRequest": "Parameters.Basic.ImplicitBody.SimpleRequest",
"parameters.basic.models.User": "Parameters.Basic.ExplicitBody.User",
"parameters.basic.BasicClient.explicit_body.simple": "Parameters.Basic.ExplicitBody.simple",
"parameters.basic.BasicClient.implicit_body.simple": "Parameters.Basic.ImplicitBody.simple"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-e ../../../tools/azure-sdk-tools
../../core/azure-core
aiohttp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import os
import pytest
from dotenv import load_dotenv
from devtools_testutils import (
test_proxy,
add_general_regex_sanitizer,
add_body_key_sanitizer,
add_header_regex_sanitizer,
)

load_dotenv()


# aovid record sensitive identity information in recordings
@pytest.fixture(scope="session", autouse=True)
def add_sanitizers(test_proxy):
basic_subscription_id = os.environ.get("BASIC_SUBSCRIPTION_ID", "00000000-0000-0000-0000-000000000000")
basic_tenant_id = os.environ.get("BASIC_TENANT_ID", "00000000-0000-0000-0000-000000000000")
basic_client_id = os.environ.get("BASIC_CLIENT_ID", "00000000-0000-0000-0000-000000000000")
basic_client_secret = os.environ.get("BASIC_CLIENT_SECRET", "00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=basic_subscription_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=basic_tenant_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=basic_client_id, value="00000000-0000-0000-0000-000000000000")
add_general_regex_sanitizer(regex=basic_client_secret, value="00000000-0000-0000-0000-000000000000")

add_header_regex_sanitizer(key="Set-Cookie", value="[set-cookie;]")
add_header_regex_sanitizer(key="Cookie", value="cookie;")
add_body_key_sanitizer(json_path="$..access_token", value="access_token")
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils import recorded_by_proxy
from testpreparer import BasicClientTestBase, BasicPreparer


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestBasicExplicitBodyOperations(BasicClientTestBase):
@BasicPreparer()
@recorded_by_proxy
def test_simple(self, basic_endpoint):
client = self.create_client(endpoint=basic_endpoint)
response = client.explicit_body.simple(
body={"name": "str"},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils.aio import recorded_by_proxy_async
from testpreparer import BasicPreparer
from testpreparer_async import BasicClientTestBaseAsync


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestBasicExplicitBodyOperationsAsync(BasicClientTestBaseAsync):
@BasicPreparer()
@recorded_by_proxy_async
async def test_simple(self, basic_endpoint):
client = self.create_async_client(endpoint=basic_endpoint)
response = await client.explicit_body.simple(
body={"name": "str"},
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils import recorded_by_proxy
from testpreparer import BasicClientTestBase, BasicPreparer


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestBasicImplicitBodyOperations(BasicClientTestBase):
@BasicPreparer()
@recorded_by_proxy
def test_simple(self, basic_endpoint):
client = self.create_client(endpoint=basic_endpoint)
response = client.implicit_body.simple(
body={"name": "str"},
name="str",
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
import pytest
from devtools_testutils.aio import recorded_by_proxy_async
from testpreparer import BasicPreparer
from testpreparer_async import BasicClientTestBaseAsync


@pytest.mark.skip("you may need to update the auto-generated test case before run it")
class TestBasicImplicitBodyOperationsAsync(BasicClientTestBaseAsync):
@BasicPreparer()
@recorded_by_proxy_async
async def test_simple(self, basic_endpoint):
client = self.create_async_client(endpoint=basic_endpoint)
response = await client.implicit_body.simple(
body={"name": "str"},
name="str",
)

# please add some check logic here by yourself
# ...
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from devtools_testutils import AzureRecordedTestCase, PowerShellPreparer
import functools
from parameters.basic import BasicClient


class BasicClientTestBase(AzureRecordedTestCase):

def create_client(self, endpoint):
credential = self.get_credential(BasicClient)
return self.create_client_from_credential(
BasicClient,
credential=credential,
endpoint=endpoint,
)


BasicPreparer = functools.partial(PowerShellPreparer, "basic", basic_endpoint="https://fake_basic_endpoint.com")
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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from devtools_testutils import AzureRecordedTestCase
from parameters.basic.aio import BasicClient


class BasicClientTestBaseAsync(AzureRecordedTestCase):

def create_async_client(self, endpoint):
credential = self.get_credential(BasicClient, is_async=True)
return self.create_client_from_credential(
BasicClient,
credential=credential,
endpoint=endpoint,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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) Python Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._client import BasicClient
from ._version import VERSION

__version__ = VERSION

try:
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"BasicClient",
]
__all__.extend([p for p in _patch_all if p not in __all__])

_patch_sdk()
Loading

0 comments on commit a1cb0be

Please sign in to comment.