From 5de68fb4ca7abc941f1f2f6627edd3c840dba17e Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Thu, 30 Nov 2023 16:43:57 +0100 Subject: [PATCH 01/11] Add integration tests with responses for the EDR API. --- .gitignore | 1 + docker-compose.yml | 2 + integration-test/Dockerfile | 3 + integration-test/requirements.in | 2 + integration-test/requirements.txt | 30 +- .../capabilities/200/all_collections.json | 77 ++++ ...thin_an_area_with_multiple_parameters.json | 380 ++++++++++++++++++ .../200/locations_within_a_bbox.json | 27 ++ ...gle_location_with_multiple_parameters.json | 167 ++++++++ .../locations/404/no_data_found.json | 3 + ...e_coordinate_with_multiple_parameters.json | 167 ++++++++ .../metadata/200/single_collection.json | 67 +++ .../response/metadata/404/not_found.json | 3 + integration-test/test_api.py | 121 ++++++ 14 files changed, 1044 insertions(+), 6 deletions(-) create mode 100644 integration-test/response/capabilities/200/all_collections.json create mode 100644 integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json create mode 100644 integration-test/response/collection/locations/200/locations_within_a_bbox.json create mode 100644 integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json create mode 100644 integration-test/response/collection/locations/404/no_data_found.json create mode 100644 integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json create mode 100644 integration-test/response/metadata/200/single_collection.json create mode 100644 integration-test/response/metadata/404/not_found.json create mode 100644 integration-test/test_api.py diff --git a/.gitignore b/.gitignore index 1376338..63ba3bd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .run/ # Python +.pytest_cache/ __pycache__/ venv/ diff --git a/docker-compose.yml b/docker-compose.yml index 7d143e6..89ee4cf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -49,6 +49,7 @@ services: condition: service_healthy api: + hostname: api build: context: . # TODO: Needed to get proto file. Find a better solution dockerfile: api/Dockerfile @@ -93,6 +94,7 @@ services: environment: - DSHOST=store - DSPORT=50050 + - BASE_URL=http://api:8000 depends_on: store: condition: service_healthy diff --git a/integration-test/Dockerfile b/integration-test/Dockerfile index 39a424a..eab301c 100644 --- a/integration-test/Dockerfile +++ b/integration-test/Dockerfile @@ -29,6 +29,9 @@ RUN python -m grpc_tools.protoc \ COPY "${PROJECT_PYTHON_PATH}/test_knmi.py" "${DOCKER_PATH}/test_knmi.py" COPY "${PROJECT_PYTHON_PATH}/test_delete.py" "${DOCKER_PATH}/test_delete.py" +COPY "${PROJECT_PYTHON_PATH}/test_api.py" "${DOCKER_PATH}/test_api.py" + +COPY "${PROJECT_PYTHON_PATH}/response/" "${DOCKER_PATH}/response/" WORKDIR "${DOCKER_PATH}" CMD ["pytest"] diff --git a/integration-test/requirements.in b/integration-test/requirements.in index d591866..3060a1e 100644 --- a/integration-test/requirements.in +++ b/integration-test/requirements.in @@ -3,5 +3,7 @@ # Install using: # pip-sync +deepdiff~=6.2 grpcio-tools~=1.56 pytest~=7.4 +requests~=2.31 diff --git a/integration-test/requirements.txt b/integration-test/requirements.txt index 1cb31cb..20bb3b0 100644 --- a/integration-test/requirements.txt +++ b/integration-test/requirements.txt @@ -1,23 +1,41 @@ # -# This file is autogenerated by pip-compile with Python 3.11 +# This file is autogenerated by pip-compile with Python 3.10 # by the following command: # # pip-compile --no-emit-index-url # -grpcio==1.58.0 +certifi==2023.11.17 + # via requests +charset-normalizer==3.3.2 + # via requests +deepdiff==6.7.1 + # via -r requirements.in +exceptiongroup==1.2.0 + # via pytest +grpcio==1.59.3 # via grpcio-tools -grpcio-tools==1.58.0 +grpcio-tools==1.59.3 # via -r requirements.in +idna==3.4 + # via requests iniconfig==2.0.0 # via pytest -packaging==23.1 +ordered-set==4.1.0 + # via deepdiff +packaging==23.2 # via pytest pluggy==1.3.0 # via pytest -protobuf==4.24.3 +protobuf==4.25.1 # via grpcio-tools -pytest==7.4.2 +pytest==7.4.3 # via -r requirements.in +requests==2.31.0 + # via -r requirements.in +tomli==2.0.1 + # via pytest +urllib3==2.1.0 + # via requests # The following packages are considered to be unsafe in a requirements file: # setuptools diff --git a/integration-test/response/capabilities/200/all_collections.json b/integration-test/response/capabilities/200/all_collections.json new file mode 100644 index 0000000..30ff65d --- /dev/null +++ b/integration-test/response/capabilities/200/all_collections.json @@ -0,0 +1,77 @@ +{ + "links": [ + { + "href": "http://localhost:8008/collections", + "rel": "self" + } + ], + "collections": [ + { + "id": "observations", + "links": [ + { + "href": "http://localhost:8008/collections/observations", + "rel": "self" + } + ], + "extent": { + "spatial": { + "bbox": [ + [ + 3.0, + 50.0, + 8.0, + 55.0 + ] + ], + "crs": "WGS84" + } + }, + "data_queries": { + "position": { + "link": { + "href": "http://localhost:8008/collections/observations/position", + "rel": "data", + "variables": { + "query_type": "position", + "output_format": [ + "CoverageJSON" + ] + } + } + }, + "area": { + "link": { + "href": "http://localhost:8008/collections/observations/area", + "rel": "data", + "variables": { + "query_type": "area", + "output_format": [ + "CoverageJSON" + ] + } + } + }, + "locations": { + "link": { + "href": "http://localhost:8008/collections/observations/locations", + "rel": "data", + "variables": { + "query_type": "locations", + "output_format": [ + "CoverageJSON" + ] + } + } + } + }, + "crs": [ + "WGS84" + ], + "output_formats": [ + "CoverageJSON" + ], + "parameter_names": {} + } + ] +} diff --git a/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json b/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json new file mode 100644 index 0000000..3f1d3b8 --- /dev/null +++ b/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json @@ -0,0 +1,380 @@ +{ + "type": "CoverageCollection", + "coverages": [ + { + "type": "Coverage", + "domain": { + "type": "Domain", + "domainType": "PointSeries", + "axes": { + "x": { + "values": [ + 5.8723225499118 + ] + }, + "y": { + "values": [ + 52.0548617826 + ] + }, + "t": { + "values": [ + "2022-12-31T00:50:00Z", + "2022-12-31T01:00:00Z", + "2022-12-31T01:10:00Z", + "2022-12-31T01:20:00Z", + "2022-12-31T01:30:00Z", + "2022-12-31T01:40:00Z", + "2022-12-31T01:50:00Z", + "2022-12-31T02:00:00Z" + ] + } + }, + "referencing": [ + { + "coordinates": [ + "y", + "x" + ], + "system": { + "type": "GeographicCRS", + "id": "http://www.opengis.net/def/crs/EPSG/0/4326" + } + }, + { + "coordinates": [ + "z" + ], + "system": { + "type": "TemporalRS", + "calendar": "Gregorian" + } + } + ] + }, + "parameters": { + "dd": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "dd" + } + }, + "unit": { + "label": { + "en": "degree" + } + } + }, + "ff": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "ff" + } + }, + "unit": { + "label": { + "en": "m s-1" + } + } + }, + "rh": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "rh" + } + }, + "unit": { + "label": { + "en": "%" + } + } + } + }, + "ranges": { + "dd": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 236.4, + 240.3, + 250.4, + 239.2, + 232.7, + 241.4, + 247.9, + 248.1 + ] + }, + "ff": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 5.38, + 5.25, + 4.04, + 4.06, + 4.41, + 4.31, + 4.57, + 4.37 + ] + }, + "rh": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 97, + 96, + 96, + 96, + 96, + 97, + 96, + 95 + ] + } + } + }, + { + "type": "Coverage", + "domain": { + "type": "Domain", + "domainType": "PointSeries", + "axes": { + "x": { + "values": [ + 5.1797058644882 + ] + }, + "y": { + "values": [ + 52.098821802977 + ] + }, + "t": { + "values": [ + "2022-12-31T00:50:00Z", + "2022-12-31T01:00:00Z", + "2022-12-31T01:10:00Z", + "2022-12-31T01:20:00Z", + "2022-12-31T01:30:00Z", + "2022-12-31T01:40:00Z", + "2022-12-31T01:50:00Z", + "2022-12-31T02:00:00Z" + ] + } + }, + "referencing": [ + { + "coordinates": [ + "y", + "x" + ], + "system": { + "type": "GeographicCRS", + "id": "http://www.opengis.net/def/crs/EPSG/0/4326" + } + }, + { + "coordinates": [ + "z" + ], + "system": { + "type": "TemporalRS", + "calendar": "Gregorian" + } + } + ] + }, + "parameters": { + "dd": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "dd" + } + }, + "unit": { + "label": { + "en": "degree" + } + } + }, + "ff": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "ff" + } + }, + "unit": { + "label": { + "en": "m s-1" + } + } + }, + "rh": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "rh" + } + }, + "unit": { + "label": { + "en": "%" + } + } + } + }, + "ranges": { + "dd": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 237.9, + 235.4, + 240, + 243.2, + 243.2, + 240, + 239.9, + 229.5 + ] + }, + "ff": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 4.26, + 4.72, + 4.1, + 3.79, + 4.2, + 3.83, + 3.69, + 3.3 + ] + }, + "rh": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 95, + 94, + 94, + 94, + 94, + 93, + 93, + 94 + ] + } + } + } + ], + "parameters": { + "dd": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "dd" + } + }, + "unit": { + "label": { + "en": "degree" + } + } + }, + "ff": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "ff" + } + }, + "unit": { + "label": { + "en": "m s-1" + } + } + }, + "rh": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "rh" + } + }, + "unit": { + "label": { + "en": "%" + } + } + } + } +} diff --git a/integration-test/response/collection/locations/200/locations_within_a_bbox.json b/integration-test/response/collection/locations/200/locations_within_a_bbox.json new file mode 100644 index 0000000..5759e01 --- /dev/null +++ b/integration-test/response/collection/locations/200/locations_within_a_bbox.json @@ -0,0 +1,27 @@ +{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 5.1797058644882, + 52.098821802977 + ] + }, + "id": "06260" + }, + { + "type": "Feature", + "geometry": { + "type": "Point", + "coordinates": [ + 5.8723225499118, + 52.0548617826 + ] + }, + "id": "06275" + } + ] +} diff --git a/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json new file mode 100644 index 0000000..ee1da91 --- /dev/null +++ b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json @@ -0,0 +1,167 @@ +{ + "type": "Coverage", + "domain": { + "type": "Domain", + "domainType": "PointSeries", + "axes": { + "x": { + "values": [ + 5.1797058644882 + ] + }, + "y": { + "values": [ + 52.098821802977 + ] + }, + "t": { + "values": [ + "2022-12-31T00:50:00Z", + "2022-12-31T01:00:00Z", + "2022-12-31T01:10:00Z", + "2022-12-31T01:20:00Z", + "2022-12-31T01:30:00Z", + "2022-12-31T01:40:00Z", + "2022-12-31T01:50:00Z", + "2022-12-31T02:00:00Z" + ] + } + }, + "referencing": [ + { + "coordinates": [ + "y", + "x" + ], + "system": { + "type": "GeographicCRS", + "id": "http://www.opengis.net/def/crs/EPSG/0/4326" + } + }, + { + "coordinates": [ + "z" + ], + "system": { + "type": "TemporalRS", + "calendar": "Gregorian" + } + } + ] + }, + "parameters": { + "dd": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "dd" + } + }, + "unit": { + "label": { + "en": "degree" + } + } + }, + "ff": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "ff" + } + }, + "unit": { + "label": { + "en": "m s-1" + } + } + }, + "rh": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "rh" + } + }, + "unit": { + "label": { + "en": "%" + } + } + } + }, + "ranges": { + "dd": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 237.9, + 235.4, + 240, + 243.2, + 243.2, + 240, + 239.9, + 229.5 + ] + }, + "ff": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 4.26, + 4.72, + 4.1, + 3.79, + 4.2, + 3.83, + 3.69, + 3.3 + ] + }, + "rh": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 95, + 94, + 94, + 94, + 94, + 93, + 93, + 94 + ] + } + } +} diff --git a/integration-test/response/collection/locations/404/no_data_found.json b/integration-test/response/collection/locations/404/no_data_found.json new file mode 100644 index 0000000..732842a --- /dev/null +++ b/integration-test/response/collection/locations/404/no_data_found.json @@ -0,0 +1,3 @@ +{ + "detail": "No data found" +} diff --git a/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json b/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json new file mode 100644 index 0000000..ee1da91 --- /dev/null +++ b/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json @@ -0,0 +1,167 @@ +{ + "type": "Coverage", + "domain": { + "type": "Domain", + "domainType": "PointSeries", + "axes": { + "x": { + "values": [ + 5.1797058644882 + ] + }, + "y": { + "values": [ + 52.098821802977 + ] + }, + "t": { + "values": [ + "2022-12-31T00:50:00Z", + "2022-12-31T01:00:00Z", + "2022-12-31T01:10:00Z", + "2022-12-31T01:20:00Z", + "2022-12-31T01:30:00Z", + "2022-12-31T01:40:00Z", + "2022-12-31T01:50:00Z", + "2022-12-31T02:00:00Z" + ] + } + }, + "referencing": [ + { + "coordinates": [ + "y", + "x" + ], + "system": { + "type": "GeographicCRS", + "id": "http://www.opengis.net/def/crs/EPSG/0/4326" + } + }, + { + "coordinates": [ + "z" + ], + "system": { + "type": "TemporalRS", + "calendar": "Gregorian" + } + } + ] + }, + "parameters": { + "dd": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "dd" + } + }, + "unit": { + "label": { + "en": "degree" + } + } + }, + "ff": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "ff" + } + }, + "unit": { + "label": { + "en": "m s-1" + } + } + }, + "rh": { + "type": "Parameter", + "observedProperty": { + "label": { + "en": "rh" + } + }, + "unit": { + "label": { + "en": "%" + } + } + } + }, + "ranges": { + "dd": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 237.9, + 235.4, + 240, + 243.2, + 243.2, + 240, + 239.9, + 229.5 + ] + }, + "ff": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 4.26, + 4.72, + 4.1, + 3.79, + 4.2, + 3.83, + 3.69, + 3.3 + ] + }, + "rh": { + "type": "NdArray", + "dataType": "float", + "axisNames": [ + "t", + "y", + "x" + ], + "shape": [ + 8, + 1, + 1 + ], + "values": [ + 95, + 94, + 94, + 94, + 94, + 93, + 93, + 94 + ] + } + } +} diff --git a/integration-test/response/metadata/200/single_collection.json b/integration-test/response/metadata/200/single_collection.json new file mode 100644 index 0000000..0043e4a --- /dev/null +++ b/integration-test/response/metadata/200/single_collection.json @@ -0,0 +1,67 @@ +{ + "id": "observations", + "links": [ + { + "href": "http://localhost:8008/collections/observations/observations", + "rel": "self" + } + ], + "extent": { + "spatial": { + "bbox": [ + [ + 3, + 50, + 8, + 55 + ] + ], + "crs": "WGS84" + } + }, + "data_queries": { + "position": { + "link": { + "href": "http://localhost:8008/collections/observations/observations/position", + "rel": "data", + "variables": { + "query_type": "position", + "output_format": [ + "CoverageJSON" + ] + } + } + }, + "area": { + "link": { + "href": "http://localhost:8008/collections/observations/observations/area", + "rel": "data", + "variables": { + "query_type": "area", + "output_format": [ + "CoverageJSON" + ] + } + } + }, + "locations": { + "link": { + "href": "http://localhost:8008/collections/observations/observations/locations", + "rel": "data", + "variables": { + "query_type": "locations", + "output_format": [ + "CoverageJSON" + ] + } + } + } + }, + "crs": [ + "WGS84" + ], + "output_formats": [ + "CoverageJSON" + ], + "parameter_names": {} +} diff --git a/integration-test/response/metadata/404/not_found.json b/integration-test/response/metadata/404/not_found.json new file mode 100644 index 0000000..634080e --- /dev/null +++ b/integration-test/response/metadata/404/not_found.json @@ -0,0 +1,3 @@ +{ + "detail": "Not Found" +} diff --git a/integration-test/test_api.py b/integration-test/test_api.py new file mode 100644 index 0000000..759fa75 --- /dev/null +++ b/integration-test/test_api.py @@ -0,0 +1,121 @@ +import json +import logging +import os +from pathlib import Path + +import requests +from deepdiff import DeepDiff + +logging.basicConfig() +logger = logging.getLogger(__name__) +logger.setLevel(os.environ.get("LOG_LEVEL", logging.INFO)) + + +BASE_URL = os.environ.get("BASE_URL", "http://localhost:8008") + + +def actual_status_code_is_expected_status_code(actual_response, expected_status_code): + assert actual_response.status_code == expected_status_code + + +def actual_response_is_expected_response(actual_response, expected_path): + file_path = Path(Path(__file__).parent, expected_path).resolve() + with open(file_path) as file: + expected_json = json.load(file) + + diff = DeepDiff(expected_json, actual_response.json(), ignore_order=True) + assert diff == {} + + +def test_get_all_collections(): + actual_response = requests.get(url=BASE_URL + "/collections") + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response(actual_response, "response/capabilities/200/all_collections.json") + + +def test_get_a_single_existing_collection(): + collection_id = "observations" + actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}") + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response(actual_response, "response/metadata/200/single_collection.json") + + +def test_get_a_collection_which_does_not_exist(): + collection_id = "does-not-exist" + actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}") + + actual_status_code_is_expected_status_code(actual_response, 404) + actual_response_is_expected_response(actual_response, "response/metadata/404/not_found.json") + + +def test_from_a_single_collection_get_locations_within_a_bbox(): + collection_id = "observations" + bbox = "5.0,52.0,6.0,52.1" + actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}/locations?bbox={bbox}") + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response( + actual_response, "response/collection/locations/200/locations_within_a_bbox.json" + ) + + +def test_from_a_single_collection_get_a_single_location(): + collection_id = "observations" + location_id = "06260" + parameters = "dd,ff,rh" + datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" + actual_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" + f"?parameter-name={parameters}&datetime={datetime}" + ) + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response( + actual_response, "response/collection/locations/200/single_location_with_multiple_parameters.json" + ) + + +def test_from_a_single_collection_get_a_single_location_which_does_not_exist(): + collection_id = "observations" + location_id = "does-not-exist" + parameters = "does-not-exist" + actual_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}?parameter-name={parameters}" + ) + + actual_status_code_is_expected_status_code(actual_response, 404) + actual_response_is_expected_response(actual_response, "response/collection/locations/404/no_data_found.json") + + +def test_from_a_single_collection_get_a_single_position_with_multiple_parameters(): + collection_id = "observations" + coords = "POINT(5.179705 52.0988218)" + parameters = "dd,ff,rh" + datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" + actual_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/position" + f"?coords={coords}¶meter-name={parameters}&datetime={datetime}" + ) + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response( + actual_response, "response/collection/position/200/single_coordinate_with_multiple_parameters.json" + ) + + +def test_from_a_single_collection_get_an_area_with_multiple_parameters(): + collection_id = "observations" + coords = "POLYGON((5.0 52.0, 6.0 52.0,6.0 52.1,5.0 52.1, 5.0 52.0))" + parameters = "dd,ff,rh" + datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" + actual_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/area" + f"?coords={coords}¶meter-name={parameters}&datetime={datetime}" + ) + + actual_status_code_is_expected_status_code(actual_response, 200) + actual_response_is_expected_response( + actual_response, "response/collection/area/200/data_within_an_area_with_multiple_parameters.json" + ) From 7c3938fe97f5e2e6e4ff0ee8d64d9b7174c10206 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Thu, 30 Nov 2023 18:02:22 +0100 Subject: [PATCH 02/11] Ignore href because the url differs based on running it locally or in the docker compose. --- integration-test/test_api.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index 759fa75..a991327 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -18,12 +18,12 @@ def actual_status_code_is_expected_status_code(actual_response, expected_status_ assert actual_response.status_code == expected_status_code -def actual_response_is_expected_response(actual_response, expected_path): +def actual_response_is_expected_response(actual_response, expected_path, **kwargs): file_path = Path(Path(__file__).parent, expected_path).resolve() with open(file_path) as file: expected_json = json.load(file) - diff = DeepDiff(expected_json, actual_response.json(), ignore_order=True) + diff = DeepDiff(expected_json, actual_response.json(), ignore_order=True, **kwargs) assert diff == {} @@ -31,7 +31,9 @@ def test_get_all_collections(): actual_response = requests.get(url=BASE_URL + "/collections") actual_status_code_is_expected_status_code(actual_response, 200) - actual_response_is_expected_response(actual_response, "response/capabilities/200/all_collections.json") + actual_response_is_expected_response( + actual_response, "response/capabilities/200/all_collections.json", exclude_regex_paths=r".*\['href'\]$" + ) def test_get_a_single_existing_collection(): @@ -39,7 +41,9 @@ def test_get_a_single_existing_collection(): actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}") actual_status_code_is_expected_status_code(actual_response, 200) - actual_response_is_expected_response(actual_response, "response/metadata/200/single_collection.json") + actual_response_is_expected_response( + actual_response, "response/metadata/200/single_collection.json", exclude_regex_paths=r".*\['href'\]$" + ) def test_get_a_collection_which_does_not_exist(): From 2b5a8881a68860c136bde3db6b164b2a277cd92d Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 14:35:03 +0100 Subject: [PATCH 03/11] Compile requirements with 3.11. --- integration-test/requirements.txt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/integration-test/requirements.txt b/integration-test/requirements.txt index 20bb3b0..390448c 100644 --- a/integration-test/requirements.txt +++ b/integration-test/requirements.txt @@ -1,5 +1,5 @@ # -# This file is autogenerated by pip-compile with Python 3.10 +# This file is autogenerated by pip-compile with Python 3.11 # by the following command: # # pip-compile --no-emit-index-url @@ -10,13 +10,11 @@ charset-normalizer==3.3.2 # via requests deepdiff==6.7.1 # via -r requirements.in -exceptiongroup==1.2.0 - # via pytest grpcio==1.59.3 # via grpcio-tools grpcio-tools==1.59.3 # via -r requirements.in -idna==3.4 +idna==3.6 # via requests iniconfig==2.0.0 # via pytest @@ -32,8 +30,6 @@ pytest==7.4.3 # via -r requirements.in requests==2.31.0 # via -r requirements.in -tomli==2.0.1 - # via pytest urllib3==2.1.0 # via requests From f5b17ad8f7beb1196a1daac692e2c2af46b76906 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 14:35:34 +0100 Subject: [PATCH 04/11] Update regex. --- integration-test/test_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index a991327..eaa931e 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -32,7 +32,7 @@ def test_get_all_collections(): actual_status_code_is_expected_status_code(actual_response, 200) actual_response_is_expected_response( - actual_response, "response/capabilities/200/all_collections.json", exclude_regex_paths=r".*\['href'\]$" + actual_response, "response/capabilities/200/all_collections.json", exclude_regex_paths=r"\['href'\]$" ) @@ -42,7 +42,7 @@ def test_get_a_single_existing_collection(): actual_status_code_is_expected_status_code(actual_response, 200) actual_response_is_expected_response( - actual_response, "response/metadata/200/single_collection.json", exclude_regex_paths=r".*\['href'\]$" + actual_response, "response/metadata/200/single_collection.json", exclude_regex_paths=r"\['href'\]$" ) From 09975eadcd6e3da12e24505978099b68e659a513 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 14:38:06 +0100 Subject: [PATCH 05/11] Remove ignore order from deepdiff. --- integration-test/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index eaa931e..40ccfae 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -23,7 +23,7 @@ def actual_response_is_expected_response(actual_response, expected_path, **kwarg with open(file_path) as file: expected_json = json.load(file) - diff = DeepDiff(expected_json, actual_response.json(), ignore_order=True, **kwargs) + diff = DeepDiff(expected_json, actual_response.json(), **kwargs) assert diff == {} From 2097ce1f978c1cda61b5f695e3bd744786d3f071 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 15:12:19 +0100 Subject: [PATCH 06/11] Variance in datetime parameter. --- ...thin_an_area_with_multiple_parameters.json | 132 ++++++++---------- ...gle_location_with_multiple_parameters.json | 54 ++++--- integration-test/test_api.py | 4 +- 3 files changed, 89 insertions(+), 101 deletions(-) diff --git a/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json b/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json index 3f1d3b8..9d4e190 100644 --- a/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json +++ b/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json @@ -19,14 +19,13 @@ }, "t": { "values": [ - "2022-12-31T00:50:00Z", - "2022-12-31T01:00:00Z", - "2022-12-31T01:10:00Z", - "2022-12-31T01:20:00Z", - "2022-12-31T01:30:00Z", - "2022-12-31T01:40:00Z", - "2022-12-31T01:50:00Z", - "2022-12-31T02:00:00Z" + "2022-12-31T22:50:00Z", + "2022-12-31T23:00:00Z", + "2022-12-31T23:10:00Z", + "2022-12-31T23:20:00Z", + "2022-12-31T23:30:00Z", + "2022-12-31T23:40:00Z", + "2022-12-31T23:50:00Z" ] } }, @@ -103,19 +102,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 236.4, - 240.3, - 250.4, - 239.2, - 232.7, - 241.4, - 247.9, - 248.1 + 214.8, + 215, + 212.5, + 213.9, + 216.6, + 213.9, + 212.3 ] }, "ff": { @@ -127,19 +125,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 5.38, - 5.25, - 4.04, - 4.06, - 4.41, - 4.31, - 4.57, - 4.37 + 10.68, + 8.84, + 9.09, + 8.64, + 8.72, + 9.59, + 10.7 ] }, "rh": { @@ -151,19 +148,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 97, - 96, - 96, - 96, - 96, - 97, - 96, - 95 + 56, + 56, + 55, + 58, + 56, + 56, + 57 ] } } @@ -186,14 +182,13 @@ }, "t": { "values": [ - "2022-12-31T00:50:00Z", - "2022-12-31T01:00:00Z", - "2022-12-31T01:10:00Z", - "2022-12-31T01:20:00Z", - "2022-12-31T01:30:00Z", - "2022-12-31T01:40:00Z", - "2022-12-31T01:50:00Z", - "2022-12-31T02:00:00Z" + "2022-12-31T22:50:00Z", + "2022-12-31T23:00:00Z", + "2022-12-31T23:10:00Z", + "2022-12-31T23:20:00Z", + "2022-12-31T23:30:00Z", + "2022-12-31T23:40:00Z", + "2022-12-31T23:50:00Z" ] } }, @@ -270,19 +265,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 237.9, - 235.4, - 240, - 243.2, - 243.2, - 240, - 239.9, - 229.5 + 211.5, + 211.2, + 209.6, + 213.9, + 216.3, + 213.7, + 219.1 ] }, "ff": { @@ -294,19 +288,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 4.26, - 4.72, - 4.1, - 3.79, - 4.2, - 3.83, - 3.69, - 3.3 + 8.37, + 7.71, + 8.35, + 8.45, + 8.95, + 9.17, + 9.4 ] }, "rh": { @@ -318,19 +311,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 95, - 94, - 94, - 94, - 94, - 93, - 93, - 94 + 58, + 58, + 58, + 58, + 58, + 58, + 59 ] } } diff --git a/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json index ee1da91..e9dc6d8 100644 --- a/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json +++ b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json @@ -16,14 +16,13 @@ }, "t": { "values": [ + "2022-12-31T00:00:00Z", + "2022-12-31T00:10:00Z", + "2022-12-31T00:20:00Z", + "2022-12-31T00:30:00Z", + "2022-12-31T00:40:00Z", "2022-12-31T00:50:00Z", - "2022-12-31T01:00:00Z", - "2022-12-31T01:10:00Z", - "2022-12-31T01:20:00Z", - "2022-12-31T01:30:00Z", - "2022-12-31T01:40:00Z", - "2022-12-31T01:50:00Z", - "2022-12-31T02:00:00Z" + "2022-12-31T01:00:00Z" ] } }, @@ -100,19 +99,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ + 224.3, + 226, + 228.3, + 230.3, + 234.9, 237.9, - 235.4, - 240, - 243.2, - 243.2, - 240, - 239.9, - 229.5 + 235.4 ] }, "ff": { @@ -124,19 +122,18 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ - 4.26, - 4.72, - 4.1, - 3.79, + 4.95, + 4.43, + 4.35, + 3.77, 4.2, - 3.83, - 3.69, - 3.3 + 4.26, + 4.72 ] }, "rh": { @@ -148,18 +145,17 @@ "x" ], "shape": [ - 8, + 7, 1, 1 ], "values": [ 95, 94, - 94, - 94, - 94, - 93, - 93, + 95, + 95, + 95, + 95, 94 ] } diff --git a/integration-test/test_api.py b/integration-test/test_api.py index 40ccfae..c3ce080 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -69,7 +69,7 @@ def test_from_a_single_collection_get_a_single_location(): collection_id = "observations" location_id = "06260" parameters = "dd,ff,rh" - datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" + datetime = "../2022-12-31T01:10:00Z" actual_response = requests.get( url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" f"?parameter-name={parameters}&datetime={datetime}" @@ -113,7 +113,7 @@ def test_from_a_single_collection_get_an_area_with_multiple_parameters(): collection_id = "observations" coords = "POLYGON((5.0 52.0, 6.0 52.0,6.0 52.1,5.0 52.1, 5.0 52.0))" parameters = "dd,ff,rh" - datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" + datetime = "2022-12-31T22:50:00Z/.." actual_response = requests.get( url=BASE_URL + f"/collections/{collection_id}/area" f"?coords={coords}¶meter-name={parameters}&datetime={datetime}" From c1c2e275a9175152cfc26cf8e4d8a13e8f0cf5b2 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 15:16:40 +0100 Subject: [PATCH 07/11] Remove function. --- integration-test/test_api.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index c3ce080..fc33d76 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -14,10 +14,6 @@ BASE_URL = os.environ.get("BASE_URL", "http://localhost:8008") -def actual_status_code_is_expected_status_code(actual_response, expected_status_code): - assert actual_response.status_code == expected_status_code - - def actual_response_is_expected_response(actual_response, expected_path, **kwargs): file_path = Path(Path(__file__).parent, expected_path).resolve() with open(file_path) as file: @@ -30,7 +26,7 @@ def actual_response_is_expected_response(actual_response, expected_path, **kwarg def test_get_all_collections(): actual_response = requests.get(url=BASE_URL + "/collections") - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/capabilities/200/all_collections.json", exclude_regex_paths=r"\['href'\]$" ) @@ -40,7 +36,7 @@ def test_get_a_single_existing_collection(): collection_id = "observations" actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}") - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/metadata/200/single_collection.json", exclude_regex_paths=r"\['href'\]$" ) @@ -50,7 +46,7 @@ def test_get_a_collection_which_does_not_exist(): collection_id = "does-not-exist" actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}") - actual_status_code_is_expected_status_code(actual_response, 404) + assert actual_response.status_code == 404 actual_response_is_expected_response(actual_response, "response/metadata/404/not_found.json") @@ -59,7 +55,7 @@ def test_from_a_single_collection_get_locations_within_a_bbox(): bbox = "5.0,52.0,6.0,52.1" actual_response = requests.get(url=BASE_URL + f"/collections/{collection_id}/locations?bbox={bbox}") - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/collection/locations/200/locations_within_a_bbox.json" ) @@ -75,7 +71,7 @@ def test_from_a_single_collection_get_a_single_location(): f"?parameter-name={parameters}&datetime={datetime}" ) - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/collection/locations/200/single_location_with_multiple_parameters.json" ) @@ -89,7 +85,7 @@ def test_from_a_single_collection_get_a_single_location_which_does_not_exist(): url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}?parameter-name={parameters}" ) - actual_status_code_is_expected_status_code(actual_response, 404) + assert actual_response.status_code == 404 actual_response_is_expected_response(actual_response, "response/collection/locations/404/no_data_found.json") @@ -103,7 +99,7 @@ def test_from_a_single_collection_get_a_single_position_with_multiple_parameters f"?coords={coords}¶meter-name={parameters}&datetime={datetime}" ) - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/collection/position/200/single_coordinate_with_multiple_parameters.json" ) @@ -119,7 +115,7 @@ def test_from_a_single_collection_get_an_area_with_multiple_parameters(): f"?coords={coords}¶meter-name={parameters}&datetime={datetime}" ) - actual_status_code_is_expected_status_code(actual_response, 200) + assert actual_response.status_code == 200 actual_response_is_expected_response( actual_response, "response/collection/area/200/data_within_an_area_with_multiple_parameters.json" ) From f18e9a8a9dde490dfa63b2018995d3d0f355545f Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 15:30:39 +0100 Subject: [PATCH 08/11] Add one second to the end_datetime so that the end_datetime is included in the interval. --- api/main.py | 3 ++- ...ngle_location_with_multiple_parameters.json | 16 ++++++++++------ ...le_coordinate_with_multiple_parameters.json | 18 +++++++++++------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/api/main.py b/api/main.py index de70c37..2313b9f 100644 --- a/api/main.py +++ b/api/main.py @@ -140,7 +140,8 @@ def get_datetime_range(datetime_string: str | None) -> Tuple[Timestamp, Timestam else: start_datetime.FromDatetime(datetime.min) if datetimes[1] != "..": - end_datetime.FromDatetime(aware_datetime_type_adapter.validate_python(datetimes[1])) + # HACK add one second so that the end_datetime is included in the interval. + end_datetime.FromDatetime(aware_datetime_type_adapter.validate_python(datetimes[1]) + timedelta(seconds=1)) else: end_datetime.FromDatetime(datetime.max) diff --git a/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json index e9dc6d8..1666c0a 100644 --- a/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json +++ b/integration-test/response/collection/locations/200/single_location_with_multiple_parameters.json @@ -22,7 +22,8 @@ "2022-12-31T00:30:00Z", "2022-12-31T00:40:00Z", "2022-12-31T00:50:00Z", - "2022-12-31T01:00:00Z" + "2022-12-31T01:00:00Z", + "2022-12-31T01:10:00Z" ] } }, @@ -99,7 +100,7 @@ "x" ], "shape": [ - 7, + 8, 1, 1 ], @@ -110,7 +111,8 @@ 230.3, 234.9, 237.9, - 235.4 + 235.4, + 240 ] }, "ff": { @@ -122,7 +124,7 @@ "x" ], "shape": [ - 7, + 8, 1, 1 ], @@ -133,7 +135,8 @@ 3.77, 4.2, 4.26, - 4.72 + 4.72, + 4.1 ] }, "rh": { @@ -145,7 +148,7 @@ "x" ], "shape": [ - 7, + 8, 1, 1 ], @@ -156,6 +159,7 @@ 95, 95, 95, + 94, 94 ] } diff --git a/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json b/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json index ee1da91..27a5ace 100644 --- a/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json +++ b/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json @@ -23,7 +23,8 @@ "2022-12-31T01:30:00Z", "2022-12-31T01:40:00Z", "2022-12-31T01:50:00Z", - "2022-12-31T02:00:00Z" + "2022-12-31T02:00:00Z", + "2022-12-31T02:10:00Z" ] } }, @@ -100,7 +101,7 @@ "x" ], "shape": [ - 8, + 9, 1, 1 ], @@ -112,7 +113,8 @@ 243.2, 240, 239.9, - 229.5 + 229.5, + 223.2 ] }, "ff": { @@ -124,7 +126,7 @@ "x" ], "shape": [ - 8, + 9, 1, 1 ], @@ -136,7 +138,8 @@ 4.2, 3.83, 3.69, - 3.3 + 3.3, + 4.04 ] }, "rh": { @@ -148,7 +151,7 @@ "x" ], "shape": [ - 8, + 9, 1, 1 ], @@ -160,7 +163,8 @@ 94, 93, 93, - 94 + 94, + 93 ] } } From 5f78d243109e90b71b160cd2a778e5fb1e373233 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 15:42:48 +0100 Subject: [PATCH 09/11] Variance in the use of parameters. --- ...a_within_an_area_with_two_parameters.json} | 85 --------------- ...single_coordinate_with_one_parameter.json} | 102 +++--------------- integration-test/test_api.py | 12 +-- 3 files changed, 19 insertions(+), 180 deletions(-) rename integration-test/response/collection/area/200/{data_within_an_area_with_multiple_parameters.json => data_within_an_area_with_two_parameters.json} (77%) rename integration-test/response/collection/position/200/{single_coordinate_with_multiple_parameters.json => single_coordinate_with_one_parameter.json} (50%) diff --git a/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json b/integration-test/response/collection/area/200/data_within_an_area_with_two_parameters.json similarity index 77% rename from integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json rename to integration-test/response/collection/area/200/data_within_an_area_with_two_parameters.json index 9d4e190..1878503 100644 --- a/integration-test/response/collection/area/200/data_within_an_area_with_multiple_parameters.json +++ b/integration-test/response/collection/area/200/data_within_an_area_with_two_parameters.json @@ -52,19 +52,6 @@ ] }, "parameters": { - "dd": { - "type": "Parameter", - "observedProperty": { - "label": { - "en": "dd" - } - }, - "unit": { - "label": { - "en": "degree" - } - } - }, "ff": { "type": "Parameter", "observedProperty": { @@ -93,29 +80,6 @@ } }, "ranges": { - "dd": { - "type": "NdArray", - "dataType": "float", - "axisNames": [ - "t", - "y", - "x" - ], - "shape": [ - 7, - 1, - 1 - ], - "values": [ - 214.8, - 215, - 212.5, - 213.9, - 216.6, - 213.9, - 212.3 - ] - }, "ff": { "type": "NdArray", "dataType": "float", @@ -215,19 +179,6 @@ ] }, "parameters": { - "dd": { - "type": "Parameter", - "observedProperty": { - "label": { - "en": "dd" - } - }, - "unit": { - "label": { - "en": "degree" - } - } - }, "ff": { "type": "Parameter", "observedProperty": { @@ -256,29 +207,6 @@ } }, "ranges": { - "dd": { - "type": "NdArray", - "dataType": "float", - "axisNames": [ - "t", - "y", - "x" - ], - "shape": [ - 7, - 1, - 1 - ], - "values": [ - 211.5, - 211.2, - 209.6, - 213.9, - 216.3, - 213.7, - 219.1 - ] - }, "ff": { "type": "NdArray", "dataType": "float", @@ -329,19 +257,6 @@ } ], "parameters": { - "dd": { - "type": "Parameter", - "observedProperty": { - "label": { - "en": "dd" - } - }, - "unit": { - "label": { - "en": "degree" - } - } - }, "ff": { "type": "Parameter", "observedProperty": { diff --git a/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json b/integration-test/response/collection/position/200/single_coordinate_with_one_parameter.json similarity index 50% rename from integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json rename to integration-test/response/collection/position/200/single_coordinate_with_one_parameter.json index 27a5ace..f8b3846 100644 --- a/integration-test/response/collection/position/200/single_coordinate_with_multiple_parameters.json +++ b/integration-test/response/collection/position/200/single_coordinate_with_one_parameter.json @@ -51,98 +51,22 @@ ] }, "parameters": { - "dd": { + "tn": { "type": "Parameter", "observedProperty": { "label": { - "en": "dd" + "en": "tn" } }, "unit": { "label": { - "en": "degree" - } - } - }, - "ff": { - "type": "Parameter", - "observedProperty": { - "label": { - "en": "ff" - } - }, - "unit": { - "label": { - "en": "m s-1" - } - } - }, - "rh": { - "type": "Parameter", - "observedProperty": { - "label": { - "en": "rh" - } - }, - "unit": { - "label": { - "en": "%" + "en": "degrees Celsius" } } } }, "ranges": { - "dd": { - "type": "NdArray", - "dataType": "float", - "axisNames": [ - "t", - "y", - "x" - ], - "shape": [ - 9, - 1, - 1 - ], - "values": [ - 237.9, - 235.4, - 240, - 243.2, - 243.2, - 240, - 239.9, - 229.5, - 223.2 - ] - }, - "ff": { - "type": "NdArray", - "dataType": "float", - "axisNames": [ - "t", - "y", - "x" - ], - "shape": [ - 9, - 1, - 1 - ], - "values": [ - 4.26, - 4.72, - 4.1, - 3.79, - 4.2, - 3.83, - 3.69, - 3.3, - 4.04 - ] - }, - "rh": { + "tn": { "type": "NdArray", "dataType": "float", "axisNames": [ @@ -156,15 +80,15 @@ 1 ], "values": [ - 95, - 94, - 94, - 94, - 94, - 93, - 93, - 94, - 93 + 12.1, + 12, + 12, + 11.9, + 11.9, + 11.8, + 11.8, + 11.7, + 11.7 ] } } diff --git a/integration-test/test_api.py b/integration-test/test_api.py index fc33d76..f78067c 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -89,10 +89,10 @@ def test_from_a_single_collection_get_a_single_location_which_does_not_exist(): actual_response_is_expected_response(actual_response, "response/collection/locations/404/no_data_found.json") -def test_from_a_single_collection_get_a_single_position_with_multiple_parameters(): +def test_from_a_single_collection_get_a_single_position_with_one_parameter(): collection_id = "observations" coords = "POINT(5.179705 52.0988218)" - parameters = "dd,ff,rh" + parameters = "tn" datetime = "2022-12-31T00:50:00Z/2022-12-31T02:10:00Z" actual_response = requests.get( url=BASE_URL + f"/collections/{collection_id}/position" @@ -101,14 +101,14 @@ def test_from_a_single_collection_get_a_single_position_with_multiple_parameters assert actual_response.status_code == 200 actual_response_is_expected_response( - actual_response, "response/collection/position/200/single_coordinate_with_multiple_parameters.json" + actual_response, "response/collection/position/200/single_coordinate_with_one_parameter.json" ) -def test_from_a_single_collection_get_an_area_with_multiple_parameters(): +def test_from_a_single_collection_get_an_area_with_two_parameters(): collection_id = "observations" coords = "POLYGON((5.0 52.0, 6.0 52.0,6.0 52.1,5.0 52.1, 5.0 52.0))" - parameters = "dd,ff,rh" + parameters = " rh, ff " datetime = "2022-12-31T22:50:00Z/.." actual_response = requests.get( url=BASE_URL + f"/collections/{collection_id}/area" @@ -117,5 +117,5 @@ def test_from_a_single_collection_get_an_area_with_multiple_parameters(): assert actual_response.status_code == 200 actual_response_is_expected_response( - actual_response, "response/collection/area/200/data_within_an_area_with_multiple_parameters.json" + actual_response, "response/collection/area/200/data_within_an_area_with_two_parameters.json" ) From 63927ba98ce4288f31138a99e2474c15c6045e51 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 15:53:48 +0100 Subject: [PATCH 10/11] Test the order of parameters. --- integration-test/test_api.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index f78067c..157f307 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -76,6 +76,20 @@ def test_from_a_single_collection_get_a_single_location(): actual_response, "response/collection/locations/200/single_location_with_multiple_parameters.json" ) + # Test that we do not care about whitespace, by adding whitespace to the parameter string. + # Test that we do not care about the parameter order, by changing the order of parameter in the parameter string. + # Will return the same response as the first request. + parameters_2 = " rh, ff, dd " + actual_response_2 = requests.get( + url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" + f"?parameter-name={parameters_2}&datetime={datetime}" + ) + + assert actual_response_2.status_code == 200 + actual_response_is_expected_response( + actual_response_2, "response/collection/locations/200/single_location_with_multiple_parameters.json" + ) + def test_from_a_single_collection_get_a_single_location_which_does_not_exist(): collection_id = "observations" From 327aa1e90e1c0f8ed1805fcd8a64278182f36dd2 Mon Sep 17 00:00:00 2001 From: Jeffrey Vervoort Date: Fri, 1 Dec 2023 17:39:12 +0100 Subject: [PATCH 11/11] Split the parameter order test from the other test. --- integration-test/test_api.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/integration-test/test_api.py b/integration-test/test_api.py index 157f307..4b02e68 100644 --- a/integration-test/test_api.py +++ b/integration-test/test_api.py @@ -76,20 +76,29 @@ def test_from_a_single_collection_get_a_single_location(): actual_response, "response/collection/locations/200/single_location_with_multiple_parameters.json" ) - # Test that we do not care about whitespace, by adding whitespace to the parameter string. - # Test that we do not care about the parameter order, by changing the order of parameter in the parameter string. - # Will return the same response as the first request. - parameters_2 = " rh, ff, dd " - actual_response_2 = requests.get( - url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" - f"?parameter-name={parameters_2}&datetime={datetime}" + +def test_that_the_order_of_the_parameters_in_the_response_is_always_the_same(): + """Test that we do not care about the order of parameters passed in the query. + By comparing two requests with the same parameters but in a different sequence. + The first request returns the same response as the second request. + """ + collection_id = "observations" + location_id = "06260" + parameters = " dd, ff , rh" + first_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" f"?parameter-name={parameters}" ) - assert actual_response_2.status_code == 200 - actual_response_is_expected_response( - actual_response_2, "response/collection/locations/200/single_location_with_multiple_parameters.json" + parameters_2 = " rh, ff, dd " + second_response = requests.get( + url=BASE_URL + f"/collections/{collection_id}/locations/{location_id}" f"?parameter-name={parameters_2}" ) + assert first_response.status_code == 200 + assert second_response.status_code == 200 + diff = DeepDiff(first_response.json(), second_response.json()) + assert diff == {} + def test_from_a_single_collection_get_a_single_location_which_does_not_exist(): collection_id = "observations"