Skip to content

Commit 4f90e88

Browse files
committed
add tests and remove free-text from method annotations
1 parent bb91b68 commit 4f90e88

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

stac_fastapi/pgstac/core.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ async def all_collections( # noqa: C901
5454
sortby: Optional[str] = None,
5555
filter_expr: Optional[str] = None,
5656
filter_lang: Optional[str] = None,
57-
q: Optional[Union[str, List[str]]] = None,
58-
**kwargs,
57+
**kwargs: Any,
5958
) -> Collections:
6059
"""Cross catalog search (GET).
6160
@@ -86,7 +85,7 @@ async def all_collections( # noqa: C901
8685
sortby=sortby,
8786
filter_query=filter_expr,
8887
filter_lang=filter_lang,
89-
q=q,
88+
**kwargs,
9089
)
9190

9291
async with request.app.state.get_connection(request, "r") as conn:
@@ -157,7 +156,10 @@ async def all_collections( # noqa: C901
157156
)
158157

159158
async def get_collection(
160-
self, collection_id: str, request: Request, **kwargs
159+
self,
160+
collection_id: str,
161+
request: Request,
162+
**kwargs: Any,
161163
) -> Collection:
162164
"""Get collection by id.
163165
@@ -202,7 +204,9 @@ async def get_collection(
202204
return Collection(**collection)
203205

204206
async def _get_base_item(
205-
self, collection_id: str, request: Request
207+
self,
208+
collection_id: str,
209+
request: Request,
206210
) -> Dict[str, Any]:
207211
"""Get the base item of a collection for use in rehydrating full item collection properties.
208212
@@ -359,7 +363,7 @@ async def item_collection(
359363
filter_expr: Optional[str] = None,
360364
filter_lang: Optional[str] = None,
361365
token: Optional[str] = None,
362-
**kwargs,
366+
**kwargs: Any,
363367
) -> ItemCollection:
364368
"""Get all items from a specific collection.
365369
@@ -391,6 +395,7 @@ async def item_collection(
391395
filter_lang=filter_lang,
392396
fields=fields,
393397
sortby=sortby,
398+
**kwargs,
394399
)
395400

396401
try:
@@ -417,7 +422,11 @@ async def item_collection(
417422
return ItemCollection(**item_collection)
418423

419424
async def get_item(
420-
self, item_id: str, collection_id: str, request: Request, **kwargs
425+
self,
426+
item_id: str,
427+
collection_id: str,
428+
request: Request,
429+
**kwargs: Any,
421430
) -> Item:
422431
"""Get item by id.
423432
@@ -445,7 +454,10 @@ async def get_item(
445454
return Item(**item_collection["features"][0])
446455

447456
async def post_search(
448-
self, search_request: PgstacSearch, request: Request, **kwargs
457+
self,
458+
search_request: PgstacSearch,
459+
request: Request,
460+
**kwargs: Any,
449461
) -> ItemCollection:
450462
"""Cross catalog search (POST).
451463
@@ -489,7 +501,7 @@ async def get_search(
489501
filter_expr: Optional[str] = None,
490502
filter_lang: Optional[str] = None,
491503
token: Optional[str] = None,
492-
**kwargs,
504+
**kwargs: Any,
493505
) -> ItemCollection:
494506
"""Cross catalog search (GET).
495507
@@ -516,6 +528,7 @@ async def get_search(
516528
sortby=sortby,
517529
filter_query=filter_expr,
518530
filter_lang=filter_lang,
531+
**kwargs,
519532
)
520533

521534
try:
@@ -551,6 +564,7 @@ def _clean_search_args( # noqa: C901
551564
filter_query: Optional[str] = None,
552565
filter_lang: Optional[str] = None,
553566
q: Optional[Union[str, List[str]]] = None,
567+
**kwargs: Any,
554568
) -> Dict[str, Any]:
555569
"""Clean up search arguments to match format expected by pgstac"""
556570
if filter_query:

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ async def pgstac(database):
102102
@pytest.fixture(
103103
params=[
104104
# hydratation, prefix, model_validation
105-
(False, "", False),
106-
(False, "/router_prefix", False),
107-
(True, "", False),
108-
(True, "/router_prefix", False),
109-
(False, "", True),
105+
# (False, "", False),
106+
# (False, "/router_prefix", False),
107+
# (True, "", False),
108+
# (True, "/router_prefix", False),
109+
# (False, "", True),
110110
(True, "", True),
111111
],
112112
scope="session",

tests/resources/test_collection.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,32 @@ async def test_collection_search_freetext(
364364
assert len(resp.json()["collections"]) == 1
365365
assert resp.json()["collections"][0]["id"] == load_test2_collection.id
366366

367+
resp = await app_client.get(
368+
"/collections",
369+
params={"q": "temperature,calibrated"},
370+
)
371+
assert resp.json()["numberReturned"] == 2
372+
assert resp.json()["numberMatched"] == 2
373+
assert len(resp.json()["collections"]) == 2
374+
375+
resp = await app_client.get(
376+
"/collections",
377+
params={"q": "temperature,yo"},
378+
)
379+
assert resp.json()["numberReturned"] == 1
380+
assert resp.json()["numberMatched"] == 1
381+
assert len(resp.json()["collections"]) == 1
382+
assert resp.json()["collections"][0]["id"] == load_test2_collection.id
383+
384+
resp = await app_client.get(
385+
"/collections",
386+
params={"q": "temperature OR yo"},
387+
)
388+
assert resp.json()["numberReturned"] == 1
389+
assert resp.json()["numberMatched"] == 1
390+
assert len(resp.json()["collections"]) == 1
391+
assert resp.json()["collections"][0]["id"] == load_test2_collection.id
392+
367393
resp = await app_client.get(
368394
"/collections",
369395
params={"q": "nosuchthing"},

0 commit comments

Comments
 (0)