Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filesystem.thumbnail: patch_after_wfst #351

Merged
merged 1 commit into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added sample/style/test_wfs_bbox_layer_qml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/style/test_wfs_bbox_layer_sld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sample/style/test_wfs_bbox_layer_sld_bigger.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 16 additions & 9 deletions src/layman/geoserver_proxy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from geoserver.util import get_layer_thumbnail, get_square_bbox
from layman import app, settings, util as layman_util
from layman.layer import db, util as layer_util
from layman.layer.filesystem import thumbnail
from layman.layer.geoserver import wfs as geoserver_wfs
from layman.layer.qgis import util as qgis_util, wms as qgis_wms

Expand Down Expand Up @@ -375,15 +376,14 @@ def assert_all_sources_bbox(workspace, layer, expected_bbox):
test_util.assert_wms_bbox(workspace, layer, expected_bbox)


@pytest.mark.parametrize('style_file', [
None,
'sample/style/small_layer.qml',
@pytest.mark.parametrize('style_file, thumbnail_style_postfix', [
(None, '_sld'),
('sample/style/small_layer.qml', '_qml'),
])
@pytest.mark.usefixtures('ensure_layman')
def test_wfs_bbox(style_file):
def test_wfs_bbox(style_file, thumbnail_style_postfix):
workspace = 'test_wfs_bbox_workspace'
layer = 'test_wfs_bbox_layer'
expected_bbox = (1571000.0, 6268800.0, 1572590.8542062, 6269876.33561699)

client_util.publish_workspace_layer(workspace, layer, style_file=style_file, )

Expand All @@ -395,12 +395,13 @@ def test_wfs_bbox(style_file):
'Content-type': 'text/xml',
}

method_bbox_tuples = [
(data_wfs.get_wfs20_insert_points, expected_bbox),
(data_wfs.get_wfs20_delete_point, SMALL_LAYER_BBOX),
expected_bbox = (1571000.0, 6268800.0, 1572590.8542062, 6269876.33561699)
method_bbox_thumbnail_tuples = [
(data_wfs.get_wfs20_insert_points, expected_bbox, '_bigger'),
(data_wfs.get_wfs20_delete_point, SMALL_LAYER_BBOX, ''),
]

for wfs_method, exp_bbox in method_bbox_tuples:
for wfs_method, exp_bbox, thumbnail_bbox_postfix in method_bbox_thumbnail_tuples:
data_xml = wfs_method(workspace, layer, )

r = requests.post(rest_url,
Expand All @@ -413,4 +414,10 @@ def test_wfs_bbox(style_file):

assert_all_sources_bbox(workspace, layer, exp_bbox)

expected_thumbnail_path = f'/code/sample/style/{layer}{thumbnail_style_postfix}{thumbnail_bbox_postfix}.png'
with app.app_context():
thumbnail_path = thumbnail.get_layer_thumbnail_path(workspace, layer)
diffs = test_util.compare_images(expected_thumbnail_path, thumbnail_path)
assert diffs < 100, expected_thumbnail_path

client_util.delete_workspace_layer(workspace, layer, )
21 changes: 21 additions & 0 deletions src/layman/layer/filesystem/thumbnail_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from celery.utils.log import get_task_logger

from layman.celery import AbortedException
from layman import celery_app
from . import thumbnail

logger = get_task_logger(__name__)


@celery_app.task(
name='layman.layer.filesystem.thumbnail.patch_after_wfst',
bind=True,
base=celery_app.AbortableTask
)
def patch_after_wfst(self, workspace, layer):
if self.is_aborted():
raise AbortedException
thumbnail.generate_layer_thumbnail(workspace, layer)

if self.is_aborted():
raise AbortedException