Skip to content
Closed
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 sync and async mock_api tests for the management group scoped resources and ARM resource identifier Spector scenarios from azure-http-specs.
8 changes: 4 additions & 4 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 @@ -103,7 +103,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.68.0",
"@azure-tools/typespec-azure-rulesets": "~0.68.0",
"@azure-tools/typespec-client-generator-core": "~0.68.4",
"@azure-tools/azure-http-specs": "0.1.0-alpha.42-dev.0",
"@azure-tools/azure-http-specs": "0.1.0-alpha.42-dev.2",
"@typespec/compiler": "^1.12.0",
"@typespec/http": "^1.12.0",
"@typespec/openapi": "^1.12.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"

SIMPLE_ARM_ID = f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Network/virtualNetworks/myVnet"
ARM_ID_WITH_TYPE = SIMPLE_ARM_ID
ARM_ID_WITH_TYPE_AND_SCOPE = SIMPLE_ARM_ID
ARM_ID_WITH_ALL_SCOPES = f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Compute/virtualMachines/myVm"


@pytest_asyncio.fixture
async def client(credential, authentication_policy):
Expand Down Expand Up @@ -93,3 +98,39 @@ async def test_error_create_for_user_defined_error(client):
except exceptions.HttpResponseError as e:
assert e.status_code == 400
assert e.error.message == "Username should not contain only numbers."


@pytest.mark.asyncio
async def test_arm_resource_identifiers_get(client):
result = await client.arm_resource_identifiers.get(
resource_group_name=RESOURCE_GROUP_NAME, arm_resource_identifier_resource_name="armId"
)
assert result.location == "eastus"
assert result.properties.provisioning_state == "Succeeded"
assert result.properties.simple_arm_id == SIMPLE_ARM_ID
assert result.properties.arm_id_with_type == ARM_ID_WITH_TYPE
assert result.properties.arm_id_with_type_and_scope == ARM_ID_WITH_TYPE_AND_SCOPE
assert result.properties.arm_id_with_all_scopes == ARM_ID_WITH_ALL_SCOPES


@pytest.mark.asyncio
async def test_arm_resource_identifiers_create_or_replace(client):
result = await client.arm_resource_identifiers.create_or_replace(
resource_group_name=RESOURCE_GROUP_NAME,
arm_resource_identifier_resource_name="armId",
resource=models.ArmResourceIdentifierResource(
location="eastus",
properties=models.ArmResourceIdentifierResourceProperties(
simple_arm_id=SIMPLE_ARM_ID,
arm_id_with_type=ARM_ID_WITH_TYPE,
arm_id_with_type_and_scope=ARM_ID_WITH_TYPE_AND_SCOPE,
arm_id_with_all_scopes=ARM_ID_WITH_ALL_SCOPES,
),
),
)
assert result.location == "eastus"
assert result.properties.provisioning_state == "Succeeded"
assert result.properties.simple_arm_id == SIMPLE_ARM_ID
assert result.properties.arm_id_with_type == ARM_ID_WITH_TYPE
assert result.properties.arm_id_with_type_and_scope == ARM_ID_WITH_TYPE_AND_SCOPE
assert result.properties.arm_id_with_all_scopes == ARM_ID_WITH_ALL_SCOPES
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import pytest
import pytest_asyncio
from azure.resourcemanager.managementgroup.aio import ManagementGroupClient
from azure.resourcemanager.managementgroup import models

MANAGEMENT_GROUP_ID = "test-mg"
RESOURCE_NAME = "resource"


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


@pytest.mark.asyncio
async def test_management_group_child_resources_get(client):
result = await client.management_group_child_resources.get(
management_group_id=MANAGEMENT_GROUP_ID, management_group_child_resource_name=RESOURCE_NAME
)
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid"
assert result.properties.provisioning_state == "Succeeded"


@pytest.mark.asyncio
async def test_management_group_child_resources_create_or_update(client):
result = await (
await client.management_group_child_resources.begin_create_or_update(
management_group_id=MANAGEMENT_GROUP_ID,
management_group_child_resource_name=RESOURCE_NAME,
resource=models.ManagementGroupChildResource(
properties=models.ManagementGroupChildResourceProperties(description="valid")
),
polling_interval=0,
)
).result()
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid"
assert result.properties.provisioning_state == "Succeeded"


@pytest.mark.asyncio
async def test_management_group_child_resources_update(client):
result = await client.management_group_child_resources.update(
management_group_id=MANAGEMENT_GROUP_ID,
management_group_child_resource_name=RESOURCE_NAME,
properties=models.ManagementGroupChildResource(
properties=models.ManagementGroupChildResourceProperties(description="valid2")
),
)
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid2"
assert result.properties.provisioning_state == "Succeeded"


@pytest.mark.asyncio
async def test_management_group_child_resources_delete(client):
await client.management_group_child_resources.delete(
management_group_id=MANAGEMENT_GROUP_ID, management_group_child_resource_name=RESOURCE_NAME
)


@pytest.mark.asyncio
async def test_management_group_child_resources_list_by_management_group(client):
result = [
item
async for item in client.management_group_child_resources.list_by_management_group(
management_group_id=MANAGEMENT_GROUP_ID
)
]
assert len(result) == 1
assert result[0].name == RESOURCE_NAME
assert result[0].properties.description == "valid"
assert result[0].properties.provisioning_state == "Succeeded"
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"
RESOURCE_GROUP_NAME = "test-rg"

SIMPLE_ARM_ID = f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Network/virtualNetworks/myVnet"
ARM_ID_WITH_TYPE = SIMPLE_ARM_ID
ARM_ID_WITH_TYPE_AND_SCOPE = SIMPLE_ARM_ID
ARM_ID_WITH_ALL_SCOPES = f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Microsoft.Compute/virtualMachines/myVm"


@pytest.fixture
def client(credential, authentication_policy):
Expand Down Expand Up @@ -87,3 +92,37 @@ def test_error_create_for_user_defined_error(client):
except exceptions.HttpResponseError as e:
assert e.status_code == 400
assert e.error.message == "Username should not contain only numbers."


def test_arm_resource_identifiers_get(client):
result = client.arm_resource_identifiers.get(
resource_group_name=RESOURCE_GROUP_NAME, arm_resource_identifier_resource_name="armId"
)
assert result.location == "eastus"
assert result.properties.provisioning_state == "Succeeded"
assert result.properties.simple_arm_id == SIMPLE_ARM_ID
assert result.properties.arm_id_with_type == ARM_ID_WITH_TYPE
assert result.properties.arm_id_with_type_and_scope == ARM_ID_WITH_TYPE_AND_SCOPE
assert result.properties.arm_id_with_all_scopes == ARM_ID_WITH_ALL_SCOPES


def test_arm_resource_identifiers_create_or_replace(client):
result = client.arm_resource_identifiers.create_or_replace(
resource_group_name=RESOURCE_GROUP_NAME,
arm_resource_identifier_resource_name="armId",
resource=models.ArmResourceIdentifierResource(
location="eastus",
properties=models.ArmResourceIdentifierResourceProperties(
simple_arm_id=SIMPLE_ARM_ID,
arm_id_with_type=ARM_ID_WITH_TYPE,
arm_id_with_type_and_scope=ARM_ID_WITH_TYPE_AND_SCOPE,
arm_id_with_all_scopes=ARM_ID_WITH_ALL_SCOPES,
),
),
)
assert result.location == "eastus"
assert result.properties.provisioning_state == "Succeeded"
assert result.properties.simple_arm_id == SIMPLE_ARM_ID
assert result.properties.arm_id_with_type == ARM_ID_WITH_TYPE
assert result.properties.arm_id_with_type_and_scope == ARM_ID_WITH_TYPE_AND_SCOPE
assert result.properties.arm_id_with_all_scopes == ARM_ID_WITH_ALL_SCOPES
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -------------------------------------------------------------------------
# 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.managementgroup import ManagementGroupClient
from azure.resourcemanager.managementgroup import models

MANAGEMENT_GROUP_ID = "test-mg"
RESOURCE_NAME = "resource"


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


def test_management_group_child_resources_get(client):
result = client.management_group_child_resources.get(
management_group_id=MANAGEMENT_GROUP_ID, management_group_child_resource_name=RESOURCE_NAME
)
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid"
assert result.properties.provisioning_state == "Succeeded"


def test_management_group_child_resources_create_or_update(client):
result = client.management_group_child_resources.begin_create_or_update(
management_group_id=MANAGEMENT_GROUP_ID,
management_group_child_resource_name=RESOURCE_NAME,
resource=models.ManagementGroupChildResource(
properties=models.ManagementGroupChildResourceProperties(description="valid")
),
polling_interval=0,
).result()
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid"
assert result.properties.provisioning_state == "Succeeded"


def test_management_group_child_resources_update(client):
result = client.management_group_child_resources.update(
management_group_id=MANAGEMENT_GROUP_ID,
management_group_child_resource_name=RESOURCE_NAME,
properties=models.ManagementGroupChildResource(
properties=models.ManagementGroupChildResourceProperties(description="valid2")
),
)
assert result.name == RESOURCE_NAME
assert result.properties.description == "valid2"
assert result.properties.provisioning_state == "Succeeded"


def test_management_group_child_resources_delete(client):
client.management_group_child_resources.delete(
management_group_id=MANAGEMENT_GROUP_ID, management_group_child_resource_name=RESOURCE_NAME
)


def test_management_group_child_resources_list_by_management_group(client):
result = list(
client.management_group_child_resources.list_by_management_group(management_group_id=MANAGEMENT_GROUP_ID)
)
assert len(result) == 1
assert result[0].name == RESOURCE_NAME
assert result[0].properties.description == "valid"
assert result[0].properties.provisioning_state == "Succeeded"