Skip to content

Commit

Permalink
Starts tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Dec 13, 2024
1 parent 119e733 commit d057924
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/app/routers/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 38 additions & 1 deletion api/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion api/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]},
Expand Down Expand Up @@ -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"}

0 comments on commit d057924

Please sign in to comment.