Skip to content

Commit

Permalink
add tests for pixellimit check
Browse files Browse the repository at this point in the history
  • Loading branch information
linakrisztian committed Nov 20, 2023
1 parent f037c9c commit cd5008f
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
155 changes: 155 additions & 0 deletions tests/test_raster_import_pixellimit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
# -*- coding: utf-8 -*-
#######
# actinia-core - an open source REST API for scalable, distributed, high
# performance processing of geographical data that uses GRASS GIS for
# computational tasks. For details, see https://actinia.mundialis.de/
#
# Copyright (c) 2016-2018 Sören Gebbert and mundialis GmbH & Co. KG
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#######

"""
Tests: Import raster with pixellimit check
"""
import unittest
from flask.json import dumps as json_dumps

try:
from .test_resource_base import (
ActiniaResourceTestCaseBase,
URL_PREFIX,
additional_external_data,
)
except Exception:
from test_resource_base import (
ActiniaResourceTestCaseBase,
URL_PREFIX,
additional_external_data,
)

__license__ = "GPLv3"
__author__ = "Lina Krisztian"
__copyright__ = "Copyright 2016-2021, mundialis GmbH & Co. KG"
__maintainer__ = "mundialis GmbH & Co. KG"


class ImportRasterLayerPixellimitTestCase(ActiniaResourceTestCaseBase):
location = "nc_spm_08"
tmp_mapset = "mapset_rasterimport_pixellimit"
endpoint = f"/locations/{location}/mapsets/{tmp_mapset}/processing_async"
rimport_inp = "elevation"
# import resolution with which the process should fail:
rimport_res_fail = 0.1

def setUp(self):
# create new temp mapset
super(ImportRasterLayerPixellimitTestCase, self).setUp()
self.create_new_mapset(self.tmp_mapset, location_name=self.location)

def tearDown(self):
# delete mapset
self.delete_mapset(self.tmp_mapset, location_name=self.location)
super(ImportRasterLayerPixellimitTestCase, self).tearDown()

def test_pixellimit_not_reached(self):
"""
Test import of raster, for which pixellimit is not reached
"""
raster_url = additional_external_data[self.rimport_inp]
raster = self.rimport_inp
process_chain = {
"version": 1,
"list": [
{
"id": "1",
"module": "r.import",
"inputs": [
{
"param": "input",
"value": raster_url,
},
{
"param": "output",
"value": raster,
},
],
},
],
}
rv = self.server.post(
URL_PREFIX + self.endpoint,
headers=self.admin_auth_header,
data=json_dumps(process_chain),
content_type="application/json",
)
# Import should succeed
self.waitAsyncStatusAssertHTTP(
rv,
headers=self.admin_auth_header,
http_status=200,
status="finished",
)

def test_pixellimit_reached(self):
"""
Test import of raster, for which pixellimit is reached
"""
raster_url = additional_external_data[self.rimport_inp]
raster = self.rimport_inp
process_chain = {
"version": 1,
"list": [
{
"id": "1",
"module": "r.import",
"inputs": [
{
"param": "input",
"value": raster_url,
},
{
"param": "output",
"value": raster,
},
{
"param": "resolution",
"value": "value",
},
{
"param": "resolution_value",
"value": f"{self.rimport_res_fail}",
},
],
},
],
}
rv = self.server.post(
URL_PREFIX + self.endpoint,
headers=self.admin_auth_header,
data=json_dumps(process_chain),
content_type="application/json",
)
# Import should fail (due too high resolution)
self.waitAsyncStatusAssertHTTP(
rv,
headers=self.admin_auth_header,
http_status=400,
status="error",
)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions tests/test_resource_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"geology_30m_tif": f"{base_url_data}/geology_30m.tif",
"geology_30m_zip": f"{base_url_data}/geology_30m.zip",
"pointInBonn": f"{base_url_data}/pointInBonn.geojson",
"elevation": f"{base_url_data}/elevation.tif",
}


Expand Down

0 comments on commit cd5008f

Please sign in to comment.