55
66import cql2
77import pytest
8- from httpx import Request
98from fastapi .testclient import TestClient
9+ from httpx import Request
1010from utils import AppFactory
1111
12- from fixtures .demo_searches import SEARCHES
13-
1412app_factory = AppFactory (
1513 oidc_discovery_url = "https://example-stac-api.com/.well-known/openid-configuration" ,
1614 default_public = False ,
198196 "true" ,
199197 """{"op": "=", "args": [{"property": "private"}, true]}""" ,
200198 ],
201- # Not sure what is demonstrated in this...
202- # [
203- # """{
204- # "op": "and",
205- # "args": [
206- # { "op": "=", "args": [{ "property": "id" }, "LC08_L1TP_060247_20180905_20180912_01_T1_L1TP" ] },
207- # { "op": "=", "args": [{ "property": "collection" }, "landsat8_l1tp"] }
208- # ]
209- # }"""
210- # ]
211- # * 3,
212199 ],
213200)
214201@pytest .mark .parametrize ("is_authenticated" , [True , False ])
215- @pytest .mark .parametrize ("input_query" , SEARCHES )
202+ @pytest .mark .parametrize (
203+ "input_query" ,
204+ [
205+ # Not using filter
206+ {
207+ "collections" : ["example-collection" ],
208+ "bbox" : [- 120.5 , 35.7 , - 120.0 , 36.0 ],
209+ "datetime" : "2021-06-01T00:00:00Z/2021-06-30T23:59:59Z" ,
210+ },
211+ # Using filter
212+ {
213+ "filter-lang" : "cql2-json" ,
214+ "filter" : {
215+ "op" : "and" ,
216+ "args" : [
217+ {"op" : "=" , "args" : [{"property" : "collection" }, "landsat-8-l1" ]},
218+ {"op" : "<=" , "args" : [{"property" : "eo:cloud_cover" }, 20 ]},
219+ {"op" : "=" , "args" : [{"property" : "platform" }, "landsat-8" ]},
220+ ],
221+ },
222+ "limit" : 5 ,
223+ },
224+ ],
225+ )
216226def test_search_post (
217227 mock_upstream ,
218228 source_api_server ,
@@ -223,6 +233,7 @@ def test_search_post(
223233 input_query ,
224234 token_builder ,
225235):
236+ """Test filter is applied to search with full-featured filtering."""
226237 # Setup app
227238 app = app_factory (
228239 upstream_url = source_api_server ,
@@ -246,19 +257,17 @@ def test_search_post(
246257 output_query = json .loads (r .read ().decode ())
247258
248259 # Parse query from upstream
249- # input_filter_lang = input_query.get("filter-lang")
250260 input_filter = input_query .get ("filter" )
251261 expected_filter = auth_filter if is_authenticated else anon_filter
252262 expected_filter_exprs = [
253263 cql2 .Expr (expr ).to_text ()
254264 for expr in [input_filter , expected_filter .strip ()]
255265 if expr
256266 ]
257- expected_filter_out = cql2 .Expr (" AND " .join (expected_filter_exprs )).to_json ()
258267
259268 expected_output_query = {
260269 ** input_query ,
261- "filter" : expected_filter_out ,
270+ "filter" : cql2 . Expr ( " AND " . join ( expected_filter_exprs )). to_json () ,
262271 }
263272
264273 assert (
0 commit comments