Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Kulas committed Sep 20, 2023
1 parent cc97704 commit 4bbf38f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions odd_collector_sdk/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def extract_metadata(
raise TypeError(f"Metadata must be a dict, got {type(data)}")

if jsonify:
encode = partial(to_json, encoder=json_encoder)
encode = partial(parse_complex_types, encoder=json_encoder)
data = walk_values(encode, data)

if flatten:
Expand All @@ -67,7 +67,7 @@ def is_none(value) -> bool:
return value is None


def to_json(value, encoder: Optional[Type[json.JSONEncoder]]) -> Optional[str]:
def parse_complex_types(value, encoder: Optional[Type[json.JSONEncoder]]) -> Optional[str]:
if isinstance(value, (str, int, float, bool, type(None))):
return value # Return primitives as-is
try:
Expand Down
7 changes: 4 additions & 3 deletions tests/utils/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def partial_extract_metadata():
"nested_field_one": 1,
"nested_field_two": "string",
"nested_field_three": [{"foo": "bat"}, {"foo": {}}],
"nested_field_four": {"more_nested_field": 1, "more_nested_field_two": {}},
"nested_field_four": {"more_nested_field": 1, "more_nested_field_two": {}, "more_nested_field_three": "string"},
"nested_field_five": {},
},
}
Expand All @@ -36,11 +36,12 @@ def partial_extract_metadata():
"nested_meta.nested_field_three": [{"foo": "bat"}, {"foo": {}}],
"nested_meta.nested_field_four.more_nested_field": 1,
"nested_meta.nested_field_four.more_nested_field_two": {},
"nested_meta.nested_field_four.more_nested_field_three": "string",
"nested_meta.nested_field_five": {},
}

ENCODED_METADATA = walk_values(json.dumps, COMPLEX_METADATA)
FLATTEN_ENCODED_METADATA = walk_values(json.dumps, FLATTEN)
ENCODED_METADATA = walk_values(lambda x: json.loads(json.dumps(x)), COMPLEX_METADATA)
FLATTEN_ENCODED_METADATA = walk_values(lambda x: json.loads(json.dumps(x)), FLATTEN)


class Entity:
Expand Down

0 comments on commit 4bbf38f

Please sign in to comment.