Skip to content
Draft
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 mock API test cases for `@responseAsBool` and `@clientDoc` decorators (from Azure/typespec-azure#4268). Fix code generation for `@responseAsBool` HEAD operations to return boolean values directly without attempting JSON body deserialization.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
DPGModelType,
ParameterListType,
ByteArraySchema,
ConstantType,
)
from ..models.utils import NamespaceType
from .parameter_serializer import ParameterSerializer, PopKwargType, check_body_optional
Expand Down Expand Up @@ -1000,6 +1001,8 @@ def response_deserialization( # pylint: disable=too-many-statements
elif self.code_model.options["models-mode"] == "dpg":
if builder.has_stream_response:
deserialize_code.append("deserialized = response.content")
elif isinstance(response.type, ConstantType) and response.type._is_literal:
deserialize_code.append(f"deserialized = {response.type.get_declaration()}")
else:
format_filed = (
f', format="{response.type.encode}"'
Expand Down
22 changes: 11 additions & 11 deletions packages/http-client-python/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/http-client-python/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"@azure-tools/typespec-azure-resource-manager": "~0.67.0",
"@azure-tools/typespec-azure-rulesets": "~0.67.0",
"@azure-tools/typespec-client-generator-core": "~0.67.0",
"@azure-tools/azure-http-specs": "0.1.0-alpha.39",
"@azure-tools/azure-http-specs": "0.1.0-alpha.40-dev.5",
"@typespec/compiler": "^1.11.0",
"@typespec/http": "^1.11.0",
"@typespec/openapi": "^1.11.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.clientdoc.aio import ClientDocClient
from specs.azure.clientgenerator.core.clientdoc.documentation import models


@pytest_asyncio.fixture
async def client():
async with ClientDocClient() as client:
yield client


@pytest.mark.asyncio
async def test_harvest(client: ClientDocClient):
plant = models.Plant(name="Rose", species="Rosa")
result = await client.documentation.harvest(plant)
assert result == models.Plant(name="Rose", species="Rosa")
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.responseasbool.aio import ResponseAsBoolClient


@pytest_asyncio.fixture
async def client():
async with ResponseAsBoolClient() as client:
yield client


@pytest.mark.asyncio
async def test_exists(client: ResponseAsBoolClient):
result = await client.head_as_boolean.exists()
assert result is True


@pytest.mark.asyncio
async def test_not_exists(client: ResponseAsBoolClient):
result = await client.head_as_boolean.not_exists()
assert result is False
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.clientdoc import ClientDocClient
from specs.azure.clientgenerator.core.clientdoc.documentation import models


@pytest.fixture
def client():
with ClientDocClient() as client:
yield client


def test_harvest(client: ClientDocClient):
plant = models.Plant(name="Rose", species="Rosa")
result = client.documentation.harvest(plant)
assert result == models.Plant(name="Rose", species="Rosa")
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -------------------------------------------------------------------------
# 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 specs.azure.clientgenerator.core.responseasbool import ResponseAsBoolClient


@pytest.fixture
def client():
with ResponseAsBoolClient() as client:
yield client


def test_exists(client: ResponseAsBoolClient):
result = client.head_as_boolean.exists()
assert result is True


def test_not_exists(client: ResponseAsBoolClient):
result = client.head_as_boolean.not_exists()
assert result is False
Loading