⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
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 test case
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 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 @@ -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",
Expand Down
Loading