diff --git a/.chronus/changes/copilot-add-test-case-http-client-python-2026-0-15-4-53-44.md b/.chronus/changes/copilot-add-test-case-http-client-python-2026-0-15-4-53-44.md new file mode 100644 index 00000000000..6ea9b8d973e --- /dev/null +++ b/.chronus/changes/copilot-add-test-case-http-client-python-2026-0-15-4-53-44.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Add test case \ No newline at end of file diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py index bc7018ecb19..9f22c8c5d15 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/asynctests/test_special_words_async.py @@ -58,3 +58,8 @@ async def test_model_properties_dict_methods(client: SpecialWordsClient): copy_property="ok", ) ) + + +@pytest.mark.asyncio +async def test_model_properties_with_list(client: SpecialWordsClient): + await client.model_properties.with_list(models.ModelWithList(list="ok")) diff --git a/packages/http-client-python/generator/test/azure/mock_api_tests/test_special_words.py b/packages/http-client-python/generator/test/azure/mock_api_tests/test_special_words.py index 7672f9cd5d5..cc083c94c0e 100644 --- a/packages/http-client-python/generator/test/azure/mock_api_tests/test_special_words.py +++ b/packages/http-client-python/generator/test/azure/mock_api_tests/test_special_words.py @@ -52,3 +52,7 @@ def test_model_properties_dict_methods(client: SpecialWordsClient): copy_property="ok", ) ) + + +def test_model_properties_with_list(client: SpecialWordsClient): + client.model_properties.with_list(models.ModelWithList(list="ok")) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py index a5abf91c3dd..12e4cb2e5a2 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/asynctests/test_specs_documentation_async.py @@ -22,11 +22,10 @@ async def test_bullet_points_op(self, client: DocumentationClient): # Expected: 204 No Content await client.lists.bullet_points_op() - @pytest.mark.skip(reason="https://github.com/microsoft/typespec/issues/9173") @pytest.mark.asyncio async def test_bullet_points_model(self, client: DocumentationClient): # POST /documentation/lists/bullet-points/model - # Expected request body: {"prop": "Simple"} + # Expected request body: {"input": {"prop": "Simple"}} # Expected: 200 OK await client.lists.bullet_points_model(input=models.BulletPointsModel(prop="Simple")) diff --git a/packages/http-client-python/generator/test/generic_mock_api_tests/test_specs_documentation.py b/packages/http-client-python/generator/test/generic_mock_api_tests/test_specs_documentation.py index 7d7a8cfefa8..2f956dd75fd 100644 --- a/packages/http-client-python/generator/test/generic_mock_api_tests/test_specs_documentation.py +++ b/packages/http-client-python/generator/test/generic_mock_api_tests/test_specs_documentation.py @@ -20,7 +20,6 @@ def test_bullet_points_op(self, client: DocumentationClient): # Expected: 204 No Content client.lists.bullet_points_op() - @pytest.mark.skip(reason="https://github.com/microsoft/typespec/issues/9173") def test_bullet_points_model(self, client: DocumentationClient): # POST /documentation/lists/bullet-points/model # Expected: 200 OK diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py index c565a9ce546..eb11843ab32 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/asynctests/test_special_words_async.py @@ -41,3 +41,26 @@ async def test_model(client: SpecialWordsClient, special_words): @pytest.mark.asyncio async def test_model_properties(client: SpecialWordsClient): await client.model_properties.same_as_model(model_properties_models.SameAsModel(same_as_model="ok")) + + +@pytest.mark.asyncio +async def test_model_properties_dict_methods(client: SpecialWordsClient): + await client.model_properties.dict_methods( + body=model_properties_models.DictMethods( + keys_property="ok", + items_property="ok", + values_property="ok", + popitem_property="ok", + clear_property="ok", + update_property="ok", + setdefault_property="ok", + pop_property="ok", + get_property="ok", + copy_property="ok", + ) + ) + + +@pytest.mark.asyncio +async def test_model_properties_with_list(client: SpecialWordsClient): + await client.model_properties.with_list(model_properties_models.ModelWithList(list="ok")) diff --git a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_special_words.py b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_special_words.py index 6fb680e17e3..89679bfd788 100644 --- a/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_special_words.py +++ b/packages/http-client-python/generator/test/unbranded/mock_api_tests/test_special_words.py @@ -37,3 +37,24 @@ def test_model(client: SpecialWordsClient, special_words): def test_model_properties(client: SpecialWordsClient): client.model_properties.same_as_model(model_properties_models.SameAsModel(same_as_model="ok")) + + +def test_model_properties_dict_methods(client: SpecialWordsClient): + client.model_properties.dict_methods( + body=model_properties_models.DictMethods( + keys_property="ok", + items_property="ok", + values_property="ok", + popitem_property="ok", + clear_property="ok", + update_property="ok", + setdefault_property="ok", + pop_property="ok", + get_property="ok", + copy_property="ok", + ) + ) + + +def test_model_properties_with_list(client: SpecialWordsClient): + client.model_properties.with_list(model_properties_models.ModelWithList(list="ok")) diff --git a/packages/http-client-python/generator/test/unittests/test_model_base_serialization.py b/packages/http-client-python/generator/test/unittests/test_model_base_serialization.py index d9027bee195..8e37a85f177 100644 --- a/packages/http-client-python/generator/test/unittests/test_model_base_serialization.py +++ b/packages/http-client-python/generator/test/unittests/test_model_base_serialization.py @@ -64,6 +64,22 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) +class ModelWithArgsProperty(Model): + """A model that has a property named 'args' to test potential conflicts with *args.""" + + name: str = rest_field() + args: list[str] = rest_field() # property named 'args' which could conflict with *args + + @overload + def __init__(self, *, name: str, args: list[str]): ... + + @overload + def __init__(self, mapping: Mapping[str, Any], /): ... + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + class Pet(Model): name: str = rest_field() # my name species: str = rest_field() # my species @@ -106,6 +122,43 @@ def test_model_and_dict_equal(): assert model.virtual_machines == model["virtualMachines"] == dict_response["virtualMachines"] +def test_model_with_args_property(): + """Test that a model with a property named 'args' works correctly.""" + # Test initialization with keyword arguments + model = ModelWithArgsProperty(name="test", args=["arg1", "arg2", "arg3"]) + assert model.name == "test" + assert model.args == ["arg1", "arg2", "arg3"] + + # Test dict-style access + assert model["name"] == "test" + assert model["args"] == ["arg1", "arg2", "arg3"] + + # Test equality with dict + dict_response = {"name": "test", "args": ["arg1", "arg2", "arg3"]} + assert model == dict_response + + # Test initialization from dict (using positional argument which goes to *args) + model_from_dict = ModelWithArgsProperty(dict_response) + assert model_from_dict.name == "test" + assert model_from_dict.args == ["arg1", "arg2", "arg3"] + assert model_from_dict == model + + # Test modification of the 'args' property + model.args = ["new_arg"] + assert model.args == ["new_arg"] + assert model["args"] == ["new_arg"] + + # Test dict-style modification of 'args' + model["args"] = ["modified_arg1", "modified_arg2"] + assert model.args == ["modified_arg1", "modified_arg2"] + + # Test JSON serialization roundtrip + json_str = json.dumps(dict(model)) + parsed = json.loads(json_str) + assert parsed["name"] == "test" + assert parsed["args"] == ["modified_arg1", "modified_arg2"] + + def test_json_roundtrip(): dict_response = { "platformUpdateDomainCount": 5, diff --git a/packages/http-client-python/package-lock.json b/packages/http-client-python/package-lock.json index c804694c65e..1fc2eff24cb 100644 --- a/packages/http-client-python/package-lock.json +++ b/packages/http-client-python/package-lock.json @@ -29,7 +29,7 @@ "@typespec/compiler": "^1.8.0", "@typespec/events": "~0.78.0", "@typespec/http": "^1.8.0", - "@typespec/http-specs": "0.1.0-alpha.30", + "@typespec/http-specs": "0.1.0-alpha.31", "@typespec/openapi": "^1.8.0", "@typespec/rest": "~0.78.0", "@typespec/spec-api": "0.1.0-alpha.12", @@ -2318,9 +2318,9 @@ } }, "node_modules/@typespec/http-specs": { - "version": "0.1.0-alpha.30", - "resolved": "https://registry.npmjs.org/@typespec/http-specs/-/http-specs-0.1.0-alpha.30.tgz", - "integrity": "sha512-9c/npRHmX+IL4iAuXcDw5Jyy/exTu7IEp4i+JxYj43e+/g8gzFKFRMtJhcrH2xaABMFtrDW5oxXz0mh8PJaIjg==", + "version": "0.1.0-alpha.31", + "resolved": "https://registry.npmjs.org/@typespec/http-specs/-/http-specs-0.1.0-alpha.31.tgz", + "integrity": "sha512-ji+Zt4wB8NnVw3cFiE+LmkXCTfBWEq1xwBQrxJ83q28NQeKBMOVxynjiCz344gxOCcEfhAX4mwKcYeJUKAFVYQ==", "dev": true, "license": "MIT", "dependencies": { diff --git a/packages/http-client-python/package.json b/packages/http-client-python/package.json index 857195f588f..3a14ca246a4 100644 --- a/packages/http-client-python/package.json +++ b/packages/http-client-python/package.json @@ -94,7 +94,7 @@ "@typespec/sse": "~0.78.0", "@typespec/streams": "~0.78.0", "@typespec/xml": "~0.78.0", - "@typespec/http-specs": "0.1.0-alpha.30", + "@typespec/http-specs": "0.1.0-alpha.31", "@types/js-yaml": "~4.0.5", "@types/node": "~24.1.0", "@types/semver": "7.5.8",