Skip to content
Draft
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,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Add mock API tests for `service/multiple-services` scenario (multiple services without explicit `@client`).
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ export const BASE_AZURE_EMITTER_OPTIONS: Record<
"service/multi-service": {
namespace: "service.multiservice",
},
"service/multiple-services": {
namespace: "service.multipleservices",
},
};

export const BASE_EMITTER_OPTIONS: Record<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
from azure.core.exceptions import HttpResponseError
from service.multipleservices.aio import ServiceAClient
from service.multipleservices.models import VersionsA


@pytest.fixture
def client():
"""Fixture that creates a ServiceAClient for testing."""
return ServiceAClient(endpoint="http://localhost:3000")


@pytest.mark.asyncio
async def test_service_multiple_services_operation_a(client):
async with client:
async with ServiceAClient(endpoint="http://localhost:3000", api_version=VersionsA.AV1) as wrong_client:
with pytest.raises(HttpResponseError):
await wrong_client.operations.op_a()

await client.operations.op_a()


@pytest.mark.asyncio
async def test_service_multiple_services_sub_namespace_operation_a(client):
async with client:
async with ServiceAClient(endpoint="http://localhost:3000", api_version=VersionsA.AV1) as wrong_client:
with pytest.raises(HttpResponseError):
await wrong_client.sub_namespace.sub_op_a()

await client.sub_namespace.sub_op_a()
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
from azure.core.exceptions import HttpResponseError
from service.multipleservices import ServiceAClient
from service.multipleservices.models import VersionsA


@pytest.fixture
def client():
"""Fixture that creates a ServiceAClient for testing."""
with ServiceAClient(endpoint="http://localhost:3000") as client:
yield client


def test_service_multiple_services_operation_a(client):
with ServiceAClient(endpoint="http://localhost:3000", api_version=VersionsA.AV1) as wrong_client:
with pytest.raises(HttpResponseError):
wrong_client.operations.op_a()

client.operations.op_a()


def test_service_multiple_services_sub_namespace_operation_a(client):
with ServiceAClient(endpoint="http://localhost:3000", api_version=VersionsA.AV1) as wrong_client:
with pytest.raises(HttpResponseError):
wrong_client.sub_namespace.sub_op_a()

client.sub_namespace.sub_op_a()
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ azure-mgmt-core==1.6.0
-e ./generated/resiliency-srv-driven1
-e ./generated/resiliency-srv-driven2
-e ./generated/service-multi-service
-e ./generated/service-multiple-services
# === end common azure dependencies across repos ===

# === common test dependencies across repos ===
Expand Down
10 changes: 5 additions & 5 deletions packages/http-client-python/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.66.0",
"@azure-tools/typespec-azure-rulesets": "~0.66.0",
"@azure-tools/typespec-client-generator-core": "~0.66.4",
"@azure-tools/azure-http-specs": "0.1.0-alpha.39-dev.4",
"@azure-tools/azure-http-specs": "0.1.0-alpha.39-dev.8",
"@typespec/compiler": "^1.10.0",
"@typespec/http": "^1.10.0",
"@typespec/openapi": "^1.10.0",
Expand Down