diff --git a/.chronus/changes/python-enable-arm-operationtemplates-tests-2026-08-17.md b/.chronus/changes/python-enable-arm-operationtemplates-tests-2026-08-17.md new file mode 100644 index 00000000000..dfa70624d02 --- /dev/null +++ b/.chronus/changes/python-enable-arm-operationtemplates-tests-2026-08-17.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Enable sync and async Azure ARM operation templates test coverage. diff --git a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts index 873e21f6f3d..e96933c5bf5 100644 --- a/packages/http-client-python/eng/scripts/ci/regenerate-common.ts +++ b/packages/http-client-python/eng/scripts/ci/regenerate-common.ts @@ -69,11 +69,7 @@ export interface BuildTaskGroupsOptions { // ---- Public constants ---- -export const SKIP_SPECS: string[] = [ - "type/file", - // LroPaging.postPagingLroWithBody generates begin_post_paging_lro_with_body with pylint R0915 (52/50). - "azure/resource-manager/operation-templates", -]; +export const SKIP_SPECS: string[] = ["type/file"]; export const SpecialFlags: Record> = { azure: { diff --git a/packages/http-client-python/eng/scripts/ci/run_pylint.py b/packages/http-client-python/eng/scripts/ci/run_pylint.py index d473b1e94e4..7001b5b648b 100644 --- a/packages/http-client-python/eng/scripts/ci/run_pylint.py +++ b/packages/http-client-python/eng/scripts/ci/run_pylint.py @@ -52,6 +52,7 @@ def _single_dir_pylint(mod): # narrow as possible: only this package, only the offending check. per_package_disables = { "azure-client-generator-core-exact-name": ["client-incorrect-naming-convention"], + "azure-resource-manager-operation-templates": ["too-many-statements"], } extra_disables = per_package_disables.get(mod.name) if extra_disables: diff --git a/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py index f8f2567d526..d28064a1bcc 100644 --- a/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py +++ b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py @@ -1,206 +1,206 @@ -# # ------------------------------------------------------------------------- -# # 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.operationtemplates.aio import OperationTemplatesClient -# from azure.resourcemanager.operationtemplates import models - -# SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" -# RESOURCE_GROUP_NAME = "test-rg" - - -# @pytest_asyncio.fixture -# async def client(credential, authentication_policy): -# async with OperationTemplatesClient( -# credential, -# SUBSCRIPTION_ID, -# "http://localhost:3000", -# authentication_policy=authentication_policy, -# polling_interval=0, -# ) as client: -# yield client - - -# @pytest.mark.asyncio -# async def test_check_name_availability_check_global(client): -# result = await client.check_name_availability.check_global( -# body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site") -# ) -# assert result.name_available == False -# assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS -# assert result.message == "Hostname 'checkName' already exists. Please select a different name." - - -# @pytest.mark.asyncio -# async def test_check_name_availability_check_local(client): -# result = await client.check_name_availability.check_local( -# location="westus", -# body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site"), -# ) -# assert result.name_available == False -# assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS -# assert result.message == "Hostname 'checkName' already exists. Please select a different name." - - -# @pytest.mark.asyncio -# async def test_operations_list(client): -# result = client.operations.list() -# async for operation in result: -# assert operation.name == "Microsoft.Compute/virtualMachines/write" -# assert operation.display.operation == "Create or Update Virtual Machine." -# assert operation.origin == "user,system" -# assert operation.action_type == "Internal" - - -# @pytest.mark.asyncio -# async def test_lro_begin_create_or_replace(client): -# result = await ( -# await client.lro.begin_create_or_replace( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# resource=models.Order( -# location="eastus", -# properties=models.OrderProperties(product_id="product1", amount=1), -# ), -# ) -# ).result() -# assert result.name == "order1" -# assert ( -# result.id -# == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1" -# ) -# assert result.type == "Azure.ResourceManager.Resources/orders" -# assert result.location == "eastus" -# assert result.system_data.created_by == "AzureSDK" - - -# @pytest.mark.asyncio -# async def test_lro_begin_export(client): -# await ( -# await client.lro.begin_export( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# body=models.ExportRequest(format="csv"), -# ) -# ).result() - - -# @pytest.mark.asyncio -# async def test_lro_begin_delete(client): -# await ( -# await client.lro.begin_delete( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# ) -# ).result() - - -# @pytest.mark.asyncio -# async def test_optional_body_get(client): -# result = await client.optional_body.get( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.name == "widget1" -# assert ( -# result.id -# == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/widgets/widget1" -# ) -# assert result.type == "Azure.ResourceManager.OperationTemplates/widgets" -# assert result.location == "eastus" -# assert result.properties.name == "widget1" -# assert result.properties.description == "A test widget" -# assert result.properties.provisioning_state == "Succeeded" - - -# @pytest.mark.asyncio -# async def test_optional_body_patch_without_body(client): -# result = await client.optional_body.patch( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.name == "widget1" -# assert result.properties.name == "widget1" -# assert result.properties.description == "A test widget" - - -# @pytest.mark.asyncio -# async def test_optional_body_patch_with_body(client): -# result = await client.optional_body.patch( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# properties=models.Widget( -# location="eastus", -# properties=models.WidgetProperties(name="updated-widget", description="Updated description"), -# ), -# ) -# assert result.name == "widget1" -# assert result.properties.name == "updated-widget" -# assert result.properties.description == "Updated description" - - -# @pytest.mark.asyncio -# async def test_optional_body_post_without_body(client): -# result = await client.optional_body.post( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.result == "Action completed successfully" - - -# @pytest.mark.asyncio -# async def test_optional_body_post_with_body(client): -# result = await client.optional_body.post( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# body=models.ActionRequest(action_type="perform", parameters="test-parameters"), -# ) -# assert result.result == "Action completed successfully with parameters" - - -# @pytest.mark.asyncio -# async def test_optional_body_provider_post_without_body(client): -# result = await client.optional_body.provider_post() -# assert result.total_allowed == 50 -# assert result.status == "Changed to default allowance" - - -# @pytest.mark.asyncio -# async def test_optional_body_provider_post_with_body(client): -# result = await client.optional_body.provider_post( -# body=models.ChangeAllowanceRequest(total_allowed=100, reason="Increased demand"), -# ) -# assert result.total_allowed == 100 -# assert result.status == "Changed to requested allowance" - - -# @pytest.mark.asyncio -# async def test_lro_begin_export_array(client): -# result = await ( -# await client.lro.begin_export_array( -# body=models.ExportRequest(format="csv"), -# ) -# ).result() -# assert len(result) == 2 -# assert result[0].content == "order1,product1,1" -# assert result[1].content == "order2,product2,2" - - -# @pytest.mark.asyncio -# async def test_lro_paging_begin_post_paging_lro(client): -# poller = await client.lro_paging.begin_post_paging_lro( -# resource_group_name=RESOURCE_GROUP_NAME, -# product_name="default", -# ) -# result = await poller.result() -# items = [item async for item in result] -# assert len(items) == 2 -# assert items[0].name == "product1" -# assert items[0].properties.product_id == "product1" -# assert items[0].properties.provisioning_state == "Succeeded" -# assert items[1].name == "product2" -# assert items[1].properties.product_id == "product2" -# assert items[1].properties.provisioning_state == "Succeeded" +# ------------------------------------------------------------------------- +# 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.operationtemplates.aio import OperationTemplatesClient +from azure.resourcemanager.operationtemplates import models + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +@pytest_asyncio.fixture +async def client(credential, authentication_policy): + async with OperationTemplatesClient( + credential, + SUBSCRIPTION_ID, + "http://localhost:3000", + authentication_policy=authentication_policy, + polling_interval=0, + ) as client: + yield client + + +@pytest.mark.asyncio +async def test_check_name_availability_check_global(client): + result = await client.check_name_availability.check_global( + body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site") + ) + assert result.name_available == False + assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS + assert result.message == "Hostname 'checkName' already exists. Please select a different name." + + +@pytest.mark.asyncio +async def test_check_name_availability_check_local(client): + result = await client.check_name_availability.check_local( + location="westus", + body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site"), + ) + assert result.name_available == False + assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS + assert result.message == "Hostname 'checkName' already exists. Please select a different name." + + +@pytest.mark.asyncio +async def test_operations_list(client): + result = client.operations.list() + async for operation in result: + assert operation.name == "Microsoft.Compute/virtualMachines/write" + assert operation.display.operation == "Create or Update Virtual Machine." + assert operation.origin == "user,system" + assert operation.action_type == "Internal" + + +@pytest.mark.asyncio +async def test_lro_begin_create_or_replace(client): + result = await ( + await client.lro.begin_create_or_replace( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + resource=models.Order( + location="eastus", + properties=models.OrderProperties(product_id="product1", amount=1), + ), + ) + ).result() + assert result.name == "order1" + assert ( + result.id + == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1" + ) + assert result.type == "Azure.ResourceManager.Resources/orders" + assert result.location == "eastus" + assert result.system_data.created_by == "AzureSDK" + + +@pytest.mark.asyncio +async def test_lro_begin_export(client): + await ( + await client.lro.begin_export( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + body=models.ExportRequest(format="csv"), + ) + ).result() + + +@pytest.mark.asyncio +async def test_lro_begin_delete(client): + await ( + await client.lro.begin_delete( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + ) + ).result() + + +@pytest.mark.asyncio +async def test_optional_body_get(client): + result = await client.optional_body.get( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.name == "widget1" + assert ( + result.id + == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/widgets/widget1" + ) + assert result.type == "Azure.ResourceManager.OperationTemplates/widgets" + assert result.location == "eastus" + assert result.properties.name == "widget1" + assert result.properties.description == "A test widget" + assert result.properties.provisioning_state == "Succeeded" + + +@pytest.mark.asyncio +async def test_optional_body_patch_without_body(client): + result = await client.optional_body.patch( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.name == "widget1" + assert result.properties.name == "widget1" + assert result.properties.description == "A test widget" + + +@pytest.mark.asyncio +async def test_optional_body_patch_with_body(client): + result = await client.optional_body.patch( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + properties=models.Widget( + location="eastus", + properties=models.WidgetProperties(name="updated-widget", description="Updated description"), + ), + ) + assert result.name == "widget1" + assert result.properties.name == "updated-widget" + assert result.properties.description == "Updated description" + + +@pytest.mark.asyncio +async def test_optional_body_post_without_body(client): + result = await client.optional_body.post( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.result == "Action completed successfully" + + +@pytest.mark.asyncio +async def test_optional_body_post_with_body(client): + result = await client.optional_body.post( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + body=models.ActionRequest(action_type="perform", parameters="test-parameters"), + ) + assert result.result == "Action completed successfully with parameters" + + +@pytest.mark.asyncio +async def test_optional_body_provider_post_without_body(client): + result = await client.optional_body.provider_post() + assert result.total_allowed == 50 + assert result.status == "Changed to default allowance" + + +@pytest.mark.asyncio +async def test_optional_body_provider_post_with_body(client): + result = await client.optional_body.provider_post( + body=models.ChangeAllowanceRequest(total_allowed=100, reason="Increased demand"), + ) + assert result.total_allowed == 100 + assert result.status == "Changed to requested allowance" + + +@pytest.mark.asyncio +async def test_lro_begin_export_array(client): + result = await ( + await client.lro.begin_export_array( + body=models.ExportRequest(format="csv"), + ) + ).result() + assert len(result) == 2 + assert result[0].content == "order1,product1,1" + assert result[1].content == "order2,product2,2" + + +@pytest.mark.asyncio +async def test_lro_paging_begin_post_paging_lro(client): + poller = await client.lro_paging.begin_post_paging_lro( + resource_group_name=RESOURCE_GROUP_NAME, + product_name="default", + ) + result = await poller.result() + items = [item async for item in result] + assert len(items) == 2 + assert items[0].name == "product1" + assert items[0].properties.product_id == "product1" + assert items[0].properties.provisioning_state == "Succeeded" + assert items[1].name == "product2" + assert items[1].properties.product_id == "product2" + assert items[1].properties.provisioning_state == "Succeeded" diff --git a/packages/http-client-python/tests/mock_api/azure/test_azure_arm_operationtemplates.py b/packages/http-client-python/tests/mock_api/azure/test_azure_arm_operationtemplates.py index cfa7dc6b8a2..c86c95ef4a9 100644 --- a/packages/http-client-python/tests/mock_api/azure/test_azure_arm_operationtemplates.py +++ b/packages/http-client-python/tests/mock_api/azure/test_azure_arm_operationtemplates.py @@ -1,180 +1,180 @@ -# # ------------------------------------------------------------------------- -# # 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.operationtemplates import OperationTemplatesClient -# from azure.resourcemanager.operationtemplates import models - -# SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" -# RESOURCE_GROUP_NAME = "test-rg" - - -# @pytest.fixture -# def client(credential, authentication_policy): -# with OperationTemplatesClient( -# credential, -# SUBSCRIPTION_ID, -# "http://localhost:3000", -# authentication_policy=authentication_policy, -# polling_interval=0, -# ) as client: -# yield client - - -# def test_check_name_availability_check_global(client): -# result = client.check_name_availability.check_global( -# body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site") -# ) -# assert result.name_available == False -# assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS -# assert result.message == "Hostname 'checkName' already exists. Please select a different name." - - -# def test_check_name_availability_check_local(client): -# result = client.check_name_availability.check_local( -# location="westus", -# body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site"), -# ) -# assert result.name_available == False -# assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS -# assert result.message == "Hostname 'checkName' already exists. Please select a different name." - - -# def test_operations_list(client): -# result = client.operations.list().next() -# assert result.name == "Microsoft.Compute/virtualMachines/write" -# assert result.display.operation == "Create or Update Virtual Machine." -# assert result.origin == "user,system" -# assert result.action_type == "Internal" - - -# def test_lro_begin_create_or_replace(client): -# result = client.lro.begin_create_or_replace( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# resource=models.Order( -# location="eastus", -# properties=models.OrderProperties(product_id="product1", amount=1), -# ), -# ).result() -# assert result.name == "order1" -# assert ( -# result.id -# == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1" -# ) -# assert result.type == "Azure.ResourceManager.Resources/orders" -# assert result.location == "eastus" -# assert result.system_data.created_by == "AzureSDK" - - -# def test_lro_begin_export(client): -# client.lro.begin_export( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# body=models.ExportRequest(format="csv"), -# ).result() - - -# def test_lro_begin_delete(client): -# client.lro.begin_delete( -# resource_group_name=RESOURCE_GROUP_NAME, -# order_name="order1", -# ).result() - - -# def test_optional_body_get(client): -# result = client.optional_body.get( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.name == "widget1" -# assert ( -# result.id -# == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/widgets/widget1" -# ) -# assert result.type == "Azure.ResourceManager.OperationTemplates/widgets" -# assert result.location == "eastus" -# assert result.properties.name == "widget1" -# assert result.properties.description == "A test widget" -# assert result.properties.provisioning_state == "Succeeded" - - -# def test_optional_body_patch_without_body(client): -# result = client.optional_body.patch( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.name == "widget1" -# assert result.properties.name == "widget1" -# assert result.properties.description == "A test widget" - - -# def test_optional_body_patch_with_body(client): -# result = client.optional_body.patch( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# properties=models.Widget( -# location="eastus", -# properties=models.WidgetProperties(name="updated-widget", description="Updated description"), -# ), -# ) -# assert result.name == "widget1" -# assert result.properties.name == "updated-widget" -# assert result.properties.description == "Updated description" - - -# def test_optional_body_post_without_body(client): -# result = client.optional_body.post( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# ) -# assert result.result == "Action completed successfully" - - -# def test_optional_body_post_with_body(client): -# result = client.optional_body.post( -# resource_group_name=RESOURCE_GROUP_NAME, -# widget_name="widget1", -# body=models.ActionRequest(action_type="perform", parameters="test-parameters"), -# ) -# assert result.result == "Action completed successfully with parameters" - - -# def test_optional_body_provider_post_without_body(client): -# result = client.optional_body.provider_post() -# assert result.total_allowed == 50 -# assert result.status == "Changed to default allowance" - - -# def test_optional_body_provider_post_with_body(client): -# result = client.optional_body.provider_post( -# body=models.ChangeAllowanceRequest(total_allowed=100, reason="Increased demand"), -# ) -# assert result.total_allowed == 100 -# assert result.status == "Changed to requested allowance" - - -# def test_lro_begin_export_array(client): -# result = client.lro.begin_export_array( -# body=models.ExportRequest(format="csv"), -# ).result() -# assert len(result) == 2 -# assert result[0].content == "order1,product1,1" -# assert result[1].content == "order2,product2,2" - - -# def test_lro_paging_begin_post_paging_lro(client): -# result = client.lro_paging.begin_post_paging_lro( -# resource_group_name=RESOURCE_GROUP_NAME, -# product_name="default", -# ).result() -# items = list(result) -# assert len(items) == 2 -# assert items[0].name == "product1" -# assert items[0].properties.product_id == "product1" -# assert items[0].properties.provisioning_state == "Succeeded" -# assert items[1].name == "product2" -# assert items[1].properties.product_id == "product2" -# assert items[1].properties.provisioning_state == "Succeeded" +# ------------------------------------------------------------------------- +# 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.operationtemplates import OperationTemplatesClient +from azure.resourcemanager.operationtemplates import models + +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" +RESOURCE_GROUP_NAME = "test-rg" + + +@pytest.fixture +def client(credential, authentication_policy): + with OperationTemplatesClient( + credential, + SUBSCRIPTION_ID, + "http://localhost:3000", + authentication_policy=authentication_policy, + polling_interval=0, + ) as client: + yield client + + +def test_check_name_availability_check_global(client): + result = client.check_name_availability.check_global( + body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site") + ) + assert result.name_available == False + assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS + assert result.message == "Hostname 'checkName' already exists. Please select a different name." + + +def test_check_name_availability_check_local(client): + result = client.check_name_availability.check_local( + location="westus", + body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site"), + ) + assert result.name_available == False + assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS + assert result.message == "Hostname 'checkName' already exists. Please select a different name." + + +def test_operations_list(client): + result = client.operations.list().next() + assert result.name == "Microsoft.Compute/virtualMachines/write" + assert result.display.operation == "Create or Update Virtual Machine." + assert result.origin == "user,system" + assert result.action_type == "Internal" + + +def test_lro_begin_create_or_replace(client): + result = client.lro.begin_create_or_replace( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + resource=models.Order( + location="eastus", + properties=models.OrderProperties(product_id="product1", amount=1), + ), + ).result() + assert result.name == "order1" + assert ( + result.id + == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1" + ) + assert result.type == "Azure.ResourceManager.Resources/orders" + assert result.location == "eastus" + assert result.system_data.created_by == "AzureSDK" + + +def test_lro_begin_export(client): + client.lro.begin_export( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + body=models.ExportRequest(format="csv"), + ).result() + + +def test_lro_begin_delete(client): + client.lro.begin_delete( + resource_group_name=RESOURCE_GROUP_NAME, + order_name="order1", + ).result() + + +def test_optional_body_get(client): + result = client.optional_body.get( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.name == "widget1" + assert ( + result.id + == "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/widgets/widget1" + ) + assert result.type == "Azure.ResourceManager.OperationTemplates/widgets" + assert result.location == "eastus" + assert result.properties.name == "widget1" + assert result.properties.description == "A test widget" + assert result.properties.provisioning_state == "Succeeded" + + +def test_optional_body_patch_without_body(client): + result = client.optional_body.patch( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.name == "widget1" + assert result.properties.name == "widget1" + assert result.properties.description == "A test widget" + + +def test_optional_body_patch_with_body(client): + result = client.optional_body.patch( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + properties=models.Widget( + location="eastus", + properties=models.WidgetProperties(name="updated-widget", description="Updated description"), + ), + ) + assert result.name == "widget1" + assert result.properties.name == "updated-widget" + assert result.properties.description == "Updated description" + + +def test_optional_body_post_without_body(client): + result = client.optional_body.post( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + ) + assert result.result == "Action completed successfully" + + +def test_optional_body_post_with_body(client): + result = client.optional_body.post( + resource_group_name=RESOURCE_GROUP_NAME, + widget_name="widget1", + body=models.ActionRequest(action_type="perform", parameters="test-parameters"), + ) + assert result.result == "Action completed successfully with parameters" + + +def test_optional_body_provider_post_without_body(client): + result = client.optional_body.provider_post() + assert result.total_allowed == 50 + assert result.status == "Changed to default allowance" + + +def test_optional_body_provider_post_with_body(client): + result = client.optional_body.provider_post( + body=models.ChangeAllowanceRequest(total_allowed=100, reason="Increased demand"), + ) + assert result.total_allowed == 100 + assert result.status == "Changed to requested allowance" + + +def test_lro_begin_export_array(client): + result = client.lro.begin_export_array( + body=models.ExportRequest(format="csv"), + ).result() + assert len(result) == 2 + assert result[0].content == "order1,product1,1" + assert result[1].content == "order2,product2,2" + + +def test_lro_paging_begin_post_paging_lro(client): + result = client.lro_paging.begin_post_paging_lro( + resource_group_name=RESOURCE_GROUP_NAME, + product_name="default", + ).result() + items = list(result) + assert len(items) == 2 + assert items[0].name == "product1" + assert items[0].properties.product_id == "product1" + assert items[0].properties.provisioning_state == "Succeeded" + assert items[1].name == "product2" + assert items[1].properties.product_id == "product2" + assert items[1].properties.provisioning_state == "Succeeded"