diff --git a/.chronus/changes/python-conditional-request-tests-2026-5-25-6-40-0.md b/.chronus/changes/python-conditional-request-tests-2026-5-25-6-40-0.md new file mode 100644 index 00000000000..5efa585d91c --- /dev/null +++ b/.chronus/changes/python-conditional-request-tests-2026-5-25-6-40-0.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add mock API tests for `Azure.SpecialHeaders.ConditionalRequest` (eTag with standard and non-standard wire names). diff --git a/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_special_headers_conditional_request_async.py b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_special_headers_conditional_request_async.py new file mode 100644 index 00000000000..264cc71cdb3 --- /dev/null +++ b/packages/http-client-python/tests/mock_api/azure/asynctests/test_azure_special_headers_conditional_request_async.py @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------- +# 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 azure.core import MatchConditions +from azure.specialheaders.conditionalrequest.aio import ConditionalRequestClient + + +@pytest_asyncio.fixture +async def client(): + async with ConditionalRequestClient() as client: + yield client + + +@pytest.mark.asyncio +async def test_post_if_match(client: ConditionalRequestClient): + await client.post_if_match(etag="valid", match_condition=MatchConditions.IfNotModified) + + +@pytest.mark.asyncio +async def test_post_if_none_match(client: ConditionalRequestClient): + await client.post_if_none_match(etag="invalid", match_condition=MatchConditions.IfModified) + + +@pytest.mark.asyncio +async def test_post_custom_if_match(client: ConditionalRequestClient): + await client.post_custom_if_match(etag="valid", match_condition=MatchConditions.IfNotModified) + + +@pytest.mark.asyncio +async def test_post_custom_if_none_match(client: ConditionalRequestClient): + await client.post_custom_if_none_match(etag="invalid", match_condition=MatchConditions.IfModified) diff --git a/packages/http-client-python/tests/mock_api/azure/test_azure_special_headers_conditional_request.py b/packages/http-client-python/tests/mock_api/azure/test_azure_special_headers_conditional_request.py new file mode 100644 index 00000000000..dacd7ba07f0 --- /dev/null +++ b/packages/http-client-python/tests/mock_api/azure/test_azure_special_headers_conditional_request.py @@ -0,0 +1,31 @@ +# ------------------------------------------------------------------------- +# 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 azure.core import MatchConditions +from azure.specialheaders.conditionalrequest import ConditionalRequestClient + + +@pytest.fixture +def client(): + with ConditionalRequestClient() as client: + yield client + + +def test_post_if_match(client: ConditionalRequestClient): + client.post_if_match(etag="valid", match_condition=MatchConditions.IfNotModified) + + +def test_post_if_none_match(client: ConditionalRequestClient): + client.post_if_none_match(etag="invalid", match_condition=MatchConditions.IfModified) + + +def test_post_custom_if_match(client: ConditionalRequestClient): + client.post_custom_if_match(etag="valid", match_condition=MatchConditions.IfNotModified) + + +def test_post_custom_if_none_match(client: ConditionalRequestClient): + client.post_custom_if_none_match(etag="invalid", match_condition=MatchConditions.IfModified)