Skip to content

Commit 45053d0

Browse files
committed
update test
1 parent 7a60ce9 commit 45053d0

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

stac_fastapi/tests/extensions/test_filter.py

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -678,38 +678,52 @@ async def test_queryables_enum_platform(
678678

679679
@pytest.mark.asyncio
680680
async def test_search_filter_ext_or_with_must_condition(app_client, ctx):
681-
"""Test that OR conditions work correctly when combined with MUST conditions."""
682-
# This test verifies that when combining MUST and SHOULD clauses,
683-
# we still require at least one SHOULD condition to match
681+
"""
682+
Test that OR conditions require at least one match when combined with MUST.
683+
This test will fail if minimum_should_match=1 is not set in the ES query.
684+
"""
685+
# Case 1: At least one OR condition matches (should return the item)
684686
params = {
685687
"filter": {
686688
"op": "and",
687689
"args": [
688-
# MUST condition (matches all test items)
689-
{"op": ">=", "args": [{"property": "eo:cloud_cover"}, 0]},
690-
# OR condition (only some items match)
690+
{
691+
"op": ">=",
692+
"args": [{"property": "eo:cloud_cover"}, 0],
693+
}, # True for test item (cloud_cover=0)
691694
{
692695
"op": "or",
693696
"args": [
694-
{"op": "<", "args": [{"property": "eo:cloud_cover"}, 10]},
697+
{
698+
"op": "<",
699+
"args": [{"property": "eo:cloud_cover"}, 1],
700+
}, # True for test item (cloud_cover=0)
695701
{
696702
"op": "=",
697703
"args": [{"property": "properties.proj:epsg"}, 99999],
698-
},
704+
}, # False
699705
],
700706
},
701707
],
702708
}
703709
}
704-
705-
# Test the API
706710
resp = await app_client.post("/search", json=params)
707711
assert resp.status_code == 200
708712
resp_json = resp.json()
709-
710-
# Should only find items where cloud_cover < 10 (second condition is false for all)
711-
for feature in resp_json["features"]:
712-
props = feature.get("properties", {})
713-
assert (
714-
props.get("eo:cloud_cover", 100) < 10
715-
), "Items should only be returned if they match at least one OR condition"
713+
assert any(
714+
f["properties"].get("eo:cloud_cover") == 0 for f in resp_json["features"]
715+
), "Should return the test item when at least one OR condition matches"
716+
717+
# Case 2: No OR conditions match (should NOT return the item if minimum_should_match=1 is set)
718+
params["filter"]["args"][1]["args"][0]["args"][
719+
1
720+
] = -1 # Now: cloud_cover < -1 (False)
721+
params["filter"]["args"][1]["args"][1]["args"][
722+
1
723+
] = 99998 # Now: proj:epsg == 99998 (False)
724+
resp = await app_client.post("/search", json=params)
725+
assert resp.status_code == 200
726+
resp_json = resp.json()
727+
assert all(
728+
f["properties"].get("eo:cloud_cover") != 0 for f in resp_json["features"]
729+
), "Should NOT return the test item when no OR conditions match (requires minimum_should_match=1)"

0 commit comments

Comments
 (0)