diff --git a/sample/style/test_sld_style_applied_in_map_thumbnail_map.png b/sample/style/test_sld_style_applied_in_map_thumbnail_map.png deleted file mode 100644 index e95e8be10..000000000 Binary files a/sample/style/test_sld_style_applied_in_map_thumbnail_map.png and /dev/null differ diff --git a/test_tools/process.py b/test_tools/process.py index 60981ba12..ea87c0e91 100644 --- a/test_tools/process.py +++ b/test_tools/process.py @@ -69,6 +69,7 @@ def oauth2_provider_mock(): 'dynamic_test_workspace_geoserver_proxy_user_2': None, 'dynamic_test_layer_patch_without_data_user': None, 'test_fix_issuer_id_user': None, + 'layer_map_relation_user': None, }, }, 'host': '0.0.0.0', diff --git a/test_tools/process_client.py b/test_tools/process_client.py index b38bc3ea1..d03b887d4 100644 --- a/test_tools/process_client.py +++ b/test_tools/process_client.py @@ -172,6 +172,7 @@ def patch_workspace_publication(publication_type, file_paths=None, external_table_uri=None, headers=None, + actor_name=None, access_rights=None, title=None, style_file=None, @@ -189,6 +190,8 @@ def patch_workspace_publication(publication_type, skip_asserts=False, ): headers = headers or {} + if actor_name: + assert TOKEN_HEADER not in headers publication_type_def = PUBLICATION_TYPES_DEF[publication_type] if not skip_asserts: @@ -210,6 +213,9 @@ def patch_workspace_publication(publication_type, # Compress settings can be used only with compress option assert not compress_settings or compress + if actor_name and actor_name != settings.ANONYM_USER: + headers.update(get_authz_headers(actor_name)) + file_paths = [] if file_paths is None and not map_layers else file_paths with app.app_context(): @@ -325,6 +331,7 @@ def publish_workspace_publication(publication_type, file_paths=None, external_table_uri=None, headers=None, + actor_name=None, access_rights=None, title=None, style_file=None, @@ -344,6 +351,8 @@ def publish_workspace_publication(publication_type, ): title = title or name headers = headers or {} + if actor_name: + assert TOKEN_HEADER not in headers publication_type_def = PUBLICATION_TYPES_DEF[publication_type] assert not map_layers or not file_paths @@ -364,6 +373,9 @@ def publish_workspace_publication(publication_type, assert not (time_regex and publication_type == MAP_TYPE) + if actor_name and actor_name != settings.ANONYM_USER: + headers.update(get_authz_headers(actor_name)) + with app.app_context(): r_url = url_for(publication_type_def.post_workspace_publication_url, workspace=workspace) @@ -557,7 +569,14 @@ def assert_workspace_publications(publication_type, workspace, expected_publicat assert_workspace_maps = partial(assert_workspace_publications, MAP_TYPE) -def get_workspace_publication_metadata_comparison(publication_type, workspace, name, headers=None): +def get_workspace_publication_metadata_comparison(publication_type, workspace, name, headers=None, actor_name=None): + headers = headers or {} + if actor_name: + assert TOKEN_HEADER not in headers + + if actor_name and actor_name != settings.ANONYM_USER: + headers.update(get_authz_headers(actor_name)) + publication_type_def = PUBLICATION_TYPES_DEF[publication_type] with app.app_context(): r_url = url_for(publication_type_def.get_workspace_metadata_comparison_url, **{publication_type_def.url_param_name: name}, workspace=workspace) diff --git a/tests/asserts/final/publication/metadata.py b/tests/asserts/final/publication/metadata.py index d8f9219d7..622b1f0b1 100644 --- a/tests/asserts/final/publication/metadata.py +++ b/tests/asserts/final/publication/metadata.py @@ -53,14 +53,16 @@ def expected_values_in_micka_metadata(workspace, publ_type, name, expected_value ) -def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_values=None): +def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_values=None, actor_name=None): exp_values = exp_values or {} + actor_name = actor_name or settings.ANONYM_USER md_props = { process_client.LAYER_TYPE: LAYER_METADATA_PROPERTIES, process_client.MAP_TYPE: MAP_METADATA_PROPERTIES, }[publ_type] with app.app_context(): - resp_json = process_client.get_workspace_publication_metadata_comparison(publ_type, workspace, name,) + resp_json = process_client.get_workspace_publication_metadata_comparison(publ_type, workspace, name, + actor_name=actor_name) assert md_props.issubset(set(resp_json['metadata_properties'].keys())) for key, value in resp_json['metadata_properties'].items(): assert value['equal_or_null'] is True, f'key={key}, value={value}' @@ -68,7 +70,7 @@ def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_v get_template_path_and_values_method, args = { process_client.LAYER_TYPE: (layer_csw_util.get_template_path_and_values, {}), - process_client.MAP_TYPE: (map_csw_util.get_template_path_and_values, {'actor_name': settings.ANONYM_USER}), + process_client.MAP_TYPE: (map_csw_util.get_template_path_and_values, {'actor_name': actor_name}), }[publ_type] with app.app_context(): _, md_values = get_template_path_and_values_method(workspace, name, http_method=http_method, **args) diff --git a/tests/dynamic_data/base_test.py b/tests/dynamic_data/base_test.py index d5397cd8c..c8cdba7d7 100644 --- a/tests/dynamic_data/base_test.py +++ b/tests/dynamic_data/base_test.py @@ -81,6 +81,8 @@ class TestSingleRestPublication: post_before_test_scope = 'function' + publ_uuids = {} + @classmethod @final def parametrize_test_cases(cls) -> [TestCaseType]: @@ -185,8 +187,13 @@ def post_publication(cls, publication, args=None, scope='function'): else: cls.publications_to_cleanup_on_function_end.add(publication) - return process_client.publish_workspace_publication(publication.type, publication.workspace, publication.name, + resp = process_client.publish_workspace_publication(publication.type, publication.workspace, publication.name, **args) + if isinstance(resp, dict): + maybe_uuid = resp.get('uuid', None) + if maybe_uuid: + cls.publ_uuids[publication] = maybe_uuid + return resp @classmethod def ensure_publication(cls, publication, args=None, scope='function'): diff --git a/tests/dynamic_data/publications/crs/maps/maps_test.py b/tests/dynamic_data/publications/crs/maps/maps_test.py index 67f5f6e19..1a16f15ca 100644 --- a/tests/dynamic_data/publications/crs/maps/maps_test.py +++ b/tests/dynamic_data/publications/crs/maps/maps_test.py @@ -7,8 +7,8 @@ from ..... import Publication DIRECTORY = os.path.dirname(os.path.abspath(__file__)) - -LAYER_FOR_MAPS = "layer_for_map_crs" +WORKSPACE = 'dynamic_test_workspace_crs_maps' +LAYER_FOR_MAPS = Publication(WORKSPACE, process_client.LAYER_TYPE, "layer_for_map_crs") KEY_INFO_VALUES = 'info_values' KEY_THUMBNAIL_TOLERANCE = 'thumbnail_tolerance' @@ -48,7 +48,7 @@ class TestMap(base_test.TestSingleRestPublication): - workspace = 'dynamic_test_workspace_crs_maps' + workspace = WORKSPACE publication_type = process_client.MAP_TYPE @@ -61,18 +61,14 @@ class TestMap(base_test.TestSingleRestPublication): type=tests.EnumTestTypes.MANDATORY, ) for key, params in TEST_CASES.items()] - layer_uuids = {} - def before_class(self): - resp = self.post_publication(Publication(self.workspace, process_client.LAYER_TYPE, LAYER_FOR_MAPS), scope='class') - self.layer_uuids[LAYER_FOR_MAPS] = resp['uuid'] + self.post_publication(LAYER_FOR_MAPS, scope='class') def test_input_crs(self, map, key, params, rest_method): """Parametrized using pytest_generate_tests""" map_crs = key - layer_name = LAYER_FOR_MAPS map_args = { - 'map_layers': [(self.workspace, layer_name)], + 'map_layers': [(LAYER_FOR_MAPS.workspace, LAYER_FOR_MAPS.name)], 'native_extent': params[KEY_INFO_VALUES]['exp_publication_detail']['native_bounding_box'], 'crs': map_crs, 'title': map.name, @@ -84,10 +80,10 @@ def test_input_crs(self, map, key, params, rest_method): 'native_crs': map_crs, 'title': map.name, '_map_layers': [{ - 'name': LAYER_FOR_MAPS, - 'workspace': self.workspace, + 'name': LAYER_FOR_MAPS.name, + 'workspace': LAYER_FOR_MAPS.workspace, 'index': 1, - 'uuid': self.layer_uuids[LAYER_FOR_MAPS], + 'uuid': self.publ_uuids[LAYER_FOR_MAPS], }], **params.get(KEY_INFO_VALUES, {}).get('exp_publication_detail', {}) } diff --git a/tests/dynamic_data/publications/map_layer_relation/internal_hranice.json b/tests/dynamic_data/publications/map_layer_relation/internal_hranice.json new file mode 100644 index 000000000..b455fa3db --- /dev/null +++ b/tests/dynamic_data/publications/map_layer_relation/internal_hranice.json @@ -0,0 +1,34 @@ +{ + "describedBy": "https://raw.githubusercontent.com/hslayers/map-compositions/2.0.0/schema.json", + "schema_version": "2.0.0", + "abstract": "World places and boundaries abstract", + "title": "World places and boundaries", + "extent": [ + -35.0, + -48.5, + 179, + 81.5 + ], + "nativeExtent": [ + -3896182.18, + -6190443.81, + 19926188.85, + 16579785.82 + ], + "projection": "epsg:3857", + "layers": [ + { + "metadata": {}, + "visibility": true, + "opacity": 1, + "title": "Hranice", + "className": "HSLayers.Layer.WMS", + "singleTile": true, + "url": "http://localhost:8000/geoserver/layer_map_relation_workspace_wms/ows", + "params": { + "LAYERS": "hranice", + "FORMAT": "image\/png" + } + } + ] +} diff --git a/sample/layman.map/internal_url_thumbnail.json b/tests/dynamic_data/publications/map_layer_relation/internal_hranice_private.json similarity index 87% rename from sample/layman.map/internal_url_thumbnail.json rename to tests/dynamic_data/publications/map_layer_relation/internal_hranice_private.json index 9a24b2c55..40ccf41c4 100644 --- a/sample/layman.map/internal_url_thumbnail.json +++ b/tests/dynamic_data/publications/map_layer_relation/internal_hranice_private.json @@ -10,26 +10,13 @@ 81.5 ], "nativeExtent": [ - -35.0, - -48.5, - 179, - 81.5 + -3896182.18, + -6190443.81, + 19926188.85, + 16579785.82 ], - "projection": "EPSG:4326", + "projection": "epsg:3857", "layers": [ - { - "metadata": {}, - "visibility": true, - "opacity": 1, - "title": "Staty", - "className": "HSLayers.Layer.WMS", - "singleTile": true, - "url": "http://localhost:8000/geoserver/test_workspace_wms/ows", - "params": { - "LAYERS": "post_blue_style", - "FORMAT": "image\/png" - } - }, { "metadata": {}, "visibility": true, @@ -52,6 +39,19 @@ "VERSION": "1.3.0" }, "dimensions": {} + }, + { + "metadata": {}, + "visibility": true, + "opacity": 1, + "title": "Hranice", + "className": "HSLayers.Layer.WMS", + "singleTile": true, + "url": "http://localhost:8000/geoserver/layer_map_relation_user_wms/ows", + "params": { + "LAYERS": "hranice_private", + "FORMAT": "image\/png" + } } ] } diff --git a/tests/dynamic_data/publications/map_layer_relation/map_layer_relation.py b/tests/dynamic_data/publications/map_layer_relation/map_layer_relation_test.py similarity index 54% rename from tests/dynamic_data/publications/map_layer_relation/map_layer_relation.py rename to tests/dynamic_data/publications/map_layer_relation/map_layer_relation_test.py index 31b54e257..59964b39b 100644 --- a/tests/dynamic_data/publications/map_layer_relation/map_layer_relation.py +++ b/tests/dynamic_data/publications/map_layer_relation/map_layer_relation_test.py @@ -1,6 +1,8 @@ import os +import pytest + from layman import app -from layman.common import REQUEST_METHOD_POST +from layman.common import REQUEST_METHOD_POST, REQUEST_METHOD_PATCH from layman.util import get_publication_info from test_tools import process_client from tests import EnumTestTypes, Publication @@ -14,58 +16,83 @@ DIRECTORY = os.path.dirname(os.path.abspath(__file__)) WORKSPACE = 'layer_map_relation_workspace' +PRIVATE_WORKSPACE = 'layer_map_relation_user' LAYER_HRANICE = Publication(WORKSPACE, process_client.LAYER_TYPE, 'hranice') +LAYER_HRANICE_PRIVATE = Publication(PRIVATE_WORKSPACE, process_client.LAYER_TYPE, 'hranice_private') +LAYER_MISTA_NON_EXISTENT = Publication(WORKSPACE, process_client.LAYER_TYPE, 'mista') +MAP_HRANICE = Publication(WORKSPACE, process_client.MAP_TYPE, 'map_hranice') +MAP_HRANICE_OPERATES_ON = [LAYER_HRANICE] TEST_CASES = { 'post': { - 'rest_method': base_test_classes.RestMethodAll.POST, - 'rest_args': { - 'file_paths': [os.path.join(DIRECTORY, 'internal_wms_and_wfs.json')], - }, 'post_before_test_args': {}, 'exp_before_rest_method': { 'map_layers': None, 'operates_on': None, }, + 'rest_method': base_test_classes.RestMethodAll.POST, + 'rest_args': { + 'file_paths': [os.path.join(DIRECTORY, 'internal_wms_and_wfs.json')], + }, 'exp_after_rest_method': { 'map_layers': { - # workspace, layer name, layer index, exists? - (WORKSPACE, 'hranice', 1, True), - (WORKSPACE, 'mista', 2, False), - (WORKSPACE, 'hranice', 3, True), + # layer, layer index, exists? + (LAYER_HRANICE, 1, True), + (LAYER_MISTA_NON_EXISTENT, 2, False), + (LAYER_HRANICE, 3, True), }, - 'operates_on': ['hranice'], + 'operates_on': [LAYER_HRANICE], }, }, 'delete': { - 'rest_method': base_test_classes.RestMethodAll.DELETE, - 'rest_args': {}, 'post_before_test_args': { 'file_paths': [os.path.join(DIRECTORY, 'internal_wms_and_wfs.json')], }, 'exp_before_rest_method': { 'map_layers': { - (WORKSPACE, 'hranice', 1, True), - (WORKSPACE, 'mista', 2, False), - (WORKSPACE, 'hranice', 3, True), + (LAYER_HRANICE, 1, True), + (LAYER_MISTA_NON_EXISTENT, 2, False), + (LAYER_HRANICE, 3, True), }, - 'operates_on': ['hranice'], + 'operates_on': [LAYER_HRANICE], }, + 'rest_method': base_test_classes.RestMethodAll.DELETE, + 'rest_args': {}, 'exp_after_rest_method': { 'map_layers': None, 'operates_on': None, }, }, + 'patch_map_with_unauthorized_layer': { + 'post_before_test_args': { + 'file_paths': [os.path.join(DIRECTORY, 'internal_hranice_private.json')], + }, + 'exp_before_rest_method': { + 'map_layers': [(LAYER_HRANICE_PRIVATE, 1, True)], + 'operates_on': [], + }, + 'rest_method': base_test_classes.RestMethodAll.PATCH, + 'rest_args': { + 'actor_name': PRIVATE_WORKSPACE, + }, + 'exp_after_rest_method': { + 'map_layers': [(LAYER_HRANICE_PRIVATE, 1, True)], + 'operates_on': [LAYER_HRANICE_PRIVATE], + }, + }, } +@pytest.mark.usefixtures('oauth2_provider_mock') class TestPublication(base_test.TestSingleRestPublication): workspace = WORKSPACE publication_type = process_client.MAP_TYPE rest_parametrization = [] + usernames_to_reserve = [PRIVATE_WORKSPACE] + test_cases = [base_test.TestCaseType(key=key, params=params, rest_args=params['rest_args'], @@ -74,10 +101,18 @@ class TestPublication(base_test.TestSingleRestPublication): type=EnumTestTypes.MANDATORY, ) for key, params in TEST_CASES.items()] - layer_uuids = {} - def before_class(self): - resp = self.post_publication(LAYER_HRANICE, args={ + self.post_publication(LAYER_HRANICE, args={ + 'file_paths': [ + 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.cpg', + 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.dbf', + 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.prj', + 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shp', + 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shx', + ], + }, scope='class') + + self.post_publication(LAYER_HRANICE_PRIVATE, args={ 'file_paths': [ 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.cpg', 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.dbf', @@ -85,10 +120,15 @@ def before_class(self): 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shp', 'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shx', ], + 'access_rights': {'read': PRIVATE_WORKSPACE, 'write': PRIVATE_WORKSPACE}, + 'actor_name': PRIVATE_WORKSPACE, }, scope='class') - self.layer_uuids[LAYER_HRANICE.name] = resp['uuid'] - def assert_exp_map_layers(self, map, exp_map_layers, exp_operates_on): + self.post_publication(MAP_HRANICE, args={ + 'file_paths': [os.path.join(DIRECTORY, 'internal_hranice.json')], + }, scope='class') + + def assert_exp_map_layers(self, map, exp_map_layers, exp_operates_on, http_method, actor_name): with app.app_context(): publ_info = get_publication_info(map.workspace, map.type, map.name, context={'keys': ['map_layers']}) @@ -101,20 +141,20 @@ def assert_exp_map_layers(self, map, exp_map_layers, exp_operates_on): for ml in publ_info['_map_layers'] } exp_map_layers = { - layer[:3] + ((self.layer_uuids[layer[1]] if layer[3] else None),) - for layer in exp_map_layers + (layer.workspace, layer.name, layer_index, self.publ_uuids[layer] if exists else None) + for layer, layer_index, exists in exp_map_layers } assert found_map_layers == exp_map_layers exp_operates_on = [ { - "xlink:href": f"http://localhost:3080/csw?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&OUTPUTSCHEMA=http://www.isotc211.org/2005/gmd&ID=m-{self.layer_uuids[layer_name]}#_m-{self.layer_uuids[layer_name]}", - "xlink:title": layer_name, + "xlink:href": f"http://localhost:3080/csw?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&OUTPUTSCHEMA=http://www.isotc211.org/2005/gmd&ID=m-{self.publ_uuids[layer]}#_m-{self.publ_uuids[layer]}", + "xlink:title": layer.name, } - for layer_name in exp_operates_on + for layer in exp_operates_on ] asserts_publ.metadata.correct_values_in_metadata( - map.workspace, map.type, map.name, http_method=REQUEST_METHOD_POST, exp_values={ + map.workspace, map.type, map.name, http_method=http_method, actor_name=actor_name, exp_values={ 'operates_on': exp_operates_on, }) @@ -123,7 +163,7 @@ def assert_exp_layer_maps(layer, map_operates_on_tuples): exp_layer_maps = sorted([ (map.workspace, map.name) for map, operates_on in map_operates_on_tuples - if layer.name in operates_on + if layer in operates_on ]) with app.app_context(): found_layer_maps = [ @@ -134,13 +174,22 @@ def assert_exp_layer_maps(layer, map_operates_on_tuples): def test_publication(self, map, rest_method, rest_args, params): exp = params['exp_before_rest_method'] - self.assert_exp_map_layers(map, exp['map_layers'], exp['operates_on']) - self.assert_exp_layer_maps(LAYER_HRANICE, [(map, exp['operates_on'] or [])]) + self.assert_exp_map_layers(map, exp['map_layers'], exp['operates_on'], http_method=REQUEST_METHOD_POST, + actor_name=params['post_before_test_args'].get('actor_name')) + self.assert_exp_layer_maps(LAYER_HRANICE, [ + (MAP_HRANICE, MAP_HRANICE_OPERATES_ON), + (map, exp['operates_on'] or []), + ]) rest_method(map, args=rest_args) - if rest_method == self.post_publication: # pylint: disable=W0143 + if rest_method in [self.post_publication, self.patch_publication]: assert_util.is_publication_valid_and_complete(map) exp = params['exp_after_rest_method'] - self.assert_exp_map_layers(map, exp['map_layers'], exp['operates_on']) - self.assert_exp_layer_maps(LAYER_HRANICE, [(map, exp['operates_on'] or [])]) + http_method = REQUEST_METHOD_PATCH if rest_method == self.patch_publication else REQUEST_METHOD_POST # pylint: disable=W0143 + self.assert_exp_map_layers(map, exp['map_layers'], exp['operates_on'], http_method=http_method, + actor_name=rest_args.get('actor_name')) + self.assert_exp_layer_maps(LAYER_HRANICE, [ + (MAP_HRANICE, MAP_HRANICE_OPERATES_ON), + (map, exp['operates_on'] or []), + ]) diff --git a/tests/static_data/__init__.py b/tests/static_data/__init__.py index a25e33fda..bd880e778 100644 --- a/tests/static_data/__init__.py +++ b/tests/static_data/__init__.py @@ -765,16 +765,6 @@ 'bbox': (1627490.9553976597, 6547334.172794042, 1716546.5480322787, 6589515.35758913), }, }, - (COMMON_WORKSPACE, MAP_TYPE, 'post_internal_layer'): { - DEFINITION: [ - {'file_paths': ['sample/layman.map/internal_url_thumbnail.json', ]}, - ], - TEST_DATA: { - 'layers': [(COMMON_WORKSPACE, LAYER_TYPE, 'post_blue_style'), ], - 'operates_on': {(COMMON_WORKSPACE, LAYER_TYPE, 'post_blue_style'), }, - 'thumbnail': 'sample/style/test_sld_style_applied_in_map_thumbnail_map.png', - }, - }, (OWNER, MAP_TYPE, 'post_private'): { DEFINITION: [ {'headers': HEADERS[OWNER]}, @@ -795,37 +785,6 @@ 'bbox': (3000, 3000, 5000, 5000), }, }, - (OWNER, MAP_TYPE, 'post_unauthorized_layer'): { - DEFINITION: [ - {'file_paths': ['sample/layman.map/internal_url_unauthorized_layer.json'], - 'access_rights': {'read': 'EVERYONE', - 'write': f"{OWNER},{OWNER2}", - }, - 'headers': HEADERS[OWNER], - }, - ], - TEST_DATA: { - 'layers': [(OWNER, LAYER_TYPE, 'post_private_sld'), (OWNER2, LAYER_TYPE, 'post_private_sld2'), ], - 'operates_on': {(OWNER, LAYER_TYPE, 'post_private_sld'), }, - 'users_can_write': [OWNER, OWNER2], - }, - }, - (OWNER, MAP_TYPE, 'patch_unauthorized_layer'): { - DEFINITION: [ - {'file_paths': ['sample/layman.map/internal_url_unauthorized_layer.json'], - 'access_rights': {'read': 'EVERYONE', - 'write': f"{OWNER},{OWNER2}", - }, - 'headers': HEADERS[OWNER], - }, - {'headers': HEADERS[OWNER2], } - ], - TEST_DATA: { - 'layers': [(OWNER, LAYER_TYPE, 'post_private_sld'), (OWNER2, LAYER_TYPE, 'post_private_sld2'), ], - 'operates_on': {(OWNER2, LAYER_TYPE, 'post_private_sld2'), }, - 'users_can_write': [OWNER, OWNER2], - }, - }, (WORKSPACE1, MAP_TYPE, 'test_publications_same_name_publ'): { DEFINITION: [ {}, @@ -848,7 +807,6 @@ # if (ws, pt, pn) in {(COMMON_WORKSPACE, LAYER_TYPE, 'post_common_sld'), # (COMMON_WORKSPACE, LAYER_TYPE, 'post_common_qml'), # (COMMON_WORKSPACE, LAYER_TYPE, 'post_jp2'), -# (COMMON_WORKSPACE, MAP_TYPE, 'post_internal_layer'), # (COMMON_WORKSPACE, LAYER_TYPE, 'post_blue_style'), # (COMMON_WORKSPACE, LAYER_TYPE, 'post_10countries_sld'), # }} @@ -865,9 +823,6 @@ LIST_QML_LAYERS = [(workspace, publ_type, publication) for (workspace, publ_type, publication), values in PUBLICATIONS.items() if publ_type == LAYER_TYPE and values[TEST_DATA].get('style_type') == 'qml'] -LIST_INTERNAL_MAPS = [(workspace, publ_type, publication) for (workspace, publ_type, publication), values in PUBLICATIONS.items() - if publ_type == MAP_TYPE and values[TEST_DATA].get('layers')] - WORKSPACES = {workspace for workspace, _, _ in PUBLICATIONS} assert len(WORKSPACES) > 0, WORKSPACES @@ -880,7 +835,6 @@ assert len(LIST_VECTOR_LAYERS) > 0, LIST_VECTOR_LAYERS assert len(LIST_SLD_LAYERS) > 0, LIST_SLD_LAYERS assert len(LIST_QML_LAYERS) > 0, LIST_QML_LAYERS -assert len(LIST_INTERNAL_MAPS) > 0, LIST_INTERNAL_MAPS assert any('normalized_overviews' in v[TEST_DATA] for v in PUBLICATIONS.values()) diff --git a/tests/static_data/multi_publications/__init__.py b/tests/static_data/multi_publications/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/static_data/multi_publications/publications_test.py b/tests/static_data/multi_publications/publications_test.py deleted file mode 100644 index 36d2c8b4b..000000000 --- a/tests/static_data/multi_publications/publications_test.py +++ /dev/null @@ -1,23 +0,0 @@ -import pytest -from layman import app -from layman.util import get_publication_info -from ... import static_data as data -from ..data import ensure_all_publications - - -@pytest.mark.timeout(600) -@pytest.mark.usefixtures('oauth2_provider_mock', 'ensure_layman') -def test_find_maps_containing_layer(): - ensure_all_publications() - - for l_workspace, l_type, layer in data.LIST_LAYERS: - expected_maps = {(workspace, publication) - for (workspace, publ_type, publication), values in data.PUBLICATIONS.items() - if publ_type == data.MAP_TYPE and (l_workspace, l_type, layer) in values[data.TEST_DATA].get('layers', [])} - - with app.app_context(): - result_maps = { - (mo['workspace'], mo['name']) - for mo in get_publication_info(l_workspace, l_type, layer, context={'keys': ['layer_maps']})['_layer_maps'] - } - assert result_maps == expected_maps diff --git a/tests/static_data/single_publication/layers_test.py b/tests/static_data/single_publication/layers_test.py index 9d8de3e28..efe75313d 100644 --- a/tests/static_data/single_publication/layers_test.py +++ b/tests/static_data/single_publication/layers_test.py @@ -29,6 +29,7 @@ } +@pytest.mark.timeout(600) @pytest.mark.parametrize('workspace, publ_type, publication', data.LIST_LAYERS) @pytest.mark.usefixtures('oauth2_provider_mock', 'ensure_layman') def test_info(workspace, publ_type, publication): diff --git a/tests/static_data/single_publication/maps_test.py b/tests/static_data/single_publication/maps_test.py deleted file mode 100644 index 151fc0815..000000000 --- a/tests/static_data/single_publication/maps_test.py +++ /dev/null @@ -1,41 +0,0 @@ -import json -import pytest - -from layman import app, util as layman_util -from test_tools import process_client -from ... import static_data as data -from ..data import ensure_publication - - -def assert_operates_on(workspace, mapname, expected_layers, authz_headers): - md_comparison = process_client.get_workspace_map_metadata_comparison(workspace, mapname, authz_headers) - operates_on = md_comparison['metadata_properties']['operates_on'] - assert (operates_on['equal']), json.dumps(operates_on, indent=2) - assert (operates_on['equal_or_null']), json.dumps(operates_on, indent=2) - assert len(operates_on['values'].values()) == 2 # GET Map File, CSW - - for operates_on_value in operates_on['values'].values(): - for (layer_uuid, layer_title) in expected_layers: - layer_record = next(rec for rec in operates_on_value - if rec['xlink:title'] == layer_title and layer_uuid in rec['xlink:href']) - assert layer_record, f"Layer uuid={layer_uuid}, title={layer_title} not found in operates_on value {json.dumps(operates_on_value, indent=2)}" - assert len(expected_layers) == len( - operates_on_value), f"Expected layers {expected_layers}, found {json.dumps(operates_on_value, indent=2)}" - - -@pytest.mark.parametrize('workspace, publ_type, publication', data.LIST_INTERNAL_MAPS) -@pytest.mark.usefixtures('oauth2_provider_mock', 'ensure_layman') -def test_map_with_unauthorized_layer(workspace, publ_type, publication): - ensure_publication(workspace, publ_type, publication) - - operates_on_layers = data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA]['operates_on'] - exp_operates_on = [] - for layer_workspace, layer_type, layer in operates_on_layers: - with app.app_context(): - info = layman_util.get_publication_info(layer_workspace, layer_type, layer, context={'keys': ['uuid', 'title']}) - uuid = info['uuid'] - title = info['title'] - exp_operates_on.append((uuid, title)) - - for headers in data.HEADERS.values(): - assert_operates_on(workspace, publication, exp_operates_on, authz_headers=headers)