-
Notifications
You must be signed in to change notification settings - Fork 0
MPT-15233 Fix for snake-case to camel-case conversion #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d13d35c
b1cb96d
d2cfacc
c0f6b5f
002dfcf
af25f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| from typing import ClassVar | ||
|
|
||
| import pytest | ||
| from httpx import Response | ||
|
|
||
|
|
@@ -70,3 +72,60 @@ def test_id_property_with_numeric_id(): | |
|
|
||
| assert resource.id == "1024" | ||
| assert isinstance(resource.id, str) | ||
|
|
||
|
|
||
| def test_case_conversion(): | ||
| resource_data = {"id": "abc-123", "FullName": "Alice Smith"} | ||
|
|
||
| resource = Model(resource_data) | ||
|
|
||
| assert resource.full_name == "Alice Smith" | ||
| assert resource.to_dict() == resource_data | ||
| with pytest.raises(AttributeError): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly speaking I would split it to two functions, just because you are checking here different things --> key-access and |
||
| _ = resource.FullName # noqa: WPS122 | ||
|
|
||
|
|
||
| def test_deep_case_conversion(): | ||
| resource_data = {"id": "ABC-123", "contact": {"id": "ABC-345", "FullName": "Alice Smith"}} | ||
| expected_resource_data = { | ||
| "id": "ABC-123", | ||
| "contact": {"id": "ABC-345", "FullName": "Alice Smith", "StreetAddress": "123 Main St"}, | ||
| } | ||
|
|
||
| resource = Model(resource_data) | ||
| resource.contact.StreetAddress = "123 Main St" | ||
|
|
||
| assert resource.contact.full_name == "Alice Smith" | ||
| assert resource.contact.street_address == "123 Main St" | ||
| assert resource.to_dict() == expected_resource_data | ||
|
|
||
| with pytest.raises(AttributeError): | ||
| _ = resource.contact.FullName # noqa: WPS122 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need this ignore now :-) |
||
|
|
||
| with pytest.raises(AttributeError): | ||
| _ = resource.contact.StreetAddress # noqa: WPS122 | ||
|
|
||
|
|
||
| def test_repr(): | ||
| resource_data = {"id": "abc-123", "FullName": "Alice Smith"} | ||
|
|
||
| resource = Model(resource_data) | ||
|
|
||
| assert repr(resource) == "<Model abc-123>" | ||
| assert str(resource) == "<Model abc-123>" | ||
|
|
||
|
|
||
| def test_mapping(): | ||
| class MappingModel(Model): # noqa: WPS431 | ||
| _attribute_mapping: ClassVar[dict[str, str]] = { | ||
| "second_id": "resource_id", | ||
| "Full_Name": "name", | ||
| } | ||
|
|
||
| resource_data = {"id": "abc-123", "second_id": "resource-abc-123", "Full_Name": "Alice Smith"} | ||
|
|
||
| resource = MappingModel(resource_data) | ||
|
|
||
| assert resource.name == "Alice Smith" | ||
| assert resource.resource_id == "resource-abc-123" | ||
| assert resource.to_dict() == resource_data | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also describe here that the
key_mappingkeyword is reserved for now