11"""test EOapi."""
2- import httpx
2+
33import os
44
5+ import httpx
6+
57# better timeouts
68timeout = httpx .Timeout (15.0 , connect = 60.0 )
79if bool (os .getenv ("IGNORE_SSL_VERIFICATION" , False )):
@@ -21,7 +23,10 @@ def test_raster_api(raster_endpoint):
2123
2224def test_mosaic_api (raster_endpoint ):
2325 """test mosaic."""
24- query = {"collections" : ["noaa-emergency-response" ], "filter-lang" : "cql-json" }
26+ query = {
27+ "collections" : ["noaa-emergency-response" ],
28+ "filter-lang" : "cql-json" ,
29+ }
2530 resp = client .post (f"{ raster_endpoint } /searches/register" , json = query )
2631 assert resp .headers ["content-type" ] == "application/json"
2732 assert resp .status_code == 200
@@ -30,7 +35,9 @@ def test_mosaic_api(raster_endpoint):
3035
3136 searchid = resp .json ()["id" ]
3237
33- resp = client .get (f"{ raster_endpoint } /searches/{ searchid } /point/-85.6358,36.1624/assets" )
38+ resp = client .get (
39+ f"{ raster_endpoint } /searches/{ searchid } /point/-85.6358,36.1624/assets"
40+ )
3441 assert resp .status_code == 200
3542 assert len (resp .json ()) == 1
3643 assert list (resp .json ()[0 ]) == ["id" , "bbox" , "assets" , "collection" ]
@@ -91,51 +98,87 @@ def test_mosaic_search(raster_endpoint):
9198 # register some fake mosaic
9299 searches = [
93100 {
94- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection1" ]},
101+ "filter" : {
102+ "op" : "=" ,
103+ "args" : [{"property" : "collection" }, "collection1" ],
104+ },
95105 "metadata" : {"owner" : "vincent" },
96106 },
97107 {
98- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection2" ]},
108+ "filter" : {
109+ "op" : "=" ,
110+ "args" : [{"property" : "collection" }, "collection2" ],
111+ },
99112 "metadata" : {"owner" : "vincent" },
100113 },
101114 {
102- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection3" ]},
115+ "filter" : {
116+ "op" : "=" ,
117+ "args" : [{"property" : "collection" }, "collection3" ],
118+ },
103119 "metadata" : {"owner" : "vincent" },
104120 },
105121 {
106- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection4" ]},
122+ "filter" : {
123+ "op" : "=" ,
124+ "args" : [{"property" : "collection" }, "collection4" ],
125+ },
107126 "metadata" : {"owner" : "vincent" },
108127 },
109128 {
110- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection5" ]},
129+ "filter" : {
130+ "op" : "=" ,
131+ "args" : [{"property" : "collection" }, "collection5" ],
132+ },
111133 "metadata" : {"owner" : "vincent" },
112134 },
113135 {
114- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection6" ]},
136+ "filter" : {
137+ "op" : "=" ,
138+ "args" : [{"property" : "collection" }, "collection6" ],
139+ },
115140 "metadata" : {"owner" : "vincent" },
116141 },
117142 {
118- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection7" ]},
143+ "filter" : {
144+ "op" : "=" ,
145+ "args" : [{"property" : "collection" }, "collection7" ],
146+ },
119147 "metadata" : {"owner" : "vincent" },
120148 },
121149 {
122- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection8" ]},
150+ "filter" : {
151+ "op" : "=" ,
152+ "args" : [{"property" : "collection" }, "collection8" ],
153+ },
123154 "metadata" : {"owner" : "sean" },
124155 },
125156 {
126- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection9" ]},
157+ "filter" : {
158+ "op" : "=" ,
159+ "args" : [{"property" : "collection" }, "collection9" ],
160+ },
127161 "metadata" : {"owner" : "sean" },
128162 },
129163 {
130- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection10" ]},
164+ "filter" : {
165+ "op" : "=" ,
166+ "args" : [{"property" : "collection" }, "collection10" ],
167+ },
131168 "metadata" : {"owner" : "drew" },
132169 },
133170 {
134- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection11" ]},
171+ "filter" : {
172+ "op" : "=" ,
173+ "args" : [{"property" : "collection" }, "collection11" ],
174+ },
135175 "metadata" : {"owner" : "drew" },
136176 },
137177 {
138- "filter" : {"op" : "=" , "args" : [{"property" : "collection" }, "collection12" ]},
178+ "filter" : {
179+ "op" : "=" ,
180+ "args" : [{"property" : "collection" }, "collection12" ],
181+ },
139182 "metadata" : {"owner" : "drew" },
140183 },
141184 ]
@@ -158,9 +201,16 @@ def test_mosaic_search(raster_endpoint):
158201
159202 links = resp .json ()["links" ]
160203 assert len (links ) == 2
161- assert links [0 ]["rel" ] == "self"
162- assert links [1 ]["rel" ] == "next"
163- assert links [1 ]["href" ] == f"{ raster_endpoint } /searches/list?limit=10&offset=10"
204+ # Find links by rel type
205+ link_rels = {link ["rel" ]: link ["href" ] for link in links }
206+ assert "self" in link_rels
207+ assert "next" in link_rels
208+ # Check if href contains the expected path (works with or without ROOT_PATH)
209+ next_href = link_rels ["next" ]
210+ assert (
211+ next_href .endswith ("/searches/list?limit=10&offset=10" )
212+ or next_href == f"{ raster_endpoint } /searches/list?limit=10&offset=10"
213+ )
164214
165215 resp = client .get (
166216 f"{ raster_endpoint } /searches/list" , params = {"limit" : 1 , "offset" : 1 }
@@ -172,34 +222,59 @@ def test_mosaic_search(raster_endpoint):
172222
173223 links = resp .json ()["links" ]
174224 assert len (links ) == 3
175- assert links [0 ]["rel" ] == "self"
176- assert links [0 ]["href" ] == f"{ raster_endpoint } /searches/list?limit=1&offset=1"
177- assert links [1 ]["rel" ] == "next"
178- assert links [1 ]["href" ] == f"{ raster_endpoint } /searches/list?limit=1&offset=2"
179- assert links [2 ]["rel" ] == "prev"
180- assert links [2 ]["href" ] == f"{ raster_endpoint } /searches/list?limit=1&offset=0"
225+ # Find links by rel type
226+ link_rels = {link ["rel" ]: link ["href" ] for link in links }
227+ assert "self" in link_rels
228+ assert "next" in link_rels
229+ assert "prev" in link_rels
230+ # Check if hrefs contain the expected paths (works with or without ROOT_PATH)
231+ assert (
232+ link_rels ["prev" ].endswith ("/searches/list?limit=1&offset=0" )
233+ or link_rels ["prev" ]
234+ == f"{ raster_endpoint } /searches/list?limit=1&offset=0"
235+ )
236+ assert (
237+ link_rels ["self" ].endswith ("/searches/list?limit=1&offset=1" )
238+ or link_rels ["self" ]
239+ == f"{ raster_endpoint } /searches/list?limit=1&offset=1"
240+ )
241+ assert (
242+ link_rels ["next" ].endswith ("/searches/list?limit=1&offset=2" )
243+ or link_rels ["next" ]
244+ == f"{ raster_endpoint } /searches/list?limit=1&offset=2"
245+ )
181246
182247 # Filter on mosaic metadata
183- resp = client .get (f"{ raster_endpoint } /searches/list" , params = {"owner" : "vincent" })
248+ resp = client .get (
249+ f"{ raster_endpoint } /searches/list" , params = {"owner" : "vincent" }
250+ )
184251 assert resp .status_code == 200
185252 assert resp .json ()["context" ]["matched" ] == 7
186253 assert resp .json ()["context" ]["limit" ] == 10
187254 assert resp .json ()["context" ]["returned" ] == 7
188255
189256 # sortBy
190- resp = client .get (f"{ raster_endpoint } /searches/list" , params = {"sortby" : "lastused" })
257+ resp = client .get (
258+ f"{ raster_endpoint } /searches/list" , params = {"sortby" : "lastused" }
259+ )
191260 assert resp .status_code == 200
192261
193- resp = client .get (f"{ raster_endpoint } /searches/list" , params = {"sortby" : "usecount" })
262+ resp = client .get (
263+ f"{ raster_endpoint } /searches/list" , params = {"sortby" : "usecount" }
264+ )
194265 assert resp .status_code == 200
195266
196- resp = client .get (f"{ raster_endpoint } /searches/list" , params = {"sortby" : "-owner" })
267+ resp = client .get (
268+ f"{ raster_endpoint } /searches/list" , params = {"sortby" : "-owner" }
269+ )
197270 assert resp .status_code == 200
198271 assert (
199272 "owner" not in resp .json ()["searches" ][0 ]["search" ]["metadata" ]
200273 ) # some mosaic don't have owners
201274
202- resp = client .get (f"{ raster_endpoint } /searches/list" , params = {"sortby" : "owner" })
275+ resp = client .get (
276+ f"{ raster_endpoint } /searches/list" , params = {"sortby" : "owner" }
277+ )
203278 assert resp .status_code == 200
204279 assert "owner" in resp .json ()["searches" ][0 ]["search" ]["metadata" ]
205280
0 commit comments