Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: internal
packages:
- "@autorest/python"
- "@azure-tools/typespec-python"
---

Add mock API tests for `service/multiple-services` scenario (multiple services without explicit `@client`).
2 changes: 1 addition & 1 deletion packages/autorest.python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"homepage": "https://github.com/Azure/autorest.python/blob/main/README.md",
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyODg2My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEzMDI2NS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@autorest/system-requirements": "~1.0.2",
"fs-extra": "~11.2.0",
"tsx": "^4.21.0"
Expand Down
3 changes: 3 additions & 0 deletions packages/typespec-python/eng/scripts/regenerate-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ export const BASE_AZURE_EMITTER_OPTIONS: Record<string, Record<string, string> |
"service/multi-service": {
namespace: "service.multiservice",
},
"service/multiple-services": {
namespace: "service.multipleservices",
},
};

export const BASE_EMITTER_OPTIONS: Record<string, Record<string, string> | Record<string, string>[]> = {
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 @@ -65,7 +65,7 @@
"@typespec/xml": ">=0.81.0 <1.0.0"
},
"dependencies": {
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEyODg2My9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"@typespec/http-client-python": "https://artprodcus3.artifacts.visualstudio.com/A0fb41ef4-5012-48a9-bf39-4ee3de03ee35/29ec6040-b234-4e31-b139-33dc4287b756/_apis/artifact/cGlwZWxpbmVhcnRpZmFjdDovL2F6dXJlLXNkay9wcm9qZWN0SWQvMjllYzYwNDAtYjIzNC00ZTMxLWIxMzktMzNkYzQyODdiNzU2L2J1aWxkSWQvNjEzMDI2NS9hcnRpZmFjdE5hbWUvYnVpbGRfYXJ0aWZhY3RzX3B5dGhvbg2/content?format=file&subPath=%2Fpackages%2Ftypespec-http-client-python-0.28.3.tgz",
"fs-extra": "~11.2.0",
"js-yaml": "~4.1.0",
"semver": "~7.6.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
include *.md
include LICENSE
include service/multipleservices/servicea/py.typed
include service/multipleservices/py.typed
recursive-include tests *.py
recursive-include samples *.py *.md
include service/__init__.py
include service/multipleservices/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"CrossLanguagePackageId": "Service.MultipleServices.ServiceA",
"CrossLanguageDefinitionId": {
"service.multipleservices.servicea.models.VersionsA": "Service.MultipleServices.ServiceA.VersionsA",
"service.multipleservices.servicea.models.VersionsB": "Service.MultipleServices.ServiceB.VersionsB",
"service.multipleservices.servicea.operations.SubNamespaceOperations.sub_op_a": "Service.MultipleServices.ServiceA.SubNamespace.subOpA",
"service.multipleservices.servicea.aio.operations.SubNamespaceOperations.sub_op_a": "Service.MultipleServices.ServiceA.SubNamespace.subOpA",
"service.multipleservices.servicea.operations.Operations.op_a": "Service.MultipleServices.ServiceA.Operations.opA",
"service.multipleservices.servicea.aio.operations.Operations.op_a": "Service.MultipleServices.ServiceA.Operations.opA",
"service.multipleservices.servicea.operations.SubNamespaceOperations.sub_op_b": "Service.MultipleServices.ServiceB.SubNamespace.subOpB",
"service.multipleservices.servicea.aio.operations.SubNamespaceOperations.sub_op_b": "Service.MultipleServices.ServiceB.SubNamespace.subOpB",
"service.multipleservices.servicea.operations.Operations.op_b": "Service.MultipleServices.ServiceB.Operations.opB",
"service.multipleservices.servicea.aio.operations.Operations.op_b": "Service.MultipleServices.ServiceB.Operations.opB"
"service.multipleservices.models.VersionsA": "Service.MultipleServices.ServiceA.VersionsA",
"service.multipleservices.models.VersionsB": "Service.MultipleServices.ServiceB.VersionsB",
"service.multipleservices.operations.SubNamespaceOperations.sub_op_a": "Service.MultipleServices.ServiceA.SubNamespace.subOpA",
"service.multipleservices.aio.operations.SubNamespaceOperations.sub_op_a": "Service.MultipleServices.ServiceA.SubNamespace.subOpA",
"service.multipleservices.operations.Operations.op_a": "Service.MultipleServices.ServiceA.Operations.opA",
"service.multipleservices.aio.operations.Operations.op_a": "Service.MultipleServices.ServiceA.Operations.opA",
"service.multipleservices.operations.SubNamespaceOperations.sub_op_b": "Service.MultipleServices.ServiceB.SubNamespace.subOpB",
"service.multipleservices.aio.operations.SubNamespaceOperations.sub_op_b": "Service.MultipleServices.ServiceB.SubNamespace.subOpB",
"service.multipleservices.operations.Operations.op_b": "Service.MultipleServices.ServiceB.Operations.opB",
"service.multipleservices.aio.operations.Operations.op_b": "Service.MultipleServices.ServiceB.Operations.opB"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# --------------------------------------------------------------------------
from devtools_testutils import AzureRecordedTestCase, PowerShellPreparer
import functools
from service.multipleservices.servicea import ServiceAClient
from service.multipleservices.serviceb import ServiceBClient
from service.multipleservices import ServiceAClient, ServiceBClient


class ServiceAClientTestBase(AzureRecordedTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------
from devtools_testutils import AzureRecordedTestCase
from service.multipleservices.servicea.aio import ServiceAClient
from service.multipleservices.serviceb.aio import ServiceBClient
from service.multipleservices.aio import ServiceAClient, ServiceBClient


class ServiceAClientTestBaseAsync(AzureRecordedTestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ requires = ["setuptools>=77.0.3", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "service-multipleservices-servicea"
name = "service-multipleservices"
authors = [
{ name = "Microsoft Corporation", email = "azpysdkhelp@microsoft.com" },
]
description = "Microsoft Corporation Azure Service Multipleservices Servicea Client Library for Python"
description = "Microsoft Corporation Azure Service Multipleservices Client Library for Python"
license = "MIT"
classifiers = [
"Development Status :: 4 - Beta",
Expand Down Expand Up @@ -43,7 +43,7 @@ dynamic = [
repository = "https://github.com/Azure/azure-sdk-for-python"

[tool.setuptools.dynamic]
version = {attr = "service.multipleservices.servicea._version.VERSION"}
version = {attr = "service.multipleservices._version.VERSION"}
readme = {file = ["README.md", "CHANGELOG.md"], content-type = "text/markdown"}

[tool.setuptools.packages.find]
Expand All @@ -54,7 +54,6 @@ exclude = [
"generated_samples*",
"doc*",
"service",
"service.multipleservices",
]

[tool.setuptools.package-data]
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,34 @@
__path__ = __import__("pkgutil").extend_path(__path__, __name__) # type: ignore
# 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.
# --------------------------------------------------------------------------
# pylint: disable=wrong-import-position

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from ._patch import * # pylint: disable=unused-wildcard-import

from ._client import ServiceAClient # type: ignore
from ._client import ServiceBClient # type: ignore
from ._version import VERSION

__version__ = VERSION

try:
from ._patch import __all__ as _patch_all
from ._patch import *
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"ServiceAClient",
"ServiceBClient",
]
__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore

_patch_sdk()
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
# 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 copy import deepcopy
from typing import Any
from typing_extensions import Self

from azure.core import PipelineClient
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from ._configuration import ServiceAClientConfiguration, ServiceBClientConfiguration
from ._utils.serialization import Deserializer, Serializer
from .operations import Operations, SubNamespaceOperations


class ServiceAClient:
"""First service definition in a multiple-services package with versioning. Without explicit
``@client``, this should create a separate root client (``ServiceAClient``).

:ivar sub_namespace: SubNamespaceOperations operations
:vartype sub_namespace: service.multipleservices.operations.SubNamespaceOperations
:ivar operations: Operations operations
:vartype operations: service.multipleservices.operations.Operations
:keyword endpoint: Service host. Default value is "http://localhost:3000".
:paramtype endpoint: str
:keyword api_version: Known values are "av2". Default value is "av2". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str or ~service.multipleservices.models.VersionsA
"""

def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self, *, endpoint: str = "http://localhost:3000", **kwargs: Any
) -> None:
_endpoint = "{endpoint}"
self._config = ServiceAClientConfiguration(endpoint=endpoint, **kwargs)

_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.sub_namespace = SubNamespaceOperations(self._client, self._config, self._serialize, self._deserialize)
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.HttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()

def __enter__(self) -> Self:
self._client.__enter__()
return self

def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)


class ServiceBClient:
"""Second service definition in a multiple-services package with versioning. Without explicit
``@client``, this should create a separate root client (``ServiceBClient``).

:ivar sub_namespace: SubNamespaceOperations operations
:vartype sub_namespace: service.multipleservices.operations.SubNamespaceOperations
:ivar operations: Operations operations
:vartype operations: service.multipleservices.operations.Operations
:keyword endpoint: Service host. Default value is "http://localhost:3000".
:paramtype endpoint: str
:keyword api_version: Known values are "bv2". Default value is "bv2". Note that overriding this
default value may result in unsupported behavior.
:paramtype api_version: str or ~service.multipleservices.models.VersionsB
"""

def __init__( # pylint: disable=missing-client-constructor-parameter-credential
self, *, endpoint: str = "http://localhost:3000", **kwargs: Any
) -> None:
_endpoint = "{endpoint}"
self._config = ServiceBClientConfiguration(endpoint=endpoint, **kwargs)

_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.sub_namespace = SubNamespaceOperations(self._client, self._config, self._serialize, self._deserialize)
self.operations = Operations(self._client, self._config, self._serialize, self._deserialize)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.

>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request

:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.HttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()

def __enter__(self) -> Self:
self._client.__enter__()
return self

def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)
Loading
Loading