Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .chronus/changes/copilot-fix-3106-2025-5-25-11-41-49.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-python"
---

Add test cases
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from azure.resourcemanager.commonproperties.aio import CommonPropertiesClient
from azure.resourcemanager.commonproperties import models
from azure.core import exceptions

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"
Expand Down Expand Up @@ -61,3 +62,33 @@ async def test_managed_identity_update_with_user_assigned_and_system_assigned(cl
assert result.location == "eastus"
assert result.identity.type == "SystemAssigned,UserAssigned"
assert result.properties.provisioning_state == "Succeeded"


@pytest.mark.asyncio
async def test_error_get_for_predefined_error(client):
try:
await client.error.get_for_predefined_error(
resource_group_name=RESOURCE_GROUP_NAME,
confidential_resource_name="confidential",
)
except exceptions.ResourceNotFoundError as e:
assert e.status_code == 404
assert (
e.error.message
== "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
)


@pytest.mark.asyncio
async def test_error_create_for_user_defined_error(client):
try:
await client.error.create_for_user_defined_error(
resource_group_name=RESOURCE_GROUP_NAME,
confidential_resource_name="confidential",
resource=models.ConfidentialResource(
location="eastus", properties=models.ConfidentialResourceProperties(username="00")
),
)
except exceptions.HttpResponseError as e:
assert e.status_code == 400
assert e.error.message == "Username should not contain only numbers."
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -------------------------------------------------------------------------
# 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.largeheader.aio import LargeHeaderClient
from azure.resourcemanager.largeheader import models

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"


@pytest.fixture
async def client(credential, authentication_policy):
async with LargeHeaderClient(
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
) as client:
yield client


@pytest.mark.asyncio
async def test_large_headers_begin_two6_k(client: LargeHeaderClient):
result = await (
await client.large_headers.begin_two6_k(
resource_group_name=RESOURCE_GROUP_NAME,
large_header_name="header1",
)
).result()
assert result == models.CancelResult(succeeded=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -------------------------------------------------------------------------
# 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.nonresource.aio import NonResourceClient
from azure.resourcemanager.nonresource import models

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"


@pytest.fixture
async def client(credential, authentication_policy):
async with NonResourceClient(
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
) as client:
yield client


@pytest.mark.asyncio
async def test_non_resource_create(client: NonResourceClient):
result = await client.non_resource_operations.create(
location="eastus", parameter="hello", body=models.NonResource(id="id", name="hello", type="nonResource")
)
assert result == models.NonResource(id="id", name="hello", type="nonResource")


@pytest.mark.asyncio
async def test_non_resource_get(client: NonResourceClient):
result = await client.non_resource_operations.get(
location="eastus",
parameter="hello",
)
assert result == models.NonResource(id="id", name="hello", type="nonResource")
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
MixedParamsClient,
PathParamClient,
ParamAliasClient,
ParentClient,
)
from specs.azure.clientgenerator.core.clientinitialization.models import Input

Expand Down Expand Up @@ -48,3 +49,11 @@ async def test_param_alias_client():
async with ParamAliasClient("sample-blob") as client:
await client.with_aliased_name()
await client.with_original_name()


# @pytest.mark.asyncio
# async def test_parent_child_client():
# async with ParentClient() as client:
# await client.child_client.with_query()
# await client.child_client.get_standalone()
# await client.child_client.delete_standalone()
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.emptystring.aio import DeserializeEmptyStringAsNullClient
from specs.azure.clientgenerator.core.emptystring import models


@pytest.fixture
async def client():
async with DeserializeEmptyStringAsNullClient() as client:
yield client


@pytest.mark.asyncio
async def test_get(client: DeserializeEmptyStringAsNullClient):
result = await client.get()
assert result == models.ResponseModel(sample_url="")
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ async def test_model_usage(client: UsageClient):
assert models.RoundTripModel(
result=models.ResultModel(name="Madge")
) == await client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())


# @pytest.mark.asyncio
# async def test_orphan_model_serializable(client: UsageClient):
# await client.model_in_operation.orphan_model_serializable(
# body=models.OrphanModel(model_name="name", description="desc")
# )
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -------------------------------------------------------------------------
# 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 specs.azure.encode.duration.aio import DurationClient
from specs.azure.encode.duration import models


@pytest.fixture
async def client():
async with DurationClient() as client:
yield client


@pytest.mark.asyncio
async def test_duration_constant(client: DurationClient):
await client.duration_constant(models.DurationModel(input="1.02:59:59.5000000"))
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pytest
from azure.resourcemanager.commonproperties import CommonPropertiesClient
from azure.resourcemanager.commonproperties import models
from azure.core import exceptions

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"
Expand Down Expand Up @@ -58,3 +59,31 @@ def test_managed_identity_update_with_user_assigned_and_system_assigned(client):
assert result.location == "eastus"
assert result.identity.type == "SystemAssigned,UserAssigned"
assert result.properties.provisioning_state == "Succeeded"


def test_error_get_for_predefined_error(client):
try:
client.error.get_for_predefined_error(
resource_group_name=RESOURCE_GROUP_NAME,
confidential_resource_name="confidential",
)
except exceptions.ResourceNotFoundError as e:
assert e.status_code == 404
assert (
e.error.message
== "The Resource 'Azure.ResourceManager.CommonProperties/confidentialResources/confidential' under resource group 'test-rg' was not found."
)


def test_error_create_for_user_defined_error(client):
try:
client.error.create_for_user_defined_error(
resource_group_name=RESOURCE_GROUP_NAME,
confidential_resource_name="confidential",
resource=models.ConfidentialResource(
location="eastus", properties=models.ConfidentialResourceProperties(username="00")
),
)
except exceptions.HttpResponseError as e:
assert e.status_code == 400
assert e.error.message == "Username should not contain only numbers."
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -------------------------------------------------------------------------
# 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.largeheader import LargeHeaderClient
from azure.resourcemanager.largeheader import models

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"


@pytest.fixture
def client(credential, authentication_policy):
with LargeHeaderClient(
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
) as client:
yield client


def test_large_headers_begin_two6_k(client: LargeHeaderClient):
result = client.large_headers.begin_two6_k(
resource_group_name=RESOURCE_GROUP_NAME,
large_header_name="header1",
).result()
assert result == models.CancelResult(succeeded=True)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -------------------------------------------------------------------------
# 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.nonresource import NonResourceClient
from azure.resourcemanager.nonresource import models

SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"


@pytest.fixture
def client(credential, authentication_policy):
with NonResourceClient(
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
) as client:
yield client


def test_non_resource_create(client: NonResourceClient):
result = client.non_resource_operations.create(
location="eastus", parameter="hello", body=models.NonResource(id="id", name="hello", type="nonResource")
)
assert result == models.NonResource(id="id", name="hello", type="nonResource")


def test_non_resource_get(client: NonResourceClient):
result = client.non_resource_operations.get(
location="eastus",
parameter="hello",
)
assert result == models.NonResource(id="id", name="hello", type="nonResource")
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
MixedParamsClient,
PathParamClient,
ParamAliasClient,
ParentClient,
)
from specs.azure.clientgenerator.core.clientinitialization.models import Input

Expand Down Expand Up @@ -42,3 +43,10 @@ def test_param_alias_client():
with ParamAliasClient("sample-blob") as client:
client.with_aliased_name()
client.with_original_name()


# def test_parent_child_client():
# with ParentClient() as client:
# client.child_client.with_query()
# client.child_client.get_standalone()
# client.child_client.delete_standalone()
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.emptystring import DeserializeEmptyStringAsNullClient
from specs.azure.clientgenerator.core.emptystring import models


@pytest.fixture
def client():
with DeserializeEmptyStringAsNullClient() as client:
yield client


def test_get(client: DeserializeEmptyStringAsNullClient):
result = client.get()
assert result == models.ResponseModel(sample_url="")
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ def test_model_usage(client: UsageClient):
assert models.RoundTripModel(
result=models.ResultModel(name="Madge")
) == client.model_in_operation.model_in_read_only_property(body=models.RoundTripModel())


# def test_orphan_model_serializable(client: UsageClient):
# client.model_in_operation.orphan_model_serializable(body=models.OrphanModel(model_name="name", description="desc"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -------------------------------------------------------------------------
# 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 specs.azure.encode.duration import DurationClient
from specs.azure.encode.duration import models


@pytest.fixture
def client():
with DurationClient() as client:
yield client


def test_duration_constant(client: DurationClient):
client.duration_constant(models.DurationModel(input="1.02:59:59.5000000"))
4 changes: 4 additions & 0 deletions packages/typespec-python/test/azure/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ azure-mgmt-core==1.5.0
# only for azure
-e ./generated/azure-client-generator-core-access
-e ./generated/azure-client-generator-core-client-initialization
-e ./generated/azure-client-generator-core-deserialize-empty-string-as-null
-e ./generated/azure-client-generator-core-flatten-property
-e ./generated/azure-client-generator-core-usage
-e ./generated/azure-core-basic
Expand All @@ -15,9 +16,12 @@ azure-mgmt-core==1.5.0
-e ./generated/azure-core-model
-e ./generated/azure-core-traits
-e ./generated/azure-core-page
-e ./generated/azure-encode-duration
-e ./generated/azure-special-headers-client-request-id/
-e ./generated/azure-example-basic
-e ./generated/azure-resource-manager-common-properties
-e ./generated/azure-resource-manager-large-header
-e ./generated/azure-resource-manager-non-resource
-e ./generated/azure-resource-manager-operation-templates
-e ./generated/azure-resource-manager-resources
-e ./generated/azure-payload-pageable
Expand Down
Loading