diff --git a/src/layman/layer/rest_workspace_layer.py b/src/layman/layer/rest_workspace_layer.py index 0652ec01f..a8ac881ac 100644 --- a/src/layman/layer/rest_workspace_layer.py +++ b/src/layman/layer/rest_workspace_layer.py @@ -6,7 +6,7 @@ from layman import settings, authn, util as layman_util from layman.authn import authenticate from layman.authz import authorize_workspace_publications_decorator -from . import util, LAYER_REST_PATH_NAME +from . import util, LAYER_REST_PATH_NAME, LAYER_TYPE from .filesystem import input_file, input_style, input_chunk bp = Blueprint('rest_workspace_layer', __name__) @@ -89,6 +89,7 @@ def patch(workspace, layername): style_file = request.files['sld'] delete_from = None + style_type = None if style_file: style_type = input_style.get_style_type_from_file_storage(style_file) kwargs['style_type'] = style_type @@ -98,6 +99,7 @@ def patch(workspace, layername): delete_from = 'layman.layer.filesystem.input_file' # FILE NAMES + filenames = None if delete_from == 'layman.layer.filesystem.input_file': if use_chunk_upload: filenames = files @@ -106,6 +108,17 @@ def patch(workspace, layername): input_file.check_filenames(workspace, layername, filenames, check_crs, ignore_existing_files=True) + if filenames: + file_type = input_file.get_file_type(input_file.get_main_file_name(filenames)) + else: + file_type = layman_util.get_publication_info(workspace, LAYER_TYPE, layername, context={'keys': ['file']})['file']['file_type'] + if style_type: + style_type_for_check = style_type.code + else: + style_type_for_check = layman_util.get_publication_info(workspace, LAYER_TYPE, layername, context={'keys': ['style']})['style']['type'] + if file_type == settings.FILE_TYPE_RASTER and style_type_for_check == 'qml': + raise LaymanError(48, f'Raster layers are not allowed to have QML style.') + props_to_refresh = util.get_same_or_missing_prop_names(workspace, layername) kwargs['metadata_properties_to_refresh'] = props_to_refresh diff --git a/src/layman/layer/rest_workspace_layer_test.py b/src/layman/layer/rest_workspace_layer_test.py index bfd4ea97d..9a3f27db1 100644 --- a/src/layman/layer/rest_workspace_layer_test.py +++ b/src/layman/layer/rest_workspace_layer_test.py @@ -1,13 +1,13 @@ import json import sys -from test import process_client +from test import process_client, util as test_util from test.util import url_for import requests import pytest del sys.modules['layman'] -from layman import app +from layman import app, LaymanError @pytest.mark.usefixtures('ensure_layman') @@ -42,3 +42,37 @@ def test_style_value(): assert r_del.status_code >= 400, (r_del.text, style_url) process_client.delete_workspace_layer(username, layername) + + +@pytest.mark.parametrize('post_params, patch_params, expected_exc', [ + ({'file_paths': ['sample/layman.layer/sample_tif_rgb.tif', ], + }, + {'style_file': 'sample/style/ne_10m_admin_0_countries.qml', + }, + {'http_code': 400, + 'code': 48, + 'message': 'Wrong combination of parameters', + 'detail': 'Raster layers are not allowed to have QML style.', + }, + ), + ({'style_file': 'sample/style/ne_10m_admin_0_countries.qml', + }, + {'file_paths': ['sample/layman.layer/sample_tif_rgb.tif', ], + }, + {'http_code': 400, + 'code': 48, + 'message': 'Wrong combination of parameters', + 'detail': 'Raster layers are not allowed to have QML style.', + }, + ), +]) +@pytest.mark.usefixtures('ensure_layman') +def test_error(post_params, patch_params, expected_exc): + workspace = 'test_error_workspace' + layer = 'test_error_layer' + + process_client.publish_workspace_layer(workspace, layer, **post_params) + with pytest.raises(LaymanError) as exc_info: + process_client.patch_workspace_layer(workspace, layer, **patch_params) + test_util.assert_error(expected_exc, exc_info) + process_client.delete_workspace_layer(workspace, layer)