diff --git a/.chronus/changes/python-flatten-property-tests-2026-3-2-7-34-49.md b/.chronus/changes/python-flatten-property-tests-2026-3-2-7-34-49.md new file mode 100644 index 00000000000..7e184e0e2dd --- /dev/null +++ b/.chronus/changes/python-flatten-property-tests-2026-3-2-7-34-49.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add test cases for flatten property with unknown type and read-only properties scenarios. diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py index fe2f64f13db..b0c6c4786df 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_azure_client_generator_core_flatten_async.py @@ -6,10 +6,12 @@ import pytest from specs.azure.clientgenerator.core.flattenproperty.aio import FlattenPropertyClient from specs.azure.clientgenerator.core.flattenproperty.models import ( - FlattenModel, + ChildFlattenModel, ChildModel, + FlattenModel, + FlattenUnknownModel, NestedFlattenModel, - ChildFlattenModel, + Solution, ) @@ -46,6 +48,22 @@ async def test_put_nested_flatten_model(client: FlattenPropertyClient): ) +@pytest.mark.asyncio +async def test_put_flatten_unknown_model(client: FlattenPropertyClient): + result = await client.put_flatten_unknown_model(FlattenUnknownModel(name="foo")) + assert result.name == "test" + assert result.properties == {"key1": "value1", "key2": "value2"} + + +@pytest.mark.asyncio +async def test_put_flatten_read_only_model(client: FlattenPropertyClient): + result = await client.put_flatten_read_only_model(Solution({"name": "foo"})) + assert result.name == "foo" + assert result["solutionId"] == "solution1" + assert result["title"] == "Solution Title" + assert result["content"] == "Solution Content" + + @pytest.mark.asyncio # ============test for compatibility ============ async def test_dpg_model_common(): flatten_model = FlattenModel(name="hello", properties=ChildModel(age=0, description="test")) diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py index b1492f524ad..e90308509a2 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_azure_client_generator_core_flatten.py @@ -6,10 +6,12 @@ import pytest from specs.azure.clientgenerator.core.flattenproperty import FlattenPropertyClient from specs.azure.clientgenerator.core.flattenproperty.models import ( - FlattenModel, + ChildFlattenModel, ChildModel, + FlattenModel, + FlattenUnknownModel, NestedFlattenModel, - ChildFlattenModel, + Solution, ) @@ -41,6 +43,20 @@ def test_put_nested_flatten_model(client: FlattenPropertyClient): ) +def test_put_flatten_unknown_model(client: FlattenPropertyClient): + result = client.put_flatten_unknown_model(FlattenUnknownModel(name="foo")) + assert result.name == "test" + assert result.properties == {"key1": "value1", "key2": "value2"} + + +def test_put_flatten_read_only_model(client: FlattenPropertyClient): + result = client.put_flatten_read_only_model(Solution({"name": "foo"})) + assert result.name == "foo" + assert result["solutionId"] == "solution1" + assert result["title"] == "Solution Title" + assert result["content"] == "Solution Content" + + # ============test for compatibility ============ def test_dpg_model_common(): flatten_model = FlattenModel(name="hello", properties=ChildModel(age=0, description="test")) diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 8035b620851..e8b8362d954 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -17,7 +17,7 @@ "tsx": "^4.21.0" }, "devDependencies": { - "@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.2", + "@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.4", "@azure-tools/typespec-autorest": "~0.65.0", "@azure-tools/typespec-azure-core": "~0.65.0", "@azure-tools/typespec-azure-resource-manager": "~0.65.0", @@ -66,9 +66,9 @@ } }, "node_modules/@azure-tools/azure-http-specs": { - "version": "0.1.0-alpha.38-dev.2", - "resolved": "https://registry.npmjs.org/@azure-tools/azure-http-specs/-/azure-http-specs-0.1.0-alpha.38-dev.2.tgz", - "integrity": "sha512-rrxSHv70c5d9ZZQRN1xZ849/vzAFM7uHEkpjSNtKBBkx/6/2J2arSiltk4OP6xE/lqHPVPeANzbYQsL4b4wNZw==", + "version": "0.1.0-alpha.38-dev.4", + "resolved": "https://registry.npmjs.org/@azure-tools/azure-http-specs/-/azure-http-specs-0.1.0-alpha.38-dev.4.tgz", + "integrity": "sha512-RcMWlJoH/ZfFXR4X/nZ/L6siNDtYylYERikcF23JbJ1/SrYsFIS3IpdG4E1YlEMwwfgolL31CDM32+d6g+AViQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 39b23f709d7..7b85c019adb 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -82,7 +82,7 @@ "@azure-tools/typespec-azure-resource-manager": "~0.65.0", "@azure-tools/typespec-azure-rulesets": "~0.65.0", "@azure-tools/typespec-client-generator-core": "~0.65.3", - "@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.2", + "@azure-tools/azure-http-specs": "0.1.0-alpha.38-dev.4", "@typespec/compiler": "^1.9.0", "@typespec/http": "^1.9.0", "@typespec/openapi": "^1.9.0",