Skip to content

Commit 3f912d4

Browse files
[python] update testcases (#3040)
1 parent 4f6224e commit 3f912d4

6 files changed

Lines changed: 566 additions & 6 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+
- "@azure-tools/typespec-python"
5+
---
6+
7+
add testcases for latest spector scenarios
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.operationtemplates.aio import OperationTemplatesClient
8+
from azure.resourcemanager.operationtemplates 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 OperationTemplatesClient(
17+
credential,
18+
SUBSCRIPTION_ID,
19+
"http://localhost:3000",
20+
authentication_policy=authentication_policy,
21+
) as client:
22+
yield client
23+
24+
25+
@pytest.mark.asyncio
26+
async def test_check_name_availability_check_global(client):
27+
result = await client.check_name_availability.check_global(
28+
body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site")
29+
)
30+
assert result.name_available == False
31+
assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS
32+
assert result.message == "Hostname 'checkName' already exists. Please select a different name."
33+
34+
35+
@pytest.mark.asyncio
36+
async def test_check_name_availability_check_local(client):
37+
result = await client.check_name_availability.check_local(
38+
location="westus",
39+
body=models.CheckNameAvailabilityRequest(name="checkName", type="Microsoft.Web/site"),
40+
)
41+
assert result.name_available == False
42+
assert result.reason == models.CheckNameAvailabilityReason.ALREADY_EXISTS
43+
assert result.message == "Hostname 'checkName' already exists. Please select a different name."
44+
45+
46+
@pytest.mark.asyncio
47+
async def test_operations_list(client):
48+
result = client.operations.list()
49+
assert result
50+
51+
52+
@pytest.mark.asyncio
53+
async def test_lro_begin_create_or_replace(client):
54+
result = await (
55+
await client.lro.begin_create_or_replace(
56+
resource_group_name=RESOURCE_GROUP_NAME,
57+
order_name="order1",
58+
resource=models.Order(
59+
location="eastus",
60+
properties=models.OrderProperties(product_id="product1", amount=1),
61+
),
62+
)
63+
).result()
64+
assert result.name == "order1"
65+
assert (
66+
result.id
67+
== "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1"
68+
)
69+
assert result.type == "Azure.ResourceManager.Resources/orders"
70+
assert result.location == "eastus"
71+
assert result.system_data.created_by == "AzureSDK"
72+
73+
74+
@pytest.mark.asyncio
75+
async def test_lro_begin_export(client):
76+
await (
77+
await client.lro.begin_export(
78+
resource_group_name=RESOURCE_GROUP_NAME,
79+
order_name="order1",
80+
body=models.ExportRequest(format="csv"),
81+
)
82+
).result()
83+
84+
85+
@pytest.mark.asyncio
86+
async def test_lro_begin_delete(client):
87+
await (
88+
await client.lro.begin_delete(
89+
resource_group_name=RESOURCE_GROUP_NAME,
90+
order_name="order1",
91+
)
92+
).result()

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

Lines changed: 199 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
@pytest.fixture
1515
async def client(credential, authentication_policy):
1616
async with ResourcesClient(
17-
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
17+
credential,
18+
SUBSCRIPTION_ID,
19+
"http://localhost:3000",
20+
authentication_policy=authentication_policy,
1821
) as client:
1922
yield client
2023

@@ -23,7 +26,10 @@ async def client(credential, authentication_policy):
2326
async def test_client_signature(credential, authentication_policy):
2427
# make sure signautre order is correct
2528
client1 = ResourcesClient(
26-
credential, SUBSCRIPTION_ID, "http://localhost:3000", authentication_policy=authentication_policy
29+
credential,
30+
SUBSCRIPTION_ID,
31+
"http://localhost:3000",
32+
authentication_policy=authentication_policy,
2733
)
2834
# make sure signautre name is correct
2935
client2 = ResourcesClient(
@@ -36,7 +42,10 @@ async def test_client_signature(credential, authentication_policy):
3642
# make sure signautre order is correct
3743
await client.top_level.get(RESOURCE_GROUP_NAME, "top")
3844
# make sure signautre name is correct
39-
await client.top_level.get(resource_group_name=RESOURCE_GROUP_NAME, top_level_tracked_resource_name="top")
45+
await client.top_level.get(
46+
resource_group_name=RESOURCE_GROUP_NAME,
47+
top_level_tracked_resource_name="top",
48+
)
4049

4150

4251
@pytest.mark.asyncio
@@ -280,3 +289,190 @@ async def test_singleton_list_by_resource_group(client):
280289
assert result.name == "default"
281290
assert result.type == "Azure.ResourceManager.Resources/singletonTrackedResources"
282291
assert result.system_data.created_by == "AzureSDK"
292+
293+
294+
@pytest.mark.asyncio
295+
@pytest.mark.parametrize(
296+
"scope",
297+
[
298+
"",
299+
"/subscriptions/00000000-0000-0000-0000-000000000000",
300+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg",
301+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top",
302+
],
303+
)
304+
async def test_extensions_resources_begin_create_or_update(client, scope):
305+
result = await (
306+
await client.extensions_resources.begin_create_or_update(
307+
resource_uri=scope,
308+
extensions_resource_name="extension",
309+
resource=models.ExtensionsResource(properties=models.ExtensionsResourceProperties(description="valid")),
310+
)
311+
).result()
312+
assert result.id == f"{scope}/providers/Azure.ResourceManager.Resources/extensionsResources/extension"
313+
assert result.name == "extension"
314+
assert result.type == "Azure.ResourceManager.Resources/extensionsResources"
315+
assert result.properties.description == "valid"
316+
assert result.properties.provisioning_state == "Succeeded"
317+
assert result.system_data.created_by == "AzureSDK"
318+
319+
320+
@pytest.mark.asyncio
321+
@pytest.mark.parametrize(
322+
"scope",
323+
[
324+
"",
325+
"/subscriptions/00000000-0000-0000-0000-000000000000",
326+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg",
327+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top",
328+
],
329+
)
330+
async def test_extensions_resources_update(client, scope):
331+
result = await client.extensions_resources.update(
332+
resource_uri=scope,
333+
extensions_resource_name="extension",
334+
properties=models.ExtensionsResource(properties=models.ExtensionsResourceProperties(description="valid2")),
335+
)
336+
assert result.id == f"{scope}/providers/Azure.ResourceManager.Resources/extensionsResources/extension"
337+
assert result.name == "extension"
338+
assert result.type == "Azure.ResourceManager.Resources/extensionsResources"
339+
assert result.properties.description == "valid2"
340+
assert result.properties.provisioning_state == "Succeeded"
341+
assert result.system_data.created_by == "AzureSDK"
342+
343+
344+
@pytest.mark.asyncio
345+
@pytest.mark.parametrize(
346+
"scope",
347+
[
348+
"",
349+
"/subscriptions/00000000-0000-0000-0000-000000000000",
350+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg",
351+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top",
352+
],
353+
)
354+
async def test_extensions_resources_get(client, scope):
355+
result = await client.extensions_resources.get(resource_uri=scope, extensions_resource_name="extension")
356+
assert result.id == f"{scope}/providers/Azure.ResourceManager.Resources/extensionsResources/extension"
357+
assert result.name == "extension"
358+
assert result.type == "Azure.ResourceManager.Resources/extensionsResources"
359+
assert result.properties.description == "valid"
360+
assert result.properties.provisioning_state == "Succeeded"
361+
assert result.system_data.created_by == "AzureSDK"
362+
363+
364+
@pytest.mark.asyncio
365+
@pytest.mark.parametrize(
366+
"scope",
367+
[
368+
"",
369+
"/subscriptions/00000000-0000-0000-0000-000000000000",
370+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg",
371+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top",
372+
],
373+
)
374+
async def test_extensions_resources_list_by_scope(client, scope):
375+
response = client.extensions_resources.list_by_scope(
376+
resource_uri=scope,
377+
)
378+
result = [r async for r in response]
379+
for result in result:
380+
assert result.id == f"{scope}/providers/Azure.ResourceManager.Resources/extensionsResources/extension"
381+
assert result.name == "extension"
382+
assert result.type == "Azure.ResourceManager.Resources/extensionsResources"
383+
assert result.properties.description == "valid"
384+
assert result.properties.provisioning_state == "Succeeded"
385+
assert result.system_data.created_by == "AzureSDK"
386+
387+
388+
@pytest.mark.asyncio
389+
@pytest.mark.parametrize(
390+
"scope",
391+
[
392+
"",
393+
"/subscriptions/00000000-0000-0000-0000-000000000000",
394+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg",
395+
"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top",
396+
],
397+
)
398+
async def test_extensions_resources_delete(client, scope):
399+
await client.extensions_resources.delete(resource_uri=scope, extensions_resource_name="extension")
400+
401+
402+
@pytest.mark.asyncio
403+
async def test_location_resources_create_or_update(client):
404+
result = await client.location_resources.create_or_update(
405+
location="eastus",
406+
location_resource_name="resource",
407+
resource=models.LocationResource(properties=models.LocationResourceProperties(description="valid")),
408+
)
409+
assert (
410+
result.id
411+
== "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource"
412+
)
413+
assert result.name == "resource"
414+
assert result.type == "Azure.ResourceManager.Resources/locationResources"
415+
assert result.properties.description == "valid"
416+
assert result.properties.provisioning_state == "Succeeded"
417+
assert result.system_data.created_by == "AzureSDK"
418+
419+
420+
@pytest.mark.asyncio
421+
async def test_location_resources_update(client):
422+
result = await client.location_resources.update(
423+
location="eastus",
424+
location_resource_name="resource",
425+
properties=models.LocationResource(properties=models.LocationResourceProperties(description="valid2")),
426+
)
427+
assert (
428+
result.id
429+
== "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource"
430+
)
431+
assert result.name == "resource"
432+
assert result.type == "Azure.ResourceManager.Resources/locationResources"
433+
assert result.properties.description == "valid2"
434+
assert result.properties.provisioning_state == "Succeeded"
435+
assert result.system_data.created_by == "AzureSDK"
436+
437+
438+
@pytest.mark.asyncio
439+
async def test_location_resources_get(client):
440+
result = await client.location_resources.get(
441+
location="eastus",
442+
location_resource_name="resource",
443+
)
444+
assert (
445+
result.id
446+
== "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource"
447+
)
448+
assert result.name == "resource"
449+
assert result.type == "Azure.ResourceManager.Resources/locationResources"
450+
assert result.properties.description == "valid"
451+
assert result.properties.provisioning_state == "Succeeded"
452+
assert result.system_data.created_by == "AzureSDK"
453+
454+
455+
@pytest.mark.asyncio
456+
async def test_location_resources_delete(client):
457+
await client.location_resources.delete(
458+
location="eastus",
459+
location_resource_name="resource",
460+
)
461+
462+
463+
@pytest.mark.asyncio
464+
async def test_location_resources_list_by_location(client):
465+
response = client.location_resources.list_by_location(
466+
location="eastus",
467+
)
468+
result = [r async for r in response]
469+
for result in result:
470+
assert (
471+
result.id
472+
== "/subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource"
473+
)
474+
assert result.name == "resource"
475+
assert result.type == "Azure.ResourceManager.Resources/locationResources"
476+
assert result.properties.description == "valid"
477+
assert result.properties.provisioning_state == "Succeeded"
478+
assert result.system_data.created_by == "AzureSDK"

0 commit comments

Comments
 (0)