3
3
from os import listdir
4
4
from os .path import isfile , join
5
5
6
+ import pytest
7
+
6
8
THIS_DIR = os .path .dirname (os .path .abspath (__file__ ))
7
9
8
10
9
- async def test_search_filters (app_client , ctx ):
11
+ @pytest .mark .asyncio
12
+ async def test_search_filters_post (app_client , ctx ):
10
13
11
14
filters = []
12
15
pwd = f"{ THIS_DIR } /cql2"
@@ -19,15 +22,45 @@ async def test_search_filters(app_client, ctx):
19
22
assert resp .status_code == 200
20
23
21
24
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 ):
23
37
params = {"filter" : {"op" : "=" , "args" : [{"property" : "id" }, ctx .item ["id" ]]}}
24
38
resp = await app_client .post ("/search" , json = params )
25
39
assert resp .status_code == 200
26
40
resp_json = resp .json ()
27
41
assert len (resp_json ["features" ]) == 1
28
42
29
43
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 ):
31
64
# there's one item that can match, so one of these queries should match it and the other shouldn't
32
65
params = {
33
66
"filter" : {
@@ -58,7 +91,53 @@ async def test_search_filter_extension_gte(app_client, ctx):
58
91
assert len (resp .json ()["features" ]) == 0
59
92
60
93
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 ):
62
141
params = {
63
142
"filter" : {
64
143
"op" : "and" ,
@@ -80,7 +159,32 @@ async def test_search_filter_ext_and(app_client, ctx):
80
159
assert len (resp .json ()["features" ]) == 1
81
160
82
161
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 ):
84
188
sun_elevation = ctx .item ["properties" ]["view:sun_elevation" ]
85
189
86
190
params = {
0 commit comments