Skip to content

Commit b1855b9

Browse files
committed
test(metadater): add tests for filter edge cases (#170)
Add unit tests for filter_matching_output and filter_metadata. Test when output_field is not in matching object. Test multiple matches without output_field. Test handling of $schema field in output_json.
1 parent 22e75e5 commit b1855b9

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

tests/test_metadater.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,38 @@ def test_get_metadata_from_filter_metadata_wrong_two():
108108
assert (
109109
"No objects found with url=/docs/cms-getting-started-20" in test_result.output
110110
)
111+
112+
113+
@pytest.mark.local
114+
def test_filter_matching_output_without_output_field(capsys):
115+
"""Test filter_matching_output when output_field is not in object."""
116+
matching_objects = {"name_0": {"foo": "bar", "baz": "qux"}}
117+
output_json = [{"foo": "bar", "baz": "qux"}]
118+
filter_matching_output(matching_objects, "nonexistent", output_json)
119+
captured = capsys.readouterr()
120+
assert '"foo": "bar"' in captured.out
121+
assert '"baz": "qux"' in captured.out
122+
123+
124+
@pytest.mark.local
125+
def test_filter_matching_output_multiple_matches_without_output_field(capsys):
126+
"""Test filter_matching_output with multiple matches when output_field is not in object."""
127+
# Two different filter fields matching the same object at index 0
128+
matching_objects = {
129+
"field1_0": {"a": "1", "b": "2"},
130+
"field2_0": {"a": "1", "b": "2"},
131+
}
132+
output_json = [{"a": "1", "b": "2"}]
133+
filter_matching_output(matching_objects, "nonexistent", output_json)
134+
captured = capsys.readouterr()
135+
assert '"a": "1"' in captured.out
136+
assert '"b": "2"' in captured.out
137+
138+
139+
@pytest.mark.local
140+
def test_filter_metadata_schema_field():
141+
"""Test filter_metadata when output_json contains $schema."""
142+
output_json = ["$schema", {"name": "test"}]
143+
with pytest.raises(SystemExit) as exc_info:
144+
filter_metadata("name", ["name=test"], output_json)
145+
assert exc_info.value.code == 1

0 commit comments

Comments
 (0)