From d057924a66f52ebc81979ecc4538a5da3fc34baf Mon Sep 17 00:00:00 2001 From: Biel Stela Date: Fri, 13 Dec 2024 13:26:51 +0100 Subject: [PATCH] Starts tests --- api/app/routers/grid.py | 2 +- api/tests/conftest.py | 39 ++++++++++++++++++++++++++++++++++++++- api/tests/test_grid.py | 13 ++++++++++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/api/app/routers/grid.py b/api/app/routers/grid.py index eb020063..a05d0208 100644 --- a/api/app/routers/grid.py +++ b/api/app/routers/grid.py @@ -202,8 +202,8 @@ async def grid_dataset_metadata_in_area( @grid_router.post("/table") def read_table( level: Annotated[int, Query(..., description="Tile level at which the query will be computed")], - geojson: FeatureDep, filters: TableFilters = Depends(), + geojson: Feature | None = None, ) -> TableResults: """Query tile dataset and return table data""" files_path = pathlib.Path(get_settings().grid_tiles_path) / str(level) diff --git a/api/tests/conftest.py b/api/tests/conftest.py index 8910dd20..d792ba1c 100644 --- a/api/tests/conftest.py +++ b/api/tests/conftest.py @@ -76,7 +76,44 @@ def grid_dataset(setup_data_folder) -> str: } ) with open(grid_dataset_path / "meta.json", "w") as f: - f.write("{}") + f.write( + json.dumps( + { + "datasets": [ + { + "var_name": "landcover", + "var_dtype": "Int32", + "label": "foo", + "description": "foo", + "unit": "", + "legend": { + "legend_type": "categorical", + "entries": [{"value": 1, "color": "#ffffff", "label": "all"}], + }, + }, + { + "var_name": "population", + "var_dtype": "Int32", + "label": "bar", + "description": "bar", + "unit": "count", + "legend": { + "legend_type": "continuous", + "colormap_name": "viridis", + "stats": [{"level": 1, "min": 1, "max": 900}], + }, + }, + ], + "h3_grid_info": [ + { + "level": 1, + "h3_cells_resolution": 6, + "h3_cells_count": 5, + } + ], + } + ) + ) with open(tile_path, "wb") as f: df.write_ipc(f) diff --git a/api/tests/test_grid.py b/api/tests/test_grid.py index bfda7dd1..967f546a 100644 --- a/api/tests/test_grid.py +++ b/api/tests/test_grid.py @@ -219,7 +219,7 @@ def test_grid_table(grid_dataset): } response = test_client.post("/grid/table?level=4&order_by=-population", headers=HEADERS, content=json.dumps(body)) - assert response.status_code == 200 + assert response.status_code == 200, response.content assert json.loads(response.read()) == { "table": [ {"column": "landcover", "values": [4, 1]}, @@ -284,3 +284,14 @@ def test_grid_tile_post_wrong_column(grid_dataset, geojson): assert response.status_code == 400 assert response.json() == {"detail": "One or more of the specified columns is not valid"} + + +def test_grid_metadata_filter(grid_dataset, geojson): + response = test_client.post( + "/grid/meta", + params={"columns": ["population"]}, + headers=HEADERS, + content=geojson, + ) + assert response.status_code == 200 + assert response.json() == {"detail": "One or more of the specified columns is not valid"}