From c41dac07c2a88fdd28bfa61771398882503297a2 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 12 Sep 2025 09:11:56 +0800 Subject: [PATCH 1/3] add test case --- ...ce_manager_method_subscription_id_async.py | 248 ++++++++++++++++++ ...resource_manager_method_subscription_id.py | 235 +++++++++++++++++ .../generator/test/azure/requirements.txt | 1 + 3 files changed, 484 insertions(+) create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py create mode 100644 packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py new file mode 100644 index 00000000000..7b96c3c297b --- /dev/null +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_resource_manager_method_subscription_id_async.py @@ -0,0 +1,248 @@ +# ------------------------------------------------------------------------- +# 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.resourcemanager.methodsubscriptionid.aio import MethodSubscriptionIdClient +from azure.resourcemanager.methodsubscriptionid import models + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +@pytest.fixture +async def client(credential, authentication_policy): + async with MethodSubscriptionIdClient( + credential, + SUBSCRIPTION_ID, + "http://localhost:3000", + authentication_policy=authentication_policy, + ) as client: + yield client + + +@pytest.mark.asyncio +async def test_operations_list(client): + """Test Operations.list() endpoint.""" + operations = client.operations.list() + operations_list = [op async for op in operations] + assert len(operations_list) > 0 + + operation = operations_list[0] + assert operation.name == "Azure.ResourceManager.MethodSubscriptionId/services/read" + assert operation.is_data_action is False + assert operation.display.provider == "Azure.ResourceManager.MethodSubscriptionId" + assert operation.display.resource == "services" + assert operation.display.operation == "Lists services" + assert operation.display.description == "Lists registered services" + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource1_operations_get(client): + """Test get operation for SubscriptionResource1 with method-level subscription ID.""" + result = await client.two_subscription_resources_method_level.subscription_resource1_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" + ) + assert result.name == "sub-resource-1" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" + assert result.properties.description == "Valid subscription resource 1" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource1_operations_put(client): + """Test put operation for SubscriptionResource1 with method-level subscription ID.""" + resource = models.SubscriptionResource1( + properties=models.SubscriptionResource1Properties(description="Valid subscription resource 1") + ) + + result = await client.two_subscription_resources_method_level.subscription_resource1_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" + ) + assert result.name == "sub-resource-1" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" + assert result.properties.description == "Valid subscription resource 1" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource1_operations_delete(client): + """Test delete operation for SubscriptionResource1 with method-level subscription ID.""" + await client.two_subscription_resources_method_level.subscription_resource1_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + ) + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource2_operations_get(client): + """Test get operation for SubscriptionResource2 with method-level subscription ID.""" + result = await client.two_subscription_resources_method_level.subscription_resource2_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" + ) + assert result.name == "sub-resource-2" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" + assert result.properties.config_value == "test-config" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource2_operations_put(client): + """Test put operation for SubscriptionResource2 with method-level subscription ID.""" + resource = models.SubscriptionResource2( + properties=models.SubscriptionResource2Properties(config_value="test-config") + ) + + result = await client.two_subscription_resources_method_level.subscription_resource2_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" + ) + assert result.name == "sub-resource-2" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" + assert result.properties.config_value == "test-config" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_two_subscription_resources_method_level_subscription_resource2_operations_delete(client): + """Test delete operation for SubscriptionResource2 with method-level subscription ID.""" + await client.two_subscription_resources_method_level.subscription_resource2_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + ) + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_subscription_resource_operations_get(client): + """Test get operation for SubscriptionResource in mixed placement scenario.""" + result = await client.mixed_subscription_placement.subscription_resource_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" + ) + assert result.name == "sub-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" + assert result.properties.subscription_setting == "test-sub-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_subscription_resource_operations_put(client): + """Test put operation for SubscriptionResource in mixed placement scenario.""" + resource = models.SubscriptionResource( + properties=models.SubscriptionResourceProperties(subscription_setting="test-sub-setting") + ) + + result = await client.mixed_subscription_placement.subscription_resource_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" + ) + assert result.name == "sub-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" + assert result.properties.subscription_setting == "test-sub-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_subscription_resource_operations_delete(client): + """Test delete operation for SubscriptionResource in mixed placement scenario.""" + await client.mixed_subscription_placement.subscription_resource_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + ) + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_resource_group_resource_operations_get(client): + """Test get operation for ResourceGroupResource with client-level subscription ID.""" + result = await client.mixed_subscription_placement.resource_group_resource_operations.get( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" + ) + assert result.name == "rg-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" + assert result.location == "eastus" + assert result.properties.resource_group_setting == "test-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_resource_group_resource_operations_put(client): + """Test put operation for ResourceGroupResource with client-level subscription ID.""" + resource = models.ResourceGroupResource( + location="eastus", properties=models.ResourceGroupResourceProperties(resource_group_setting="test-setting") + ) + + result = await client.mixed_subscription_placement.resource_group_resource_operations.put( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" + ) + assert result.name == "rg-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" + assert result.location == "eastus" + assert result.properties.resource_group_setting == "test-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_mixed_subscription_placement_resource_group_resource_operations_delete(client): + """Test delete operation for ResourceGroupResource with client-level subscription ID.""" + await client.mixed_subscription_placement.resource_group_resource_operations.delete( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + ) diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py new file mode 100644 index 00000000000..5f3704a5a19 --- /dev/null +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_resource_manager_method_subscription_id.py @@ -0,0 +1,235 @@ +# ------------------------------------------------------------------------- +# 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.resourcemanager.methodsubscriptionid import MethodSubscriptionIdClient +from azure.resourcemanager.methodsubscriptionid import models + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +@pytest.fixture +def client(credential, authentication_policy): + with MethodSubscriptionIdClient( + credential, + SUBSCRIPTION_ID, + "http://localhost:3000", + authentication_policy=authentication_policy, + ) as client: + yield client + + +def test_operations_list(client): + """Test Operations.list() endpoint.""" + operations = client.operations.list() + operations_list = [op for op in operations] + assert len(operations_list) > 0 + + operation = operations_list[0] + assert operation.name == "Azure.ResourceManager.MethodSubscriptionId/services/read" + assert operation.is_data_action is False + assert operation.display.provider == "Azure.ResourceManager.MethodSubscriptionId" + assert operation.display.resource == "services" + assert operation.display.operation == "Lists services" + assert operation.display.description == "Lists registered services" + + +def test_two_subscription_resources_method_level_subscription_resource1_operations_get(client): + """Test get operation for SubscriptionResource1 with method-level subscription ID.""" + result = client.two_subscription_resources_method_level.subscription_resource1_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" + ) + assert result.name == "sub-resource-1" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" + assert result.properties.description == "Valid subscription resource 1" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_two_subscription_resources_method_level_subscription_resource1_operations_put(client): + """Test put operation for SubscriptionResource1 with method-level subscription ID.""" + resource = models.SubscriptionResource1( + properties=models.SubscriptionResource1Properties(description="Valid subscription resource 1") + ) + + result = client.two_subscription_resources_method_level.subscription_resource1_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" + ) + assert result.name == "sub-resource-1" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" + assert result.properties.description == "Valid subscription resource 1" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_two_subscription_resources_method_level_subscription_resource1_operations_delete(client): + """Test delete operation for SubscriptionResource1 with method-level subscription ID.""" + client.two_subscription_resources_method_level.subscription_resource1_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource1_name="sub-resource-1", + ) + + +def test_two_subscription_resources_method_level_subscription_resource2_operations_get(client): + """Test get operation for SubscriptionResource2 with method-level subscription ID.""" + result = client.two_subscription_resources_method_level.subscription_resource2_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" + ) + assert result.name == "sub-resource-2" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" + assert result.properties.config_value == "test-config" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_two_subscription_resources_method_level_subscription_resource2_operations_put(client): + """Test put operation for SubscriptionResource2 with method-level subscription ID.""" + resource = models.SubscriptionResource2( + properties=models.SubscriptionResource2Properties(config_value="test-config") + ) + + result = client.two_subscription_resources_method_level.subscription_resource2_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" + ) + assert result.name == "sub-resource-2" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" + assert result.properties.config_value == "test-config" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_two_subscription_resources_method_level_subscription_resource2_operations_delete(client): + """Test delete operation for SubscriptionResource2 with method-level subscription ID.""" + client.two_subscription_resources_method_level.subscription_resource2_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource2_name="sub-resource-2", + ) + + +def test_mixed_subscription_placement_subscription_resource_operations_get(client): + """Test get operation for SubscriptionResource in mixed placement scenario.""" + result = client.mixed_subscription_placement.subscription_resource_operations.get( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" + ) + assert result.name == "sub-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" + assert result.properties.subscription_setting == "test-sub-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_mixed_subscription_placement_subscription_resource_operations_put(client): + """Test put operation for SubscriptionResource in mixed placement scenario.""" + resource = models.SubscriptionResource( + properties=models.SubscriptionResourceProperties(subscription_setting="test-sub-setting") + ) + + result = client.mixed_subscription_placement.subscription_resource_operations.put( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" + ) + assert result.name == "sub-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" + assert result.properties.subscription_setting == "test-sub-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_mixed_subscription_placement_subscription_resource_operations_delete(client): + """Test delete operation for SubscriptionResource in mixed placement scenario.""" + client.mixed_subscription_placement.subscription_resource_operations.delete( + subscription_id=SUBSCRIPTION_ID, + subscription_resource_name="sub-resource", + ) + + +def test_mixed_subscription_placement_resource_group_resource_operations_get(client): + """Test get operation for ResourceGroupResource with client-level subscription ID.""" + result = client.mixed_subscription_placement.resource_group_resource_operations.get( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" + ) + assert result.name == "rg-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" + assert result.location == "eastus" + assert result.properties.resource_group_setting == "test-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_mixed_subscription_placement_resource_group_resource_operations_put(client): + """Test put operation for ResourceGroupResource with client-level subscription ID.""" + resource = models.ResourceGroupResource( + location="eastus", properties=models.ResourceGroupResourceProperties(resource_group_setting="test-setting") + ) + + result = client.mixed_subscription_placement.resource_group_resource_operations.put( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + resource=resource, + ) + + assert ( + result.id + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" + ) + assert result.name == "rg-resource" + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" + assert result.location == "eastus" + assert result.properties.resource_group_setting == "test-setting" + assert result.properties.provisioning_state == "Succeeded" + assert result.system_data.created_by == "AzureSDK" + + +def test_mixed_subscription_placement_resource_group_resource_operations_delete(client): + """Test delete operation for ResourceGroupResource with client-level subscription ID.""" + client.mixed_subscription_placement.resource_group_resource_operations.delete( + resource_group_name=RESOURCE_GROUP_NAME, + resource_group_resource_name="rg-resource", + ) diff --git a/packages/http-client-python/generator/test/azure/requirements.txt b/packages/http-client-python/generator/test/azure/requirements.txt index 3b76996c747..2b34391ff48 100644 --- a/packages/http-client-python/generator/test/azure/requirements.txt +++ b/packages/http-client-python/generator/test/azure/requirements.txt @@ -29,6 +29,7 @@ azure-mgmt-core==1.6.0 -e ./generated/azure-resource-manager-non-resource -e ./generated/azure-resource-manager-operation-templates -e ./generated/azure-resource-manager-resources +-e ./generated/azure-resource-manager-method-subscription-id -e ./generated/client-namespace -e ./generated/azure-payload-pageable -e ./generated/client-naming From 34f13e5a00979ea73925358504027f5c9d89c4c3 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 12 Sep 2025 09:12:48 +0800 Subject: [PATCH 2/3] add changelog --- .../changes/add-testcases-2025-09-12-2025-8-12-9-12-36.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/add-testcases-2025-09-12-2025-8-12-9-12-36.md diff --git a/.chronus/changes/add-testcases-2025-09-12-2025-8-12-9-12-36.md b/.chronus/changes/add-testcases-2025-09-12-2025-8-12-9-12-36.md new file mode 100644 index 00000000000..0ec55539601 --- /dev/null +++ b/.chronus/changes/add-testcases-2025-09-12-2025-8-12-9-12-36.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add test cases for subscriptionId \ No newline at end of file From ecebae95c49faf7bc288ced68b46b7ade4f22c67 Mon Sep 17 00:00:00 2001 From: Yuchao Yan Date: Fri, 12 Sep 2025 09:20:31 +0800 Subject: [PATCH 3/3] add cspell --- cspell.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.yaml b/cspell.yaml index cfb667ec268..0cb0fa9a448 100644 --- a/cspell.yaml +++ b/cspell.yaml @@ -138,6 +138,7 @@ words: - MACVMIMAGE - MACVMIMAGEM - mday + - methodsubscriptionid - mgmt - mgmtplane - mocharc