-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from datayoga-io/389-relationalwrite-incorrec…
…tly-handles-invalid-mapped-field `relational.write` incorrectly handles invalid mapped field #389
- Loading branch information
Showing
2 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import pytest | ||
from datayoga_core import write_utils | ||
from datayoga_core.result import Status | ||
|
||
|
@@ -32,3 +33,69 @@ def test_group_by_opcode_invalid_opcode(): | |
groups = write_utils.group_records_by_opcode(change_records, opcode_field="opcode") | ||
assert groups["r"] == change_records[0:1] | ||
assert groups["x"] == change_records[1:2] | ||
|
||
|
||
@pytest.mark.parametrize("record, source, expected", [ | ||
# Existing simple nested key | ||
( | ||
{"value": {"id": 123}}, | ||
"value.id", | ||
{"target": 123} | ||
), | ||
# Existing deeply nested key | ||
( | ||
{"user": {"profile": {"email": "[email protected]"}}}, | ||
"user.profile.email", | ||
{"target": "[email protected]"} | ||
), | ||
# Missing simple nested key | ||
( | ||
{"value": {"x": 2}}, | ||
"value.id", | ||
{"target": None} | ||
), | ||
# Missing deeply nested key | ||
( | ||
{"user": {"profile": {"name": "John"}}}, | ||
"user.profile.email", | ||
{"target": None} | ||
), | ||
# Partially nested key | ||
( | ||
{"user": {"profile": {"name": "John"}}}, | ||
"user.address.street", | ||
{"target": None} | ||
), | ||
# Mixed case with existing and non-existing keys | ||
( | ||
{"data": {"info": {"id": 123, "active": True}}}, | ||
"data.info.status", | ||
{"target": None} | ||
), | ||
# Empty nested structure | ||
( | ||
{"user": {}}, | ||
"user.profile", | ||
{"target": None} | ||
), | ||
# Null value in nested structure | ||
( | ||
{"user": {"profile": None}}, | ||
"user.profile.name", | ||
{"target": None} | ||
), | ||
# Boolean value | ||
( | ||
{"settings": {"active": True}}, | ||
"settings.active", | ||
{"target": True} | ||
) | ||
]) | ||
def test_map_record_nested_key(record, source, expected): | ||
"""Tests map_record function's handling of nested keys, including existing and missing scenarios.""" | ||
mapped = write_utils.map_record( | ||
record, | ||
keys=[{"target": source}] | ||
) | ||
|
||
assert mapped == expected, f"Failed for record {record} with source {source}" |