Skip to content

Commit db58bcd

Browse files
Copilotmsyyc
andauthored
[python] Add mock API tests for ARM service group extension resources (#11401)
Adds Python SDK Spector mock API test coverage for the ARM service group extension resource scenarios introduced in Azure/typespec-azure#4891, covering the new `Extension.ServiceGroup` scope and `ServiceGroup` ARM resource identifier scope. ## Dependency bumps (`packages/http-client-python/package.json`) - `@azure-tools/azure-http-specs`: `0.1.0-alpha.43` → `0.1.0-alpha.44-dev.5` — includes the `azure/resource-manager/service-group` spec and `armIdWithGroupScope` field - `@azure-tools/typespec-azure-resource-manager`: `~0.70.0` → `0.71.0-dev.3` — adds `Extension.ServiceGroup` target - `@azure-tools/typespec-azure-core`: `~0.70.0` → `0.71.0-dev.1` — adds `ServiceGroup` as an `armResourceIdentifier` scope - `@azure-tools/typespec-autorest`, `typespec-azure-rulesets`, `typespec-client-generator-core`: aligned to compatible `0.71.0-dev.*` versions ## New tests - `test_azure_arm_servicegroup.py` + async counterpart: 5 tests covering the full CRUD lifecycle (`get`, `begin_create_or_update` LRO, `update`, `delete`, `list_by_service_group`) against the `ServiceGroupExtensionClient` at service group scope (`/providers/Microsoft.Management/serviceGroups/{id}/...`) ## Updated tests - `test_azure_arm_commonproperties.py` + async counterpart: adds `ARM_ID_WITH_GROUP_SCOPE` constant and assertions for the new `arm_id_with_group_scope` property in both `get` and `create_or_replace` test cases <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #11399 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
1 parent e097c90 commit db58bcd

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Add test coverage for Azure ARM service group extension resources and ARM resource identifier group scope
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import pytest
7+
import pytest_asyncio
8+
from azure.resourcemanager.servicegroupextension.aio import ServiceGroupExtensionClient
9+
from azure.resourcemanager.servicegroupextension import models
10+
11+
SERVICE_GROUP_ID = "test-sg"
12+
RESOURCE_NAME = "resource"
13+
14+
15+
@pytest_asyncio.fixture
16+
async def client(credential, authentication_policy):
17+
async with ServiceGroupExtensionClient(
18+
credential, "http://localhost:3000", authentication_policy=authentication_policy
19+
) as client:
20+
yield client
21+
22+
23+
@pytest.mark.asyncio
24+
async def test_service_group_extension_resources_get(client):
25+
result = await client.service_group_extension_resources.get(
26+
service_group_id=SERVICE_GROUP_ID, service_group_extension_resource_name=RESOURCE_NAME
27+
)
28+
assert result.name == RESOURCE_NAME
29+
assert result.properties.description == "valid"
30+
assert result.properties.provisioning_state == "Succeeded"
31+
32+
33+
@pytest.mark.asyncio
34+
async def test_service_group_extension_resources_create_or_update(client):
35+
result = await (
36+
await client.service_group_extension_resources.begin_create_or_update(
37+
service_group_id=SERVICE_GROUP_ID,
38+
service_group_extension_resource_name=RESOURCE_NAME,
39+
resource=models.ServiceGroupExtensionResource(
40+
properties=models.ServiceGroupExtensionResourceProperties(description="valid")
41+
),
42+
polling_interval=0,
43+
)
44+
).result()
45+
assert result.name == RESOURCE_NAME
46+
assert result.properties.description == "valid"
47+
assert result.properties.provisioning_state == "Succeeded"
48+
49+
50+
@pytest.mark.asyncio
51+
async def test_service_group_extension_resources_update(client):
52+
result = await client.service_group_extension_resources.update(
53+
service_group_id=SERVICE_GROUP_ID,
54+
service_group_extension_resource_name=RESOURCE_NAME,
55+
properties=models.ServiceGroupExtensionResource(
56+
properties=models.ServiceGroupExtensionResourceProperties(description="valid2")
57+
),
58+
)
59+
assert result.name == RESOURCE_NAME
60+
assert result.properties.description == "valid2"
61+
assert result.properties.provisioning_state == "Succeeded"
62+
63+
64+
@pytest.mark.asyncio
65+
async def test_service_group_extension_resources_delete(client):
66+
await client.service_group_extension_resources.delete(
67+
service_group_id=SERVICE_GROUP_ID, service_group_extension_resource_name=RESOURCE_NAME
68+
)
69+
70+
71+
@pytest.mark.asyncio
72+
async def test_service_group_extension_resources_list_by_service_group(client):
73+
result = [
74+
item
75+
async for item in client.service_group_extension_resources.list_by_service_group(
76+
service_group_id=SERVICE_GROUP_ID
77+
)
78+
]
79+
assert len(result) == 1
80+
assert result[0].name == RESOURCE_NAME
81+
assert result[0].properties.description == "valid"
82+
assert result[0].properties.provisioning_state == "Succeeded"
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for
4+
# license information.
5+
# --------------------------------------------------------------------------
6+
import pytest
7+
from azure.resourcemanager.servicegroupextension import ServiceGroupExtensionClient
8+
from azure.resourcemanager.servicegroupextension import models
9+
10+
SERVICE_GROUP_ID = "test-sg"
11+
RESOURCE_NAME = "resource"
12+
13+
14+
@pytest.fixture
15+
def client(credential, authentication_policy):
16+
with ServiceGroupExtensionClient(
17+
credential, "http://localhost:3000", authentication_policy=authentication_policy
18+
) as client:
19+
yield client
20+
21+
22+
def test_service_group_extension_resources_get(client):
23+
result = client.service_group_extension_resources.get(
24+
service_group_id=SERVICE_GROUP_ID, service_group_extension_resource_name=RESOURCE_NAME
25+
)
26+
assert result.name == RESOURCE_NAME
27+
assert result.properties.description == "valid"
28+
assert result.properties.provisioning_state == "Succeeded"
29+
30+
31+
def test_service_group_extension_resources_create_or_update(client):
32+
result = client.service_group_extension_resources.begin_create_or_update(
33+
service_group_id=SERVICE_GROUP_ID,
34+
service_group_extension_resource_name=RESOURCE_NAME,
35+
resource=models.ServiceGroupExtensionResource(
36+
properties=models.ServiceGroupExtensionResourceProperties(description="valid")
37+
),
38+
polling_interval=0,
39+
).result()
40+
assert result.name == RESOURCE_NAME
41+
assert result.properties.description == "valid"
42+
assert result.properties.provisioning_state == "Succeeded"
43+
44+
45+
def test_service_group_extension_resources_update(client):
46+
result = client.service_group_extension_resources.update(
47+
service_group_id=SERVICE_GROUP_ID,
48+
service_group_extension_resource_name=RESOURCE_NAME,
49+
properties=models.ServiceGroupExtensionResource(
50+
properties=models.ServiceGroupExtensionResourceProperties(description="valid2")
51+
),
52+
)
53+
assert result.name == RESOURCE_NAME
54+
assert result.properties.description == "valid2"
55+
assert result.properties.provisioning_state == "Succeeded"
56+
57+
58+
def test_service_group_extension_resources_delete(client):
59+
client.service_group_extension_resources.delete(
60+
service_group_id=SERVICE_GROUP_ID, service_group_extension_resource_name=RESOURCE_NAME
61+
)
62+
63+
64+
def test_service_group_extension_resources_list_by_service_group(client):
65+
result = list(client.service_group_extension_resources.list_by_service_group(service_group_id=SERVICE_GROUP_ID))
66+
assert len(result) == 1
67+
assert result[0].name == RESOURCE_NAME
68+
assert result[0].properties.description == "valid"
69+
assert result[0].properties.provisioning_state == "Succeeded"

0 commit comments

Comments
 (0)