From 8fb0e896f033a1f4bbc1103b9c0243f16423448f Mon Sep 17 00:00:00 2001 From: Biel Stela Date: Thu, 12 Sep 2024 10:47:55 +0200 Subject: [PATCH] Adds test for table results with geojson filter --- api/tests/test_grid.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/api/tests/test_grid.py b/api/tests/test_grid.py index 6a6fe5e5..fb7726d4 100644 --- a/api/tests/test_grid.py +++ b/api/tests/test_grid.py @@ -211,14 +211,14 @@ def test_table_filters_multiple_filters(): def test_grid_table(grid_dataset): - filters = [ - {"filter_type": "numerical", "column_name": "population", "operation": "lte", "value": 200}, - {"filter_type": "numerical", "column_name": "population", "operation": "gt", "value": 1}, - ] + body = { + "filters": [ + {"filter_type": "numerical", "column_name": "population", "operation": "lte", "value": 200}, + {"filter_type": "numerical", "column_name": "population", "operation": "gt", "value": 1}, + ] + } - response = test_client.post( - "/grid/table?level=4&order_by=-population", headers=HEADERS, content=json.dumps(filters) - ) + response = test_client.post("/grid/table?level=4&order_by=-population", headers=HEADERS, content=json.dumps(body)) assert response.status_code == 200 assert json.loads(response.read()) == { "cell": [ @@ -230,6 +230,25 @@ def test_grid_table(grid_dataset): } +def test_grid_table_geojson(grid_dataset, geojson): + body = { + "filters": [ + {"filter_type": "numerical", "column_name": "population", "operation": "lte", "value": 200}, + {"filter_type": "numerical", "column_name": "population", "operation": "gt", "value": 1}, + ], + "geojson": json.loads(geojson), + } + response = test_client.post("/grid/table?level=4&order_by=-population", headers=HEADERS, content=json.dumps(body)) + assert response.status_code == 200 + assert json.loads(response.read()) == { + "cell": [ + "895f4261e03ffff", + ], + "landcover": [1], + "population": [100], + } + + def test_grid_tile_post_geojson(grid_dataset, geojson): response = test_client.post( f"/grid/tile/{grid_dataset}",