From b90932d97a3296076c86112d336a87446c1241ee Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Fri, 6 Oct 2023 16:43:39 +0200 Subject: [PATCH] update collections endpoit in raster API --- .github/workflows/tests/test_raster.py | 13 +++++++++++++ runtime/eoapi/raster/eoapi/raster/app.py | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests/test_raster.py b/.github/workflows/tests/test_raster.py index 50b35b4..17556ca 100644 --- a/.github/workflows/tests/test_raster.py +++ b/.github/workflows/tests/test_raster.py @@ -188,3 +188,16 @@ def test_item(): in resp.json()["tiles"][0] ) assert resp.json()["bounds"] == [-85.5501, 36.1749, -85.5249, 36.2001] + + +def test_collections(): + """test collection endpoints.""" + resp = httpx.get( + f"{raster_endpoint}/collections", + ) + assert resp.status_code == 200 + assert resp.headers["content-type"] == "application/json" + + collections = resp.json() + assert len(collections) == 1 + assert collections[0]["id"] == "noaa-emergency-response" diff --git a/runtime/eoapi/raster/eoapi/raster/app.py b/runtime/eoapi/raster/eoapi/raster/app.py index 9741b99..2883be7 100644 --- a/runtime/eoapi/raster/eoapi/raster/app.py +++ b/runtime/eoapi/raster/eoapi/raster/app.py @@ -9,6 +9,7 @@ from eoapi.raster.config import ApiSettings from fastapi import Depends, FastAPI, Query from psycopg import OperationalError +from psycopg.rows import dict_row from psycopg_pool import PoolTimeout from starlette.middleware.cors import CORSMiddleware from starlette.requests import Request @@ -118,9 +119,10 @@ async def mosaic_builder(request: Request): async def list_collection(request: Request): """list collections.""" with request.app.state.dbpool.connection() as conn: - with conn.cursor() as cursor: - cursor.execute("SELECT * FROM collections;") - return [t[2] for t in cursor.fetchall() if t] + with conn.cursor(row_factory=dict_row) as cursor: + cursor.execute("SELECT * FROM pgstac.all_collections();") + r = cursor.fetchone() + return r.get("all_collections", []) app.include_router(mosaic.router, tags=["Mosaic"], prefix="/mosaic")