Skip to content

Commit 5ccc2fe

Browse files
Copilotmsyyc
andauthored
Add Python mock-api tests for postPagingLroWithBody ARM LRO paging scenario (#11344)
fix #11400 and #11405 Adds Python SDK coverage for the `postPagingLroWithBody` ARM scenario updated in [Azure/typespec-azure#4991](Azure/typespec-azure#4991), which declares the LRO final result (`ArmLroLocationHeader<FinalResult = ProductListResult>`) for a paged LRO POST that takes a request body. ### Changes - **Spec dependency**: bumped `@azure-tools/azure-http-specs` to `0.1.0-alpha.44-dev.4`, the first published version containing the fix. - **Sync test** (`mock_api/azure/test_azure_arm_operationtemplates.py`): exercises `begin_post_paging_lro_with_body` with a `VnetProfile` body and asserts the two-page result. - **Async test** (`mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py`): async counterpart. - **Changelog**: `internal` entry for `@typespec/http-client-python`. ```python def test_lro_paging_begin_post_paging_lro_with_body(client): result = client.lro_paging.begin_post_paging_lro_with_body( resource_group_name=RESOURCE_GROUP_NAME, product_name="default", body=models.VnetProfile(vnet_id="vnet1"), ).result() items = list(result) assert [i.name for i in items] == ["product1", "product2"] ``` --------- 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 d3cdadd commit 5ccc2fe

3 files changed

Lines changed: 184 additions & 0 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+
- "@typespec/http-client-python"
5+
---
6+
7+
Add mock API tests for the new ARM operation-templates scenarios (`postPagingLroWithBody`, `getLro`, `postActionPaging`, `markAsPageable`, `Legacy.routedGet`, and `Legacy.createOrReplaceOptionalBody`).

packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_arm_operationtemplates_async.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,96 @@ async def test_lro_paging_begin_post_paging_lro(client):
204204
assert items[1].name == "product2"
205205
assert items[1].properties.product_id == "product2"
206206
assert items[1].properties.provisioning_state == "Succeeded"
207+
208+
209+
@pytest.mark.asyncio
210+
async def test_lro_paging_begin_post_paging_lro_with_body(client):
211+
poller = await client.lro_paging.begin_post_paging_lro_with_body(
212+
resource_group_name=RESOURCE_GROUP_NAME,
213+
product_name="default",
214+
body=models.VnetProfile(vnet_id="vnet1"),
215+
)
216+
result = await poller.result()
217+
items = [item async for item in result]
218+
assert len(items) == 2
219+
assert items[0].name == "product1"
220+
assert items[0].properties.product_id == "product1"
221+
assert items[0].properties.provisioning_state == "Succeeded"
222+
assert items[1].name == "product2"
223+
assert items[1].properties.product_id == "product2"
224+
assert items[1].properties.provisioning_state == "Succeeded"
225+
226+
227+
@pytest.mark.asyncio
228+
async def test_lro_begin_get_lro(client):
229+
poller = await client.lro.begin_get_lro(
230+
scope=f"subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}",
231+
operation_id="report1",
232+
)
233+
result = await poller.result()
234+
assert result.name == "report1"
235+
assert result.properties.download_url == "https://storage.blob.core.windows.net/reports/report1.csv"
236+
assert result.properties.provisioning_state == "Succeeded"
237+
238+
239+
@pytest.mark.asyncio
240+
async def test_paging_post_action_paging(client):
241+
result = client.paging.post_action_paging(
242+
resource_group_name=RESOURCE_GROUP_NAME,
243+
monitor_name="monitor1",
244+
body=models.LogStatusRequest(filter="status eq 'active'"),
245+
)
246+
items = [item async for item in result]
247+
assert items[0].id.endswith("/Microsoft.Compute/virtualMachines/vm1")
248+
assert items[0].sending_metrics == True
249+
250+
251+
@pytest.mark.asyncio
252+
async def test_paging_mark_as_pageable(client):
253+
result = client.paging.mark_as_pageable(
254+
resource_group_name=RESOURCE_GROUP_NAME,
255+
monitor_name="monitor1",
256+
)
257+
items = [item async for item in result]
258+
assert len(items) == 2
259+
assert items[0].name == "collection1"
260+
assert items[0].properties.display_name == "Test Collection"
261+
assert items[1].name == "collection2"
262+
assert items[1].properties.display_name == "Another Collection"
263+
264+
265+
@pytest.mark.asyncio
266+
async def test_legacy_routed_get(client):
267+
result = await client.legacy.routed_get(
268+
resource_group_name=RESOURCE_GROUP_NAME,
269+
name="default",
270+
diagnostic_name="memory",
271+
)
272+
assert result.name == "memory"
273+
assert result.status == "healthy"
274+
275+
276+
@pytest.mark.asyncio
277+
async def test_legacy_create_or_replace_optional_body_with_body(client):
278+
result = await client.legacy.create_or_replace_optional_body(
279+
resource_group_name=RESOURCE_GROUP_NAME,
280+
configuration_name="default",
281+
resource=models.Configuration(
282+
location="eastus",
283+
properties=models.ConfigurationProperties(config_value="custom-value"),
284+
),
285+
)
286+
assert result.name == "default"
287+
assert result.properties.config_value == "custom-value"
288+
assert result.properties.provisioning_state == "Succeeded"
289+
290+
291+
@pytest.mark.asyncio
292+
async def test_legacy_create_or_replace_optional_body_without_body(client):
293+
result = await client.legacy.create_or_replace_optional_body(
294+
resource_group_name=RESOURCE_GROUP_NAME,
295+
configuration_name="default",
296+
)
297+
assert result.name == "default"
298+
assert result.properties.config_value == "default-value"
299+
assert result.properties.provisioning_state == "Succeeded"

packages/http-client-python/tests/mock_api/azure/test_azure_arm_operationtemplates.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,87 @@ def test_lro_paging_begin_post_paging_lro(client):
178178
assert items[1].name == "product2"
179179
assert items[1].properties.product_id == "product2"
180180
assert items[1].properties.provisioning_state == "Succeeded"
181+
182+
183+
def test_lro_paging_begin_post_paging_lro_with_body(client):
184+
result = client.lro_paging.begin_post_paging_lro_with_body(
185+
resource_group_name=RESOURCE_GROUP_NAME,
186+
product_name="default",
187+
body=models.VnetProfile(vnet_id="vnet1"),
188+
).result()
189+
items = list(result)
190+
assert len(items) == 2
191+
assert items[0].name == "product1"
192+
assert items[0].properties.product_id == "product1"
193+
assert items[0].properties.provisioning_state == "Succeeded"
194+
assert items[1].name == "product2"
195+
assert items[1].properties.product_id == "product2"
196+
assert items[1].properties.provisioning_state == "Succeeded"
197+
198+
199+
def test_lro_begin_get_lro(client):
200+
result = client.lro.begin_get_lro(
201+
scope=f"subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}",
202+
operation_id="report1",
203+
).result()
204+
assert result.name == "report1"
205+
assert result.properties.download_url == "https://storage.blob.core.windows.net/reports/report1.csv"
206+
assert result.properties.provisioning_state == "Succeeded"
207+
208+
209+
def test_paging_post_action_paging(client):
210+
result = client.paging.post_action_paging(
211+
resource_group_name=RESOURCE_GROUP_NAME,
212+
monitor_name="monitor1",
213+
body=models.LogStatusRequest(filter="status eq 'active'"),
214+
)
215+
items = list(result)
216+
assert items[0].id.endswith("/Microsoft.Compute/virtualMachines/vm1")
217+
assert items[0].sending_metrics == True
218+
219+
220+
def test_paging_mark_as_pageable(client):
221+
result = client.paging.mark_as_pageable(
222+
resource_group_name=RESOURCE_GROUP_NAME,
223+
monitor_name="monitor1",
224+
)
225+
items = list(result)
226+
assert len(items) == 2
227+
assert items[0].name == "collection1"
228+
assert items[0].properties.display_name == "Test Collection"
229+
assert items[1].name == "collection2"
230+
assert items[1].properties.display_name == "Another Collection"
231+
232+
233+
def test_legacy_routed_get(client):
234+
result = client.legacy.routed_get(
235+
resource_group_name=RESOURCE_GROUP_NAME,
236+
name="default",
237+
diagnostic_name="memory",
238+
)
239+
assert result.name == "memory"
240+
assert result.status == "healthy"
241+
242+
243+
def test_legacy_create_or_replace_optional_body_with_body(client):
244+
result = client.legacy.create_or_replace_optional_body(
245+
resource_group_name=RESOURCE_GROUP_NAME,
246+
configuration_name="default",
247+
resource=models.Configuration(
248+
location="eastus",
249+
properties=models.ConfigurationProperties(config_value="custom-value"),
250+
),
251+
)
252+
assert result.name == "default"
253+
assert result.properties.config_value == "custom-value"
254+
assert result.properties.provisioning_state == "Succeeded"
255+
256+
257+
def test_legacy_create_or_replace_optional_body_without_body(client):
258+
result = client.legacy.create_or_replace_optional_body(
259+
resource_group_name=RESOURCE_GROUP_NAME,
260+
configuration_name="default",
261+
)
262+
assert result.name == "default"
263+
assert result.properties.config_value == "default-value"
264+
assert result.properties.provisioning_state == "Succeeded"

0 commit comments

Comments
 (0)