Skip to content

Commit

Permalink
Tests lv (#22)
Browse files Browse the repository at this point in the history
* black

* flake8

* try to fix tests

* use actinia-docker docker image

* fix test

* fix setup.cfg

* fix test_strds_area_stats.py

* add required addons

* linting

* vector_sampling test

* add example

* fix sampling endpoint

* fixed tests

* updated examples.md

* fixed linting errors

Co-authored-by: anikaweinmann <[email protected]>
  • Loading branch information
linakrisztian and anikaweinmann authored Aug 3, 2022
1 parent e249d35 commit 0bc7f2b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 65 deletions.
18 changes: 18 additions & 0 deletions examples/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ 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
```

area_stats_univar for 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/timestamp/2016-01-01T00:00:00/area_stats_univar_async -d @area.geojson
# sync
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_univar_sync -d @area.geojson
```


## Raster sampling
Raster statistics of area
```
Expand All @@ -44,9 +54,17 @@ 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
```
```
# async
curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/landuse96_28m/sampling_async -d @points2.json
# sync
curl -u ${AUTH} -H 'Content-Type: application/json' -X POST ${BASE_URL}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/landuse96_28m/sampling_sync -d @points2.json
# note: sync doesn't run successfully (even though test_raste_sample.py passed all tests)
```


## 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
```

28 changes: 1 addition & 27 deletions tests/test_raster_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_async_sampling(self):
break
time.sleep(0.2)

self.assertEquals(resp["status"], "finished", "Process not finished.")
self.assertEqual(resp["status"], "finished", "Process not finished.")
self.assertEqual(
rv.status_code,
200,
Expand All @@ -101,7 +101,6 @@ def test_async_sampling(self):

time.sleep(1)

"""
def test_sync_sampling(self):
# PROBLEM: Not yet returned!

Expand Down Expand Up @@ -133,31 +132,6 @@ def test_sync_sampling(self):

time.sleep(1)

def test_sync_sampling_geojson(self):
rv = self.server.post(
f"{URL_PREFIX}/locations/nc_spm_08/mapsets/PERMANENT/raster_layers/"
"landuse96_28m/sampling_sync_geojson",
headers=self.user_auth_header,
data=json_dump(JSON),
content_type="application/json")
self.assertEqual(
rv.status_code, 200, "HTML status code is wrong %i"
% rv.status_code)
self.assertEqual(
rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype)
value_list = json_load(rv.data)["process_results"]
self.assertEqual(value_list[0][0], "easting")
self.assertEqual(value_list[0][1], "northing")
self.assertEqual(value_list[0][2], "site_name")
self.assertEqual(value_list[0][3], "landuse96_28m")
self.assertEqual(value_list[0][4], "landuse96_28m_label")
self.assertEqual(value_list[0][5], "landuse96_28m_color")
"""


if __name__ == "__main__":
unittest.main()
73 changes: 35 additions & 38 deletions tests/test_strds_area_stats_univar.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import unittest
# import time
# from flask.json import loads as json_load
# from flask.json import dumps as json_dump
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
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"
Expand All @@ -19,13 +19,14 @@
LOCATION = "nc_spm_08"
MAPSET = "modis_lst"
STRDS = "LST_Day_monthly"
TIMESTAMP = "2016-01-01T00:00:00"

# 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": [
{
Expand All @@ -35,25 +36,24 @@
"type": "Polygon",
"coordinates": [
[
[7.756, 52.298157894736846],
[11.986947368421044, 51.657105263157924],
[9.550947368421047, 48.580052631578958],
[6.345684210526304, 48.836473684210539],
[7.756, 52.298157894736846],
[330000.0, 65000.0],
[331000.0, 65000.0],
[331000.0, 649000.0],
[330000.0, 649000.0],
[330000.0, 65000.0],
]
],
},
}
],
}

"""

class STRDSAreaStatsUnivarTestCase(ActiniaResourceTestCaseBase):
def test_async_raster_area_stats_json(self):
rv = self.server.post(
URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/"
"temperature_mean_1950_2013_yearly_celsius/"
"timestamp/2001-01-01T00:00:00/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_async",
headers=self.admin_auth_header,
data=json_dump(JSON),
Expand All @@ -65,6 +65,7 @@ def test_async_raster_area_stats_json(self):
200,
"HTML status code is wrong %i" % rv.status_code,
)

self.assertEqual(
rv.mimetype, "application/json", "Wrong mimetype %s" % rv.mimetype
)
Expand All @@ -73,13 +74,13 @@ def test_async_raster_area_stats_json(self):
rv, headers=self.admin_auth_header
)["process_results"]
self.assertEqual(value_list[0]["cat"], "1")
self.assertEqual(value_list[0]["raster_number"], 209)
self.assertEqual(value_list[0]["raster_maximum"], 13781.)
self.assertEqual(value_list[0]["raster_number"], 1.0)

def test_sync_raster_area_stats_1(self):
rv = self.server.post(
URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/"
"temperature_mean_1950_2013_yearly_celsius/"
"timestamp/2001-01-01T00:00:00/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=json_dump(JSON),
Expand All @@ -97,13 +98,13 @@ 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"], 209)
self.assertEqual(value_list[0]["raster_maximum"], 13781.)
self.assertEqual(value_list[0]["raster_number"], 1.0)

def test_sync_raster_area_stats_2(self):
rv = self.server.post(
URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/"
"temperature_mean_1950_2013_yearly_celsius/"
"timestamp/2001-01-01T00:00:00/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=json_dump(JSON),
Expand All @@ -121,13 +122,13 @@ 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"], 209)
self.assertEqual(value_list[0]["raster_maximum"], 13781.)
self.assertEqual(value_list[0]["raster_number"], 1.0)

def test_sync_raster_area_stats_error_no_map_found(self):
rv = self.server.post(
URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/"
"temperature_mean_1950_2013_yearly_celsius/"
"timestamp/2021-01-01T00:00:00/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=None,
Expand All @@ -145,9 +146,8 @@ def test_sync_raster_area_stats_error_no_map_found(self):

def test_sync_raster_area_stats_module_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/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=json_dump({}),
Expand All @@ -165,9 +165,8 @@ def test_sync_raster_area_stats_module_error(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/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/{TIMESTAMP}/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=None,
Expand All @@ -185,9 +184,8 @@ def test_sync_raster_area_stats_error_nodata(self):

def test_sync_raster_area_stats_error_wrong_timestamp(self):
rv = self.server.post(
URL_PREFIX + "/locations/ECAD/mapsets/PERMANENT/strds/"
"temperature_mean_1950_2013_yearly_celsius/"
"timestamp/2001-01-01T00.00.00/"
URL_PREFIX + f"/locations/{LOCATION}/mapsets/{MAPSET}/strds/"
f"{STRDS}/timestamp/2001-01-01T00.00.00/"
"area_stats_univar_sync",
headers=self.admin_auth_header,
data=json_dump(JSON),
Expand All @@ -202,7 +200,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__":
Expand Down

0 comments on commit 0bc7f2b

Please sign in to comment.