diff --git a/.chronus/changes/add-flatten-read-only-model-tests-2026-3-6-8-0-10.md b/.chronus/changes/add-flatten-read-only-model-tests-2026-3-6-8-0-10.md new file mode 100644 index 00000000000..e4bbcfb6773 --- /dev/null +++ b/.chronus/changes/add-flatten-read-only-model-tests-2026-3-6-8-0-10.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add test cases for flatten property with read-only properties (putFlattenReadOnlyModel and putFlattenUnknownModel 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..cb044b430fe 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,13 @@ 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, + SolutionProperties, ) @@ -46,6 +49,25 @@ 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 == Solution( + name="foo", + properties=SolutionProperties(solution_id="solution1", title="Solution Title", content="Solution Content"), + ) + assert result.solution_id == "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..30745aae253 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,13 @@ 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, + SolutionProperties, ) @@ -41,6 +44,23 @@ 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 == Solution( + name="foo", + properties=SolutionProperties(solution_id="solution1", title="Solution Title", content="Solution Content"), + ) + assert result.solution_id == "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/generator/test/unittests/test_name_converter.py b/packages/http-client-python/generator/test/unittests/test_name_converter.py index 4bfbee891b6..88a10a20409 100644 --- a/packages/http-client-python/generator/test/unittests/test_name_converter.py +++ b/packages/http-client-python/generator/test/unittests/test_name_converter.py @@ -33,4 +33,3 @@ def test_escaped_reserved_words(): } for name in expected_conversion_parameter: assert pad_reserved_words(name, pad_type=PadType.PARAMETER) == expected_conversion_parameter[name] - diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index 8035b620851..f4a84d1c7c6 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.6", "@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.6", + "resolved": "https://registry.npmjs.org/@azure-tools/azure-http-specs/-/azure-http-specs-0.1.0-alpha.38-dev.6.tgz", + "integrity": "sha512-MXjnMSArEM1+ADCmSrYDsOlTzL9bQWaVMtrTtOK8+2eAL87dZdfxiFuiPr9jWHYC8m8nIwLZ+h4dE7TSQR0KwQ==", "dev": true, "license": "MIT", "dependencies": { @@ -81,7 +81,7 @@ "peerDependencies": { "@azure-tools/typespec-azure-core": "^0.65.0 || >=0.66.0-dev <0.66.0", "@typespec/compiler": "^1.9.0", - "@typespec/http": "^1.9.0", + "@typespec/http": "^1.9.1", "@typespec/rest": "^0.79.0 || >=0.80.0-dev <0.80.0", "@typespec/versioning": "^0.79.0 || >=0.80.0-dev <0.80.0", "@typespec/xml": "^0.79.0 || >=0.80.0-dev <0.80.0" @@ -2473,9 +2473,9 @@ } }, "node_modules/@typespec/http": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@typespec/http/-/http-1.9.0.tgz", - "integrity": "sha512-JzlZZsgCo71f2KhWbf4BLOz5e+dVLj7gJJ4kvXvrmuG9QHoT41VaGPpCQamYgpZLMz2LQbsOtw34AmpovhuJSw==", + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/@typespec/http/-/http-1.9.1.tgz", + "integrity": "sha512-agcwmbB/hK/o9KmM38UB8OGZwLgB17lJ7b4EjqYGpyshqcRMTESMRxnJIH7rRzUq4HJDTqal0tsb8z0K0zXuDg==", "dev": true, "license": "MIT", "engines": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 39b23f709d7..2752851f089 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.6", "@typespec/compiler": "^1.9.0", "@typespec/http": "^1.9.0", "@typespec/openapi": "^1.9.0",