Skip to content

Commit

Permalink
fix column param default and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Jul 15, 2024
1 parent 092547f commit 3e89d5d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion api/app/routers/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@
responses={200: {"description": "Get a grid tile"}, 404: {"description": "Not found"}},
response_model=None,
)
async def grid_tile(tile_index: str, columns: list[str] = Query()) -> Response:
async def grid_tile(
tile_index: str,
columns: list[str] = Query(
[], description="Colum/s to include in the tile. If empty, it returns only the cell index."
),
) -> Response:
"""Request a tile of h3 cells filtered by columns"""
try:
z = h3.api.basic_str.h3_get_resolution(tile_index)
Expand Down
19 changes: 18 additions & 1 deletion api/tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@


def test_grid_tile(grid_dataset):
response = test_client.get(f"/grid/tile/{grid_dataset}", headers=HEADERS)
response = test_client.get(
f"/grid/tile/{grid_dataset}", params={"columns": ["landcover", "population"]}, headers=HEADERS
)

assert response.status_code == 200
assert pl.read_ipc(response.read()).to_dict(as_series=False) == {
Expand All @@ -24,6 +26,21 @@ def test_grid_tile(grid_dataset):
}


def test_grid_tile_empty_column_param(grid_dataset):
response = test_client.get(f"/grid/tile/{grid_dataset}", headers=HEADERS)

assert response.status_code == 200
assert pl.read_ipc(response.read()).to_dict(as_series=False) == {
"cell": [
618668968382824400,
619428375900454900,
619428407452893200,
619428407943888900,
619428407676764200,
],
}


def test_grid_tile_404(grid_dataset):
response = test_client.get("/grid/tile/8439181ffffffff", headers=HEADERS)

Expand Down

0 comments on commit 3e89d5d

Please sign in to comment.