Skip to content
Merged
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 Spector tests for responses with a model body or no content, including raw response status and headers.
1 change: 1 addition & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ words:
- blib
- blockful
- blockless
- bodyornocontent
- buongiorno
- cadl
- cadleditor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -------------------------------------------------------------------------
# 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 response.bodyornocontent.aio import BodyOrNoContentClient
from response.bodyornocontent.models import BlobLayout


@pytest_asyncio.fixture
async def client():
async with BodyOrNoContentClient(endpoint="http://localhost:3000") as client:
yield client


@pytest.mark.asyncio
async def test_get_body(client: BodyOrNoContentClient):
result = await client.get_body()
assert result == BlobLayout(content="hello")

response = await client.get_body(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
assert response.status_code == 200
assert response.headers["x-ms-request-id"] == "body-request"


@pytest.mark.asyncio
async def test_get_no_content(client: BodyOrNoContentClient):
result = await client.get_no_content()
assert result is None

response = await client.get_no_content(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
assert response.status_code == 204
assert response.headers["x-ms-request-id"] == "no-content-request"
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -------------------------------------------------------------------------
# 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 response.bodyornocontent import BodyOrNoContentClient
from response.bodyornocontent.models import BlobLayout


@pytest.fixture
def client():
with BodyOrNoContentClient(endpoint="http://localhost:3000") as client:
yield client


def test_get_body(client: BodyOrNoContentClient):
result = client.get_body()
assert result == BlobLayout(content="hello")

response = client.get_body(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
assert response.status_code == 200
assert response.headers["x-ms-request-id"] == "body-request"


def test_get_no_content(client: BodyOrNoContentClient):
result = client.get_no_content()
assert result is None

response = client.get_no_content(cls=lambda pipeline_response, _, __: pipeline_response.http_response)
assert response.status_code == 204
assert response.headers["x-ms-request-id"] == "no-content-request"
Loading