Skip to content

Commit 79ca62c

Browse files
Copilotmsyyc
andauthored
[python] Add body-or-no-content Spector coverage (#12153)
Add Python SDK coverage for operations whose successful response is either a model body (HTTP 200) or no content (HTTP 204). - **Coverage:** Shared sync and async tests for Azure and unbranded clients assert `BlobLayout(content="hello")` for 200 and `None` for 204. - **Response metadata:** Verify raw status codes and `x-ms-request-id` headers for both responses. - **Changelog:** Add an internal entry for the Python emitter. <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #12152 --------- 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 2a5cea6 commit 79ca62c

4 files changed

Lines changed: 75 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 sync and async Spector tests for responses with a model body or no content, including raw response status and headers.

‎cspell.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ words:
4040
- blib
4141
- blockful
4242
- blockless
43+
- bodyornocontent
4344
- buongiorno
4445
- cadl
4546
- cadleditor
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
import pytest_asyncio
8+
from response.bodyornocontent.aio import BodyOrNoContentClient
9+
from response.bodyornocontent.models import BlobLayout
10+
11+
12+
@pytest_asyncio.fixture
13+
async def client():
14+
async with BodyOrNoContentClient(endpoint="http://localhost:3000") as client:
15+
yield client
16+
17+
18+
@pytest.mark.asyncio
19+
async def test_get_body(client: BodyOrNoContentClient):
20+
result = await client.get_body()
21+
assert result == BlobLayout(content="hello")
22+
23+
response = await client.get_body(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
24+
assert response.status_code == 200
25+
assert response.headers["x-ms-request-id"] == "body-request"
26+
27+
28+
@pytest.mark.asyncio
29+
async def test_get_no_content(client: BodyOrNoContentClient):
30+
result = await client.get_no_content()
31+
assert result is None
32+
33+
response = await client.get_no_content(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
34+
assert response.status_code == 204
35+
assert response.headers["x-ms-request-id"] == "no-content-request"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 response.bodyornocontent import BodyOrNoContentClient
8+
from response.bodyornocontent.models import BlobLayout
9+
10+
11+
@pytest.fixture
12+
def client():
13+
with BodyOrNoContentClient(endpoint="http://localhost:3000") as client:
14+
yield client
15+
16+
17+
def test_get_body(client: BodyOrNoContentClient):
18+
result = client.get_body()
19+
assert result == BlobLayout(content="hello")
20+
21+
response = client.get_body(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
22+
assert response.status_code == 200
23+
assert response.headers["x-ms-request-id"] == "body-request"
24+
25+
26+
def test_get_no_content(client: BodyOrNoContentClient):
27+
result = client.get_no_content()
28+
assert result is None
29+
30+
response = client.get_no_content(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
31+
assert response.status_code == 204
32+
assert response.headers["x-ms-request-id"] == "no-content-request"

0 commit comments

Comments
 (0)