Added unit tests for grass engine

pull/451/head
Piero Toffanin 2018-05-13 13:30:44 -04:00
rodzic 38ec4cafee
commit 572abd8db9
5 zmienionych plików z 52 dodań i 7 usunięć

Wyświetl plik

@ -37,7 +37,7 @@ def boot():
# Make sure our app/media/tmp folder exists
if not os.path.exists(settings.MEDIA_TMP):
os.mkdir(settings.MEDIA_TMP)
os.makedirs(settings.MEDIA_TMP)
# Check default group
try:

Wyświetl plik

@ -60,7 +60,7 @@ class GrassContext:
"""
:param location: either a "epsg:XXXXX" string or a path to a geospatial file defining the location
"""
if not location.startswith('epsg:'):
if not location.lower().startswith('epsg:'):
location = os.path.abspath(location)
self.location = location
@ -107,6 +107,7 @@ class GrassContext:
}
def __del__(self):
pass
# Cleanup
if os.path.exists(self.get_cwd()):
shutil.rmtree(self.get_cwd())

Wyświetl plik

@ -0,0 +1,6 @@
# test: Geospatial test file
# ------
# output: greets the user and prints the information of a spatial file
v.in.ogr input=${test} layer=test output=test --overwrite
v.info map=test

Wyświetl plik

@ -5,6 +5,9 @@ from rest_framework import status
from app.plugins import get_plugin_by_name
from .classes import BootTestCase
from app.plugins.grass_engine import grass, GrassEngineException
from worker.tasks import execute_grass_script
class TestPlugins(BootTestCase):
def setUp(self):
@ -45,5 +48,41 @@ class TestPlugins(BootTestCase):
test_plugin = get_plugin_by_name("test")
self.assertTrue(os.path.exists(test_plugin.get_path("public/node_modules")))
# TODO:
# test GRASS engine
def test_grass_engine(self):
cwd = os.path.dirname(os.path.realpath(__file__))
grass_scripts_dir = os.path.join(cwd, "grass_scripts")
ctx = grass.create_context()
ctx.add_file('test.geojson', """{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
13.770675659179686,
45.655328041141374
]
}
}
]
}""")
ctx.set_location("EPSG:4326")
output = execute_grass_script.delay(
os.path.join(grass_scripts_dir, "simple_test.grass"),
ctx.serialize()
).get()
self.assertTrue("Number of points: 1" in output)
error = execute_grass_script.delay(
os.path.join(grass_scripts_dir, "nonexistant_script.grass"),
ctx.serialize()
).get()
self.assertIsInstance(error, dict)
self.assertIsInstance(error['error'], str)
with self.assertRaises(GrassEngineException):
ctx.execute(os.path.join(grass_scripts_dir, "nonexistant_script.grass"))

Wyświetl plik

@ -250,6 +250,8 @@ CORS_ALLOW_CREDENTIALS = True
# File uploads
MEDIA_ROOT = os.path.join(BASE_DIR, 'app', 'media')
if TESTING:
MEDIA_ROOT = os.path.join(BASE_DIR, 'app', 'media_test')
MEDIA_TMP = os.path.join(MEDIA_ROOT, 'tmp')
# Store flash messages in cookies
@ -330,9 +332,6 @@ CELERY_WORKER_HIJACK_ROOT_LOGGER = False
if TESTING:
CELERY_TASK_ALWAYS_EAGER = True
if TESTING:
MEDIA_ROOT = os.path.join(BASE_DIR, 'app', 'media_test')
try:
from .local_settings import *
except ImportError: