33from os import listdir
44from os .path import isfile , join
55
6+ import pytest
7+
68THIS_DIR = os .path .dirname (os .path .abspath (__file__ ))
79
810
9- async def test_search_filters (app_client , ctx ):
11+ @pytest .mark .asyncio
12+ async def test_search_filters_post (app_client , ctx ):
1013
1114 filters = []
1215 pwd = f"{ THIS_DIR } /cql2"
@@ -19,15 +22,45 @@ async def test_search_filters(app_client, ctx):
1922 assert resp .status_code == 200
2023
2124
22- async def test_search_filter_extension_eq (app_client , ctx ):
25+ @pytest .mark .asyncio
26+ async def test_search_filter_extension_eq_get (app_client , ctx ):
27+ resp = await app_client .get (
28+ '/search?filter-lang=cql2-json&filter={"op":"=","args":[{"property":"id"},"test-item"]}'
29+ )
30+ assert resp .status_code == 200
31+ resp_json = resp .json ()
32+ assert len (resp_json ["features" ]) == 1
33+
34+
35+ @pytest .mark .asyncio
36+ async def test_search_filter_extension_eq_post (app_client , ctx ):
2337 params = {"filter" : {"op" : "=" , "args" : [{"property" : "id" }, ctx .item ["id" ]]}}
2438 resp = await app_client .post ("/search" , json = params )
2539 assert resp .status_code == 200
2640 resp_json = resp .json ()
2741 assert len (resp_json ["features" ]) == 1
2842
2943
30- async def test_search_filter_extension_gte (app_client , ctx ):
44+ @pytest .mark .asyncio
45+ async def test_search_filter_extension_gte_get (app_client , ctx ):
46+ # there's one item that can match, so one of these queries should match it and the other shouldn't
47+ resp = await app_client .get (
48+ '/search?filter-lang=cql2-json&filter={"op":"<=","args":[{"property": "properties.proj:epsg"},32756]}'
49+ )
50+
51+ assert resp .status_code == 200
52+ assert len (resp .json ()["features" ]) == 1
53+
54+ resp = await app_client .get (
55+ '/search?filter-lang=cql2-json&filter={"op":">","args":[{"property": "properties.proj:epsg"},32756]}'
56+ )
57+
58+ assert resp .status_code == 200
59+ assert len (resp .json ()["features" ]) == 0
60+
61+
62+ @pytest .mark .asyncio
63+ async def test_search_filter_extension_gte_post (app_client , ctx ):
3164 # there's one item that can match, so one of these queries should match it and the other shouldn't
3265 params = {
3366 "filter" : {
@@ -58,7 +91,53 @@ async def test_search_filter_extension_gte(app_client, ctx):
5891 assert len (resp .json ()["features" ]) == 0
5992
6093
61- async def test_search_filter_ext_and (app_client , ctx ):
94+ @pytest .mark .asyncio
95+ async def test_search_filter_ext_and_get (app_client , ctx ):
96+ resp = await app_client .get (
97+ '/search?filter-lang=cql2-json&filter={"op":"and","args":[{"op":"<=","args":[{"property":"properties.proj:epsg"},32756]},{"op":"=","args":[{"property":"id"},"test-item"]}]}'
98+ )
99+
100+ assert resp .status_code == 200
101+ assert len (resp .json ()["features" ]) == 1
102+
103+
104+ @pytest .mark .asyncio
105+ async def test_search_filter_ext_and_get_cql2text_id (app_client , ctx ):
106+ collection = ctx .item ["collection" ]
107+ id = ctx .item ["id" ]
108+ filter = f"id='{ id } ' AND collection='{ collection } '"
109+ resp = await app_client .get (f"/search?filter-lang=cql2-text&filter={ filter } " )
110+
111+ assert resp .status_code == 200
112+ assert len (resp .json ()["features" ]) == 1
113+
114+
115+ @pytest .mark .asyncio
116+ async def test_search_filter_ext_and_get_cql2text_cloud_cover (app_client , ctx ):
117+ collection = ctx .item ["collection" ]
118+ cloud_cover = ctx .item ["properties" ]["eo:cloud_cover" ]
119+ filter = f"cloud_cover={ cloud_cover } AND collection='{ collection } '"
120+ resp = await app_client .get (f"/search?filter-lang=cql2-text&filter={ filter } " )
121+
122+ assert resp .status_code == 200
123+ assert len (resp .json ()["features" ]) == 1
124+
125+
126+ @pytest .mark .asyncio
127+ async def test_search_filter_ext_and_get_cql2text_cloud_cover_no_results (
128+ app_client , ctx
129+ ):
130+ collection = ctx .item ["collection" ]
131+ cloud_cover = ctx .item ["properties" ]["eo:cloud_cover" ] + 1
132+ filter = f"cloud_cover={ cloud_cover } AND collection='{ collection } '"
133+ resp = await app_client .get (f"/search?filter-lang=cql2-text&filter={ filter } " )
134+
135+ assert resp .status_code == 200
136+ assert len (resp .json ()["features" ]) == 0
137+
138+
139+ @pytest .mark .asyncio
140+ async def test_search_filter_ext_and_post (app_client , ctx ):
62141 params = {
63142 "filter" : {
64143 "op" : "and" ,
@@ -80,7 +159,32 @@ async def test_search_filter_ext_and(app_client, ctx):
80159 assert len (resp .json ()["features" ]) == 1
81160
82161
83- async def test_search_filter_extension_floats (app_client , ctx ):
162+ @pytest .mark .asyncio
163+ async def test_search_filter_extension_floats_get (app_client , ctx ):
164+ resp = await app_client .get (
165+ """/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
166+ )
167+
168+ assert resp .status_code == 200
169+ assert len (resp .json ()["features" ]) == 1
170+
171+ resp = await app_client .get (
172+ """/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item-7"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30891534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30691534"]}]}"""
173+ )
174+
175+ assert resp .status_code == 200
176+ assert len (resp .json ()["features" ]) == 0
177+
178+ resp = await app_client .get (
179+ """/search?filter={"op":"and","args":[{"op":"=","args":[{"property":"id"},"test-item"]},{"op":">","args":[{"property":"properties.view:sun_elevation"},"-37.30591534"]},{"op":"<","args":[{"property":"properties.view:sun_elevation"},"-37.30491534"]}]}"""
180+ )
181+
182+ assert resp .status_code == 200
183+ assert len (resp .json ()["features" ]) == 0
184+
185+
186+ @pytest .mark .asyncio
187+ async def test_search_filter_extension_floats_post (app_client , ctx ):
84188 sun_elevation = ctx .item ["properties" ]["view:sun_elevation" ]
85189
86190 params = {
0 commit comments