Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #265 from microsoft/shem/fix_enum_serialization_py…
Browse files Browse the repository at this point in the history
…thon

Fix Enum serialization Python
  • Loading branch information
shemogumbe authored Apr 11, 2024
2 parents 1ccbb0a + 51caeaa commit 738ee46
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] - 2024-04-09

### Added

### Changed
- Enhanced error handling: Enabled silent failure when an enum key is not available

## [1.1.0] - 2024-02-29

### Added
Expand Down
2 changes: 1 addition & 1 deletion kiota_serialization_json/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION: str = '1.1.0'
VERSION: str = '1.2.0'
2 changes: 1 addition & 1 deletion kiota_serialization_json/json_parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def get_enum_value(self, enum_class: K) -> Optional[K]:
try:
return enum_class[camel_case_key] # type: ignore
except KeyError:
raise Exception(f'Invalid key: {camel_case_key} for enum {enum_class}.')
return None

def get_object_value(self, factory: ParsableFactory) -> U:
"""Gets the model object value of the node
Expand Down
27 changes: 19 additions & 8 deletions tests/unit/test_json_parse_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def test_get_enum_value():
assert result == OfficeLocation.Dunhill


def test_get_enum_value_for_key_not_found():
parse_node = JsonParseNode("whitehouse")
result = parse_node.get_enum_value(OfficeLocation)
assert result is None


def test_get_object_value(user1_json):
parse_node = JsonParseNode(json.loads(user1_json))
result = parse_node.get_object_value(User)
Expand All @@ -110,18 +116,23 @@ def test_get_object_value(user1_json):
assert result.business_phones == ["+1 205 555 0108"]
assert result.is_active is True
assert result.mobile_phone is None
assert result.additional_data["additional_data"]["@odata.context"] == "https://graph.microsoft.com/v1.0/$metadata#users/$entity"
assert result.additional_data["additional_data"][
"@odata.context"] == "https://graph.microsoft.com/v1.0/$metadata#users/$entity"
assert result.additional_data["additional_data"]["manager"] == {
"id": UUID('8f841f30-e6e3-439a-a812-ebd369559c36'),
"updated_at": DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")),
"is_active": True}
"updated_at":
DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")),
"is_active": True
}
assert result.additional_data["additional_data"]["approvers"] == [
{
"id": UUID('8f841f30-e6e3-439a-a812-ebd369559c36'),
"updated_at": DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")),
"is_active": True
},
{
"id":
UUID('8f841f30-e6e3-439a-a812-ebd369559c36'),
"updated_at":
DateTime(2022, 1, 27, 12, 59, 45, 596117, tzinfo=FixedTimezone(0, name="+00:00")),
"is_active":
True
}, {
"display_name": "John Doe",
"age": 32
}
Expand Down

0 comments on commit 738ee46

Please sign in to comment.