From e249d356674d8c536d9298ba14d52af981652ca4 Mon Sep 17 00:00:00 2001 From: Anika Weinmann <37300249+anikaweinmann@users.noreply.github.com> Date: Mon, 1 Aug 2022 14:09:02 +0200 Subject: [PATCH] Fix Tests (#20) * Fix sampling endpoint by removing region setting, because actinia users have a cell limit * Add required GRASS GIS addon to README.md * adding some examples * fix some tests Co-authored-by: anikaweinmann --- README.md | 4 + docker/actinia-plugin-tests/Dockerfile | 10 +- docker/actinia-plugin-tests/actinia-test.cfg | 17 +-- examples/area.geojson | 25 ++++ examples/area2.geojson | 25 ++++ examples/examples.md | 52 +++++++ examples/points.geojson | 1 + examples/points.json | 1 + examples/points2.json | 1 + examples/points_where.json | 1 + setup.cfg | 2 +- src/actinia_statistic_plugin/endpoints.py | 2 +- .../ephemeral_raster_area_stats_univar.py | 3 + .../raster_sampling.py | 2 +- .../response_models.py | 2 +- .../strds_sampling_geojson.py | 3 + .../vector_sampling.py | 13 +- tests/test_raster_area_stats.py | 33 +++-- tests/test_raster_area_stats_univar.py | 86 +++++------- tests/test_raster_sample.py | 2 +- tests/test_strds_area_stats.py | 95 ++++++------- tests/test_strds_sample.py | 131 +++++++----------- tests/test_vector_sample.py | 79 +++++------ 23 files changed, 310 insertions(+), 280 deletions(-) create mode 100644 examples/area.geojson create mode 100644 examples/area2.geojson create mode 100644 examples/examples.md create mode 100644 examples/points.geojson create mode 100644 examples/points.json create mode 100644 examples/points2.json create mode 100644 examples/points_where.json diff --git a/README.md b/README.md index c1f7470..1a1563c 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,10 @@ python3 setup.py install After installation set the plugin name in the actinia core configuration and restart the actinia core server. +### Required GRASS GIS Addons + +The statistic plugin needs the GRASS GIS addon [t.rast.sample](https://github.com/mundialis/t.rast.sample) to be installed in actinia. + ## Testing locally diff --git a/docker/actinia-plugin-tests/Dockerfile b/docker/actinia-plugin-tests/Dockerfile index 91272e5..1ff9813 100644 --- a/docker/actinia-plugin-tests/Dockerfile +++ b/docker/actinia-plugin-tests/Dockerfile @@ -1,4 +1,4 @@ -FROM mundialis/actinia-core:latest as actinia_test +FROM mundialis/actinia:latest as actinia_test LABEL authors="Carmen Tawalika,Anika Weinmann" LABEL maintainer="tawalika@mundialis.de,weinmann@mundialis.de" @@ -18,10 +18,10 @@ RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_08_mic rm -f nc_spm_08_micro.zip && \ mv nc_spm_08_micro /actinia_core/grassdb/nc_spm_08 RUN grass -e -c 'EPSG:4326' /actinia_core/grassdb/latlong_wgs84 -RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_mapset_modis2015_2016_lst.zip && \ - unzip nc_spm_mapset_modis2015_2016_lst.zip && \ - rm -f nc_spm_mapset_modis2015_2016_lst.zip && \ - mv modis_lst /actinia_core/grassdb/nc_spm_08/modis_lst +RUN wget --quiet https://grass.osgeo.org/sampledata/north_carolina/nc_spm_mapset_modis2015_2016_lst_grass8.zip && \ + unzip nc_spm_mapset_modis2015_2016_lst_grass8.zip && \ + rm -f nc_spm_mapset_modis2015_2016_lst_grass8.zip && \ + mv modis_lst /actinia_core/grassdb/nc_spm_08/modis_lst RUN chown -R 1001:1001 /actinia_core/grassdb/nc_spm_08/modis_lst && chmod -R g+w /actinia_core/grassdb/nc_spm_08/modis_lst # copy needed files and configs for test diff --git a/docker/actinia-plugin-tests/actinia-test.cfg b/docker/actinia-plugin-tests/actinia-test.cfg index 004a9c9..1a08ad4 100644 --- a/docker/actinia-plugin-tests/actinia-test.cfg +++ b/docker/actinia-plugin-tests/actinia-test.cfg @@ -13,12 +13,6 @@ grass_default_location = nc_spm_08 plugins = [] force_https_urls = True -[LIMITS] -max_cell_limit = 22500000 -process_time_limt = 60 -process_num_limit = 20 -number_of_workers = 3 - [REDIS] redis_server_url = localhost redis_server_port = 6379 @@ -27,17 +21,8 @@ redis_queue_server_port = 6379 worker_queue_name = actinia_job worker_logfile = /actinia_core/workspace/tmp/actinia_worker_test.log -[LOGGING] -log_interface = fluentd -log_fluent_host = fluentd -log_fluent_port = 24224 -log_level = 1 - [MISC] tmp_workdir = /actinia_core/workspace/tmp download_cache = /actinia_core/workspace/download_cache secret_key = token_signing_key_changeme - -[MANAGEMENT] -default_user = user -default_user_group = group +save_interim_results = False diff --git a/examples/area.geojson b/examples/area.geojson new file mode 100644 index 0000000..9ad3d0c --- /dev/null +++ b/examples/area.geojson @@ -0,0 +1,25 @@ +{ + "type": "FeatureCollection", + "crs": { + "type": "name", + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"} + }, + "features": [ + { + "type": "Feature", + "properties": {"fid": "test"}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [330000.0, 65000.0], + [337000.0, 65000.0], + [337000.0, 647000.0], + [330000.0, 647000.0], + [330000.0, 65000.0] + ] + ] + } + } + ] +} diff --git a/examples/area2.geojson b/examples/area2.geojson new file mode 100644 index 0000000..7a3f895 --- /dev/null +++ b/examples/area2.geojson @@ -0,0 +1,25 @@ +{ + "type": "FeatureCollection", + "crs": { + "type": "name", + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"} + }, + "features": [ + { + "type": "Feature", + "properties": {"fid": "test"}, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [635000.0, 220000.0], + [637000.0, 220000.0], + [637000.0, 221000.0], + [635000.0, 221000.0], + [635000.0, 220000.0] + ] + ] + } + } + ] +} diff --git a/examples/examples.md b/examples/examples.md new file mode 100644 index 0000000..aa7d432 --- /dev/null +++ b/examples/examples.md @@ -0,0 +1,52 @@ +# Examples +``` +BASE_URL="http://localhost:8088/api/v3" +AUTH='actinia-gdi:actinia-gdi' +``` + +## STRDS sampling + +Sampling STRDS at point coordinates +``` +# async +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/sampling_async -d @points.json + +# sync +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/sampling_sync -d @points.json +``` + +Sampling STRDS at point coordinates by filtering the time of the STRDS +``` +# async +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/sampling_async -d @points_where.json + +# sync +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/sampling_sync -d @points_where.json +``` + +Sampling STRDS at Points in a GeoJson +``` +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/sampling_sync_geojson -d @points.geojson +``` + +Sampling STRDS by area +``` +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/modis_lst/strds/LST_Day_monthly/timestamp/2016-01-01T00:00:00/area_stats_sync -d @area.geojson +``` + +## Raster sampling +Raster statistics of area +``` +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/landuse96_28m/area_stats_sync -d @area2.geojson +``` + +Univar raster statistics of area +``` +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/area_stats_univar_sync -d @area2.geojson +``` + + +## Vector sampling +``` +curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/vector_layers/nc_state/sampling_async -d @points2.json +``` diff --git a/examples/points.geojson b/examples/points.geojson new file mode 100644 index 0000000..12bb521 --- /dev/null +++ b/examples/points.geojson @@ -0,0 +1 @@ +{"type": "FeatureCollection", "crs": {"type": "name", "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"}}, "features": [{"type": "Feature", "properties": {"cat": 1}, "geometry": {"type": "Point", "coordinates": [330000.0, 65000.0]}}, {"type": "Feature", "properties": {"cat": 2}, "geometry": {"type": "Point", "coordinates": [500000.0, 500000.0]}}]} diff --git a/examples/points.json b/examples/points.json new file mode 100644 index 0000000..9a7a7c8 --- /dev/null +++ b/examples/points.json @@ -0,0 +1 @@ +{"points": [["a", "330000.0", "65000.0"], ["b", "300000.0", "60000.0"], ["c", "500000.0", "500000.0"]]} diff --git a/examples/points2.json b/examples/points2.json new file mode 100644 index 0000000..70c3986 --- /dev/null +++ b/examples/points2.json @@ -0,0 +1 @@ +{"points": [["p1", "330000.0", "65000.0"],["p2", "331000.0", "649000.0"]]} diff --git a/examples/points_where.json b/examples/points_where.json new file mode 100644 index 0000000..eaea387 --- /dev/null +++ b/examples/points_where.json @@ -0,0 +1 @@ +{"points": [["a", "330000.0", "65000.0"], ["b", "300000.0", "60000.0"], ["c", "500000.0", "500000.0"]], "where": "start_time >'2016-01-01'"} diff --git a/setup.cfg b/setup.cfg index b118ea3..eadb500 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,7 +50,7 @@ addopts = tests # e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml # in order to write a coverage file that can be read by Jenkins. addopts = - --cov actinia_core --cov-report term-missing + --cov actinia_statistic_plugin --cov-report term-missing --verbose --tb=line -x norecursedirs = dist diff --git a/src/actinia_statistic_plugin/endpoints.py b/src/actinia_statistic_plugin/endpoints.py index a561b81..7b5c362 100644 --- a/src/actinia_statistic_plugin/endpoints.py +++ b/src/actinia_statistic_plugin/endpoints.py @@ -40,7 +40,7 @@ __license__ = "GPLv3" __author__ = "Sören Gebbert, Markus Neteler" __copyright__ = ( - "Copyright 2016-present, Sören Gebbert and mundialis GmbH & Co. KG" + "Copyright 2016-2022, Sören Gebbert and mundialis GmbH & Co. KG" ) diff --git a/src/actinia_statistic_plugin/ephemeral_raster_area_stats_univar.py b/src/actinia_statistic_plugin/ephemeral_raster_area_stats_univar.py index a3a2916..ab0d44d 100644 --- a/src/actinia_statistic_plugin/ephemeral_raster_area_stats_univar.py +++ b/src/actinia_statistic_plugin/ephemeral_raster_area_stats_univar.py @@ -100,6 +100,9 @@ def _execute(self, location_name, mapset_name, raster_name): map_name=raster_name, ) if rdc: + # # for debugging + # processing = AsyncEphemeralRasterAreaStatsUnivar(rdc) + # processing.run() enqueue_job(self.job_timeout, start_job, rdc) return rdc diff --git a/src/actinia_statistic_plugin/raster_sampling.py b/src/actinia_statistic_plugin/raster_sampling.py index 1d53bf2..08e71aa 100644 --- a/src/actinia_statistic_plugin/raster_sampling.py +++ b/src/actinia_statistic_plugin/raster_sampling.py @@ -24,7 +24,7 @@ __license__ = "GPLv3" __author__ = "Markus Neteler" __copyright__ = ( - "Copyright 2022-present, Markus Neteler and mundialis GmbH & Co. KG" + "Copyright 2022-2022, Markus Neteler and mundialis GmbH & Co. KG" ) diff --git a/src/actinia_statistic_plugin/response_models.py b/src/actinia_statistic_plugin/response_models.py index c9ecac5..34f16cf 100644 --- a/src/actinia_statistic_plugin/response_models.py +++ b/src/actinia_statistic_plugin/response_models.py @@ -6,7 +6,7 @@ __license__ = "GPLv3" __author__ = "Sören Gebbert, Markus Neteler" -__copyright__ = "Copyright 2016-present, Sören Gebbert, Markus Neteler and " +__copyright__ = "Copyright 2016-2022, Sören Gebbert, Markus Neteler and " "mundialis GmbH & Co. KG" diff --git a/src/actinia_statistic_plugin/strds_sampling_geojson.py b/src/actinia_statistic_plugin/strds_sampling_geojson.py index 956680f..997b9d0 100644 --- a/src/actinia_statistic_plugin/strds_sampling_geojson.py +++ b/src/actinia_statistic_plugin/strds_sampling_geojson.py @@ -253,6 +253,9 @@ def _execute(self, location_name, mapset_name, strds_name): map_name=strds_name, ) if rdc: + # # for debugging + # processing = AsyncEphemeralSTRDSSamplingGeoJSON(rdc) + # processing.run() enqueue_job(self.job_timeout, start_job, rdc) return rdc diff --git a/src/actinia_statistic_plugin/vector_sampling.py b/src/actinia_statistic_plugin/vector_sampling.py index 139f783..30fa04b 100644 --- a/src/actinia_statistic_plugin/vector_sampling.py +++ b/src/actinia_statistic_plugin/vector_sampling.py @@ -23,7 +23,7 @@ __license__ = "GPLv3" __author__ = "Markus Neteler" __copyright__ = ( - "Copyright 2022-present, Markus Neteler and mundialis GmbH & Co. KG" + "Copyright 2022-2022, Markus Neteler and mundialis GmbH & Co. KG" ) @@ -193,17 +193,6 @@ def _execute(self): pc = { "list": [ - { - "id": "g_region", - "module": "g.region", - "inputs": [ - { - "param": "vector", - "value": "%s@%s" % (vector_name, self.mapset_name), - } - ], - "flags": "p", - }, { "id": "v_what", "module": "v.what", diff --git a/tests/test_raster_area_stats.py b/tests/test_raster_area_stats.py index 639281b..f01b41d 100644 --- a/tests/test_raster_area_stats.py +++ b/tests/test_raster_area_stats.py @@ -10,11 +10,14 @@ from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX __license__ = "GPLv3" -__author__ = "Sören Gebbert" -__copyright__ = "Copyright 2016, Sören Gebbert" -__maintainer__ = "Soeren Gebbert" -__email__ = "soerengebbert@googlemail.com" - +__author__ = "Sören Gebbert, Anika Weinmann" +__copyright__ = "Copyright 2016-2022, Sören Gebbert and mundialis GmbH & Co.KG" +__maintainer__ = "mundialis GmbH & Co. KG" + +LOCATION = "nc_spm_08" +MAPSET = "PERMANENT" +RASTER = "landuse96_28m" +RASTER2 = "basin_50K" JSON = { "type": "FeatureCollection", "crs": { @@ -45,8 +48,8 @@ class RasterAreaStatsTestCase(ActiniaResourceTestCaseBase): def test_async_raster_area_stats_json(self): rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers" - "/landuse96_28m/area_stats_async", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/raster_layers" + f"/{RASTER}/area_stats_async", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -60,8 +63,8 @@ def test_async_raster_area_stats_json(self): def test_sync_raster_area_stats_1(self): rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers" - "/landuse96_28m/area_stats_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/raster_layers" + f"/{RASTER}/area_stats_sync", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -82,8 +85,8 @@ def test_sync_raster_area_stats_1(self): def test_sync_raster_area_stats_2(self): rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers" - "/basin_50K/area_stats_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/raster_layers" + f"/{RASTER2}/area_stats_sync", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -103,8 +106,8 @@ def test_sync_raster_area_stats_2(self): def test_sync_raster_area_stats_error_wrong_content_type(self): rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers" - "/basin_50K/area_stats_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/raster_layers" + f"/{RASTER}/area_stats_sync", headers=self.admin_auth_header, data="{}", content_type="application/json", @@ -121,8 +124,8 @@ def test_sync_raster_area_stats_error_wrong_content_type(self): def test_sync_raster_area_stats_error_wrong_request_missing_json(self): rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers" - "/towns/area_stats_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/raster_layers" + f"/{RASTER}/area_stats_sync", headers=self.admin_auth_header, data=None, content_type="application/json", diff --git a/tests/test_raster_area_stats_univar.py b/tests/test_raster_area_stats_univar.py index 20f4355..9194e13 100644 --- a/tests/test_raster_area_stats_univar.py +++ b/tests/test_raster_area_stats_univar.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- import unittest -# from flask.json import loads as json_load +from flask.json import loads as json_load from flask.json import dumps as json_dump try: @@ -10,69 +10,65 @@ __license__ = "GPLv3" -__author__ = "Sören Gebbert" -__copyright__ = "Copyright 2016, Sören Gebbert" -__maintainer__ = "Soeren Gebbert" -__email__ = "soerengebbert@googlemail.com" - - +__author__ = "Sören Gebbert, Anika Weinmann" +__copyright__ = "Copyright 2016-2022, Sören Gebbert and mundialis GmbH & Co.KG" +__maintainer__ = "mundialis GmbH & Co. KG" + +LOCATION = "nc_spm_08" +MAPSET = "PERMANENT" +RASTER = "elevation" +RASTER2 = "aspect" JSON = { "type": "FeatureCollection", "crs": { "type": "name", - "properties": {"name": "urn:ogc:def:crs:EPSG::3358"}, + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"} }, "features": [ { "type": "Feature", - "properties": {"fid": "swwake_10m.0"}, + "properties": {"fid": "test"}, "geometry": { "type": "Polygon", "coordinates": [ [ - [630000.0, 215000.0], - [630000.0, 228500.0], - [645000.0, 228500.0], - [645000.0, 215000.0], - [630000.0, 215000.0], + [635000.0, 220000.0], + [637000.0, 220000.0], + [637000.0, 221000.0], + [635000.0, 221000.0], + [635000.0, 220000.0] ] - ], - }, + ] + } } - ], + ] } class RasterAreaStatsTestCase(ActiniaResourceTestCaseBase): - """ + def test_async_raster_area_stats_json(self): rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/" - "area_stats_univar_async", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER}/area_stats_univar_async", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", ) - import pdb - - pdb.set_trace() rv = self.waitAsyncStatusAssertHTTP(rv, headers=self.admin_auth_header) value_list = rv["process_results"] - import pdb - pdb.set_trace() self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 2025000) + self.assertEqual(value_list[0]["raster_number"], 20000.0) + self.assertEqual(value_list[0]["raster_maximum"], 138.268508911133) def test_sync_raster_area_stats_1(self): rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/elevation/" - "area_stats_univar_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER}/area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -89,17 +85,14 @@ def test_sync_raster_area_stats_1(self): value_list = json_load(rv.data)["process_results"] self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 2025000) + self.assertEqual(value_list[0]["raster_number"], 20000.0) + self.assertEqual(value_list[0]["raster_maximum"], 138.268508911133) def test_sync_raster_area_stats_2(self): - import pdb - - pdb.set_trace() rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/towns/" - "area_stats_univar_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER2}/area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -116,15 +109,14 @@ def test_sync_raster_area_stats_2(self): value_list = json_load(rv.data)["process_results"] self.assertEqual(value_list[0]["cat"], "1") - self.assertEqual(value_list[0]["raster_number"], 2025000) - """ + self.assertEqual(value_list[0]["raster_number"], 20000.0) + self.assertEqual(value_list[0]["raster_maximum"], 359.995971679688) def test_sync_raster_area_stats_error_wrong_content_type(self): rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/" - "area_stats_univar_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER}/area_stats_univar_sync", headers=self.admin_auth_header, data=" This is no data", content_type="application/XML", @@ -141,9 +133,8 @@ def test_sync_raster_area_stats_error_wrong_content_type(self): def test_sync_raster_area_stats_module_error(self): rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/" - "area_stats_univar_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER}/area_stats_univar_sync", headers=self.admin_auth_header, data=json_dump({}), content_type="application/json", @@ -160,9 +151,8 @@ def test_sync_raster_area_stats_module_error(self): def test_sync_raster_area_stats_nodata_error(self): rv = self.server.post( - URL_PREFIX - + "/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/basin_50K/" - "area_stats_univar_sync", + f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" + f"raster_layers/{RASTER}/area_stats_univar_sync", headers=self.admin_auth_header, data=None, content_type="application/json", diff --git a/tests/test_raster_sample.py b/tests/test_raster_sample.py index ec93067..f63d02d 100644 --- a/tests/test_raster_sample.py +++ b/tests/test_raster_sample.py @@ -13,7 +13,7 @@ __license__ = "GPLv3" __author__ = "Markus Neteler" __copyright__ = ( - "Copyright 2022-present, Markus Neteler and mundialis GmbH & Co. KG" + "Copyright 2022-2022, Markus Neteler and mundialis GmbH & Co. KG" ) JSON = { diff --git a/tests/test_strds_area_stats.py b/tests/test_strds_area_stats.py index 7ce5d36..49ee24e 100644 --- a/tests/test_strds_area_stats.py +++ b/tests/test_strds_area_stats.py @@ -1,21 +1,18 @@ # -*- coding: utf-8 -*- import unittest -# import time -# from flask.json import loads as json_load -# from flask.json import dumps as json_dump -# -# try: -# from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX -# except Exception: -# from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +from flask.json import loads as json_load +from flask.json import dumps as json_dump + +try: + from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +except Exception: + from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX __license__ = "GPLv3" -__author__ = "Sören Gebbert" -__copyright__ = "Copyright 2016, Sören Gebbert" -__maintainer__ = "Soeren Gebbert" -__email__ = "soerengebbert@googlemail.com" +__author__ = "Sören Gebbert, Anika Weinmann" +__copyright__ = "Copyright 2016-2022, Sören Gebbert and mundialis GmbH & Co.KG" +__maintainer__ = "mundialis GmbH & Co. KG" -# TODO use modis data LOCATION = "nc_spm_08" MAPSET = "modis_lst" STRDS = "LST_Day_monthly" @@ -24,7 +21,7 @@ "type": "FeatureCollection", "crs": { "type": "name", - "properties": {"name": "urn:ogc:def:crs:EPSG::3358"}, + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"} }, "features": [ { @@ -34,24 +31,29 @@ "type": "Polygon", "coordinates": [ [ - [349852.196963928756304, 252507.816825738176703], - [349852.196963928756304, 244101.739720351994038], - [361635.941179184708744, 244101.739720351994038], - [361635.941179184708744, 252507.816825738176703], - [349852.196963928756304, 252507.816825738176703], + [330000.0, 65000.0], + [337000.0, 65000.0], + [337000.0, 647000.0], + [330000.0, 647000.0], + [330000.0, 65000.0], ] ], }, } ], } +TIMESTAMP = "2016-01-01T00:00:00" +BASE_URL = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" \ + f"{STRDS}/timestamp/{TIMESTAMP}" +ASYNC_URL = f"{BASE_URL}/area_stats_async" +SYNC_URL = f"{BASE_URL}/area_stats_sync" + -""" class STRDSAreaStatsTestCase(ActiniaResourceTestCaseBase): def test_async_raster_area_stats_json(self): + rv = self.server.post( - f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" - f"{STRDS}/timestamp/2016-01-01T00:00:00/area_stats_async", + ASYNC_URL, headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -70,12 +72,12 @@ def test_async_raster_area_stats_json(self): rv, headers=self.admin_auth_header ) - self.assertEqual(len(data["process_results"]), 29) + self.assertEqual(len(data["process_results"]), 93) def test_sync_raster_area_stats_1(self): + rv = self.server.post( - f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" - f"{STRDS}/timestamp/2016-01-01T00:00:00/area_stats_sync", + SYNC_URL, headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -91,16 +93,12 @@ def test_sync_raster_area_stats_1(self): ) value_list = json_load(rv.data)["process_results"] - self.assertEqual(len(value_list), 29) + self.assertEqual(len(value_list), 93) def test_sync_raster_area_stats_2(self): + rv = self.server.post( - f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" - f"{STRDS}/timestamp/2016-01-01T00:00:00/area_stats_sync", - # URL_PREFIX + '/locations/ECAD/mapsets/PERMANENT/strds/' - # 'temperature_mean_1950_2013_yearly_celsius/' - # 'timestamp/2001-01-01T00:00:00/' - # 'area_stats_sync', + SYNC_URL, headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -116,14 +114,13 @@ def test_sync_raster_area_stats_2(self): ) value_list = json_load(rv.data)["process_results"] - self.assertEqual(len(value_list), 29) + self.assertEqual(len(value_list), 93) def test_sync_raster_area_stats_error_no_map_found(self): + + newer_timestamp = "2021-01-01T00:00:00" rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2021-01-01T00:00:00/" - "area_stats_sync", + SYNC_URL.replace(TIMESTAMP, newer_timestamp), headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -139,11 +136,9 @@ def test_sync_raster_area_stats_error_no_map_found(self): ) def test_sync_raster_area_stats_wrong_content_type(self): + rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" - "area_stats_sync", + SYNC_URL, headers=self.admin_auth_header, data=" This is no data", content_type="application/XML", @@ -160,10 +155,7 @@ def test_sync_raster_area_stats_wrong_content_type(self): def test_sync_raster_area_stats_error_nodata(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" - "area_stats_sync", + SYNC_URL, headers=self.admin_auth_header, data=json_dump({}), content_type="application/json", @@ -180,10 +172,7 @@ def test_sync_raster_area_stats_error_nodata(self): def test_sync_raster_area_stats_error(self): rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00:00:00/" - "area_stats_sync", + SYNC_URL, headers=self.admin_auth_header, data=None, content_type="application/json", @@ -199,11 +188,10 @@ def test_sync_raster_area_stats_error(self): ) def test_sync_raster_area_stats_error_wrong_timestamp(self): + + wrong_timestamp = "2016-01-01T00.00.00" rv = self.server.post( - URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/" - "timestamp/2001-01-01T00.00.00/" - "area_stats_sync", + SYNC_URL.replace(TIMESTAMP, wrong_timestamp), headers=self.admin_auth_header, data=json_dump(JSON), content_type="application/json", @@ -217,7 +205,6 @@ def test_sync_raster_area_stats_error_wrong_timestamp(self): self.assertEqual( rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype ) -""" if __name__ == "__main__": diff --git a/tests/test_strds_sample.py b/tests/test_strds_sample.py index 265791e..2209fbb 100644 --- a/tests/test_strds_sample.py +++ b/tests/test_strds_sample.py @@ -1,79 +1,61 @@ # -*- coding: utf-8 -*- import unittest -# import time -# from flask.json import loads as json_load -# from flask.json import dumps as json_dump -# -# try: -# from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX -# except Exception: -# from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +import time +from flask.json import loads as json_load +from flask.json import dumps as json_dump + +try: + from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +except Exception: + from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX __license__ = "GPLv3" -__author__ = "Sören Gebbert" -__copyright__ = "Copyright 2016, Sören Gebbert" -__maintainer__ = "Soeren Gebbert" -__email__ = "soerengebbert@googlemail.com" +__author__ = "Sören Gebbert, Anika Weinmann" +__copyright__ = "Copyright 2016-2022, Sören Gebbert and mundialis GmbH & Co.KG" +__maintainer__ = "mundialis GmbH & Co. KG" -# TODO use modis data LOCATION = "nc_spm_08" MAPSET = "modis_lst" STRDS = "LST_Day_monthly" -# TODO change coordinates JSON = { "type": "FeatureCollection", "crs": { "type": "name", - "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}, + "properties": {"name": "urn:x-ogc:def:crs:EPSG:3358"} }, "features": [ { "type": "Feature", "properties": {"cat": 1}, - "geometry": { - "type": "Point", - "coordinates": [-5.095406, 38.840583], - }, + "geometry": {"type": "Point", "coordinates": [330000.0, 65000.0]} }, { "type": "Feature", "properties": {"cat": 2}, - "geometry": { - "type": "Point", - "coordinates": [9.9681980, 51.666166], - }, - }, - { - "type": "Feature", - "properties": {"cat": 3}, - "geometry": { - "type": "Point", - "coordinates": [24.859647, 52.699099], - }, - }, - ], + "geometry": {"type": "Point", "coordinates": [500000.0, 500000.0]} + } + ] } +POINT_LIST = [ + ["a", "330000.0", "65000.0"], + ["b", "300000.0", "60000.0"], + ["c", "500000.0", "500000.0"], +] +WHERE = "start_time >'2016-01-01'" -""" class STRDSTestCase(ActiniaResourceTestCaseBase): def test_async_sampling(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" \ + f"{STRDS}/sampling_async" + rv = self.server.post( - f"{URL_PREFIX}/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/sampling_async", + url, headers=self.user_auth_header, - data=json_dump( - { - "points": [ - ["a", "-5.095406", "38.840583"], - ["b", "9.9681980", "51.666166"], - ["c", "24.859647", "52.699099"], - ] - } - ), + data=json_dump({"points": POINT_LIST}), content_type="application/json", ) @@ -120,19 +102,12 @@ def test_async_sampling(self): def test_sync_sampling(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" \ + f"{STRDS}/sampling_sync" rv = self.server.post( - f"{URL_PREFIX}/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/sampling_sync", + url, headers=self.user_auth_header, - data=json_dump( - { - "points": [ - ["a", "-5.095406", "38.840583"], - ["b", "9.9681980", "51.666166"], - ["c", "24.859647", "52.699099"], - ] - } - ), + data=json_dump({"points": POINT_LIST}), content_type="application/json", ) @@ -155,13 +130,19 @@ def test_sync_sampling(self): time.sleep(1) - def test_sync_sampling_geojson(self): + def test_sync_sampling_where(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" \ + f"{STRDS}/sampling_sync" rv = self.server.post( - f"{URL_PREFIX}/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/sampling_sync_geojson", + url, headers=self.user_auth_header, - data=json_dump(JSON), + data=json_dump( + { + "points": POINT_LIST, + "where": WHERE, + } + ), content_type="application/json", ) @@ -178,26 +159,18 @@ def test_sync_sampling_geojson(self): self.assertEqual(value_list[0][0], "start_time") self.assertEqual(value_list[0][1], "end_time") - self.assertEqual(value_list[0][2], "1") - self.assertEqual(value_list[0][3], "2") - self.assertEqual(value_list[0][4], "3") + self.assertEqual(value_list[0][2], "a") + self.assertEqual(value_list[0][3], "b") + self.assertEqual(value_list[0][4], "c") - def test_sync_sampling_where(self): + def test_sync_sampling_geojson(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/strds/" \ + f"{STRDS}/sampling_sync_geojson" rv = self.server.post( - f"{URL_PREFIX}/locations/ECAD/mapsets/PERMANENT/strds/" - "temperature_mean_1950_2013_yearly_celsius/sampling_sync", + url, headers=self.user_auth_header, - data=json_dump( - { - "points": [ - ["a", "-5.095406", "38.840583"], - ["b", "9.9681980", "51.666166"], - ["c", "24.859647", "52.699099"], - ], - "where": "start_time >'2010-01-01'", - } - ), + data=json_dump(JSON), content_type="application/json", ) @@ -214,10 +187,8 @@ def test_sync_sampling_where(self): self.assertEqual(value_list[0][0], "start_time") self.assertEqual(value_list[0][1], "end_time") - self.assertEqual(value_list[0][2], "a") - self.assertEqual(value_list[0][3], "b") - self.assertEqual(value_list[0][4], "c") -""" + self.assertEqual(value_list[0][2], "1") + self.assertEqual(value_list[0][3], "2") if __name__ == "__main__": diff --git a/tests/test_vector_sample.py b/tests/test_vector_sample.py index ac2e60b..f63f920 100644 --- a/tests/test_vector_sample.py +++ b/tests/test_vector_sample.py @@ -1,40 +1,39 @@ # -*- coding: utf-8 -*- import unittest -# import time -# from flask.json import loads as json_load -# from flask.json import dumps as json_dump -# -# try: -# from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX -# except Exception: -# from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +import time +from flask.json import loads as json_load +from flask.json import dumps as json_dump +try: + from .test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX +except Exception: + from test_resource_base import ActiniaResourceTestCaseBase, URL_PREFIX __license__ = "GPLv3" -__author__ = "Markus Neteler" +__author__ = "Markus Neteler, Anika Weinmann" __copyright__ = ( - "Copyright 2016-present, Markus Neteler and mundialis GmbH & Co. KG" + "Copyright 2016-2022, Markus Neteler and mundialis GmbH & Co. KG" ) -# TODO zipcodes_wake not in test GRASS GIS DB +LOCATION = "nc_spm_08" +MAPSET = "PERMANENT" +VECTOR = "nc_state" + +POINTS_LIST = [ + ["p1", "638684.0", "220210.0"], + ["p2", "635676.0", "226371.0"], +] -""" class VectorTestCase(ActiniaResourceTestCaseBase): def test_async_sampling(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" \ + f"vector_layers/{VECTOR}/sampling_async" rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/vector_layers" - "/zipcodes_wake/sampling_async", + url, headers=self.user_auth_header, - data=json_dump( - { - "points": [ - ["a", "638684.0", "220210.0"], - ["b", "635676.0", "226371.0"], - ] - } - ), + data=json_dump({"points": POINTS_LIST}), content_type="application/json", ) @@ -62,10 +61,7 @@ def test_async_sampling(self): break time.sleep(0.2) - import pdb - - pdb.set_trace() - self.assertEquals(resp["status"], "finished") + self.assertEqual(resp["status"], "finished", resp) self.assertEqual( rv.status_code, 200, @@ -74,27 +70,21 @@ def test_async_sampling(self): value_list = json_load(rv.data)["process_results"] - self.assertIn("East", value_list["p1"]) - self.assertIn("North", value_list["p2"]) - self.assertIn("ZIPCODE", value_list["p2"]) - self.assertEqual(value_list["p2"]["ZIPCODE"], "RALEIGH_27606") + self.assertIn("East", value_list[0]["p1"]) + self.assertIn("North", value_list[1]["p2"]) + self.assertIn("STATE", value_list[1]["p2"]) + self.assertEqual(value_list[1]["p2"]["STATE"], "NORTH_CAROLINA") time.sleep(1) def test_sync_sampling(self): + url = f"{URL_PREFIX}/locations/{LOCATION}/mapsets/{MAPSET}/" \ + f"vector_layers/{VECTOR}/sampling_sync" rv = self.server.post( - f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/vector_layers" - "/zipcodes_wake/sampling_sync", + url, headers=self.user_auth_header, - data=json_dump( - { - "points": [ - ["p1", "638684.0", "220210.0"], - ["p2", "635676.0", "226371.0"], - ] - } - ), + data=json_dump({"points": POINTS_LIST}), content_type="application/json", ) @@ -109,13 +99,12 @@ def test_sync_sampling(self): value_list = json_load(rv.data)["process_results"] - self.assertIn("East", value_list["p1"]) - self.assertIn("North", value_list["p2"]) - self.assertIn("ZIPCODE", value_list["p2"]) - self.assertEqual(value_list["p2"]["ZIPCODE"], "RALEIGH_27606") + self.assertIn("East", value_list[0]["p1"]) + self.assertIn("North", value_list[1]["p2"]) + self.assertIn("STATE", value_list[1]["p2"]) + self.assertEqual(value_list[1]["p2"]["STATE"], "NORTH_CAROLINA") time.sleep(1) -""" if __name__ == "__main__":