Skip to content

Commit 8c68bac

Browse files
Copilotmsyyc
andauthored
[Copilot] Add test cases from TypeSpec PR #7693 (#3107)
* Initial plan * Add test cases from TypeSpec PR #7693 Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Add changelog entry for test cases Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Run black formatter on Python test files Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> * Revert changelog entry for test cases per feedback Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --------- 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 62a21af commit 8c68bac

16 files changed

+302
-0
lines changed
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+
- "@azure-tools/typespec-python"
5+
---
6+
7+
Add test cases

packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_arm_commonproperties_async.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from azure.resourcemanager.commonproperties.aio import CommonPropertiesClient
88
from azure.resourcemanager.commonproperties import models
9+
from azure.core import exceptions
910

1011
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
1112
RESOURCE_GROUP_NAME = "test-rg"
@@ -61,3 +62,33 @@ async def test_managed_identity_update_with_user_assigned_and_system_assigned(cl
6162
assert result.location == "eastus"
6263
assert result.identity.type == "SystemAssigned,UserAssigned"
6364
assert result.properties.provisioning_state == "Succeeded"
65+
66+
67+
@pytest.mark.asyncio
68+
async def test_error_get_for_predefined_error(client):
69+
try:
70+
await client.error.get_for_predefined_error(
71+
resource_group_name=RESOURCE_GROUP_NAME,
72+
confidential_resource_name="confidential",
73+
)
74+
except exceptions.ResourceNotFoundError as e:
75+
assert e.status_code == 404
76+
assert (
77+
e.error.message
78+
== "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
79+
)
80+
81+
82+
@pytest.mark.asyncio
83+
async def test_error_create_for_user_defined_error(client):
84+
try:
85+
await client.error.create_for_user_defined_error(
86+
resource_group_name=RESOURCE_GROUP_NAME,
87+
confidential_resource_name="confidential",
88+
resource=models.ConfidentialResource(
89+
location="eastus", properties=models.ConfidentialResourceProperties(username="00")
90+
),
91+
)
92+
except exceptions.HttpResponseError as e:
93+
assert e.status_code == 400
94+
assert e.error.message == "Username should not contain only numbers."
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.largeheader.aio import LargeHeaderClient
8+
from azure.resourcemanager.largeheader import models
9+
10+
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11+
RESOURCE_GROUP_NAME = "test-rg"
12+
13+
14+
@pytest.fixture
15+
async def client(credential, authentication_policy):
16+
async with LargeHeaderClient(
17+
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18+
) as client:
19+
yield client
20+
21+
22+
@pytest.mark.asyncio
23+
async def test_large_headers_begin_two6_k(client: LargeHeaderClient):
24+
result = await (
25+
await client.large_headers.begin_two6_k(
26+
resource_group_name=RESOURCE_GROUP_NAME,
27+
large_header_name="header1",
28+
)
29+
).result()
30+
assert result == models.CancelResult(succeeded=True)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.nonresource.aio import NonResourceClient
8+
from azure.resourcemanager.nonresource import models
9+
10+
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11+
RESOURCE_GROUP_NAME = "test-rg"
12+
13+
14+
@pytest.fixture
15+
async def client(credential, authentication_policy):
16+
async with NonResourceClient(
17+
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18+
) as client:
19+
yield client
20+
21+
22+
@pytest.mark.asyncio
23+
async def test_non_resource_create(client: NonResourceClient):
24+
result = await client.non_resource_operations.create(
25+
location="eastus", parameter="hello", body=models.NonResource(id="id", name="hello", type="nonResource")
26+
)
27+
assert result == models.NonResource(id="id", name="hello", type="nonResource")
28+
29+
30+
@pytest.mark.asyncio
31+
async def test_non_resource_get(client: NonResourceClient):
32+
result = await client.non_resource_operations.get(
33+
location="eastus",
34+
parameter="hello",
35+
)
36+
assert result == models.NonResource(id="id", name="hello", type="nonResource")

packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_client_initialization_async.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
MixedParamsClient,
1111
PathParamClient,
1212
ParamAliasClient,
13+
ParentClient,
1314
)
1415
from specs.azure.clientgenerator.core.clientinitialization.models import Input
1516

@@ -48,3 +49,11 @@ async def test_param_alias_client():
4849
async with ParamAliasClient("sample-blob") as client:
4950
await client.with_aliased_name()
5051
await client.with_original_name()
52+
53+
54+
# @pytest.mark.asyncio
55+
# async def test_parent_child_client():
56+
# async with ParentClient() as client:
57+
# await client.child_client.with_query()
58+
# await client.child_client.get_standalone()
59+
# await client.child_client.delete_standalone()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 specs.azure.clientgenerator.core.emptystring.aio import DeserializeEmptyStringAsNullClient
8+
from specs.azure.clientgenerator.core.emptystring import models
9+
10+
11+
@pytest.fixture
12+
async def client():
13+
async with DeserializeEmptyStringAsNullClient() as client:
14+
yield client
15+
16+
17+
@pytest.mark.asyncio
18+
async def test_get(client: DeserializeEmptyStringAsNullClient):
19+
result = await client.get()
20+
assert result == models.ResponseModel(sample_url="")

packages/typespec-python/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_usage_async.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,10 @@ async def test_model_usage(client: UsageClient):
2929
assert models.RoundTripModel(
3030
result=models.ResultModel(name="Madge")
3131
) == await client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())
32+
33+
34+
# @pytest.mark.asyncio
35+
# async def test_orphan_model_serializable(client: UsageClient):
36+
# await client.model_in_operation.orphan_model_serializable(
37+
# body=models.OrphanModel(model_name="name", description="desc")
38+
# )
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 specs.azure.encode.duration.aio import DurationClient
8+
from specs.azure.encode.duration import models
9+
10+
11+
@pytest.fixture
12+
async def client():
13+
async with DurationClient() as client:
14+
yield client
15+
16+
17+
@pytest.mark.asyncio
18+
async def test_duration_constant(client: DurationClient):
19+
await client.duration_constant(models.DurationModel(input="1.02:59:59.5000000"))

packages/typespec-python/test/azure/mock_api_tests/test_azure_arm_commonproperties.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pytest
77
from azure.resourcemanager.commonproperties import CommonPropertiesClient
88
from azure.resourcemanager.commonproperties import models
9+
from azure.core import exceptions
910

1011
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
1112
RESOURCE_GROUP_NAME = "test-rg"
@@ -58,3 +59,31 @@ def test_managed_identity_update_with_user_assigned_and_system_assigned(client):
5859
assert result.location == "eastus"
5960
assert result.identity.type == "SystemAssigned,UserAssigned"
6061
assert result.properties.provisioning_state == "Succeeded"
62+
63+
64+
def test_error_get_for_predefined_error(client):
65+
try:
66+
client.error.get_for_predefined_error(
67+
resource_group_name=RESOURCE_GROUP_NAME,
68+
confidential_resource_name="confidential",
69+
)
70+
except exceptions.ResourceNotFoundError as e:
71+
assert e.status_code == 404
72+
assert (
73+
e.error.message
74+
== "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
75+
)
76+
77+
78+
def test_error_create_for_user_defined_error(client):
79+
try:
80+
client.error.create_for_user_defined_error(
81+
resource_group_name=RESOURCE_GROUP_NAME,
82+
confidential_resource_name="confidential",
83+
resource=models.ConfidentialResource(
84+
location="eastus", properties=models.ConfidentialResourceProperties(username="00")
85+
),
86+
)
87+
except exceptions.HttpResponseError as e:
88+
assert e.status_code == 400
89+
assert e.error.message == "Username should not contain only numbers."
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.largeheader import LargeHeaderClient
8+
from azure.resourcemanager.largeheader import models
9+
10+
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
11+
RESOURCE_GROUP_NAME = "test-rg"
12+
13+
14+
@pytest.fixture
15+
def client(credential, authentication_policy):
16+
with LargeHeaderClient(
17+
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
18+
) as client:
19+
yield client
20+
21+
22+
def test_large_headers_begin_two6_k(client: LargeHeaderClient):
23+
result = client.large_headers.begin_two6_k(
24+
resource_group_name=RESOURCE_GROUP_NAME,
25+
large_header_name="header1",
26+
).result()
27+
assert result == models.CancelResult(succeeded=True)

0 commit comments

Comments
 (0)