diff --git a/src/layman/map/micka/csw.py b/src/layman/map/micka/csw.py index a48da5de7..774f80411 100644 --- a/src/layman/map/micka/csw.py +++ b/src/layman/map/micka/csw.py @@ -1,6 +1,5 @@ from datetime import datetime, date from functools import partial -import re import os import traceback from xml.sax.saxutils import escape @@ -9,16 +8,15 @@ from flask import current_app import crs as crs_def -from layman import common, settings +from layman import common, settings, util as layman_util from layman.common import language as common_language, empty_method, empty_method_returns_none, bbox as bbox_util from layman.common.filesystem.uuid import get_publication_uuid_file from layman.common.micka import util as common_util, requests as micka_requests +from layman.common.micka.util import get_metadata_uuid +from layman.layer import LAYER_TYPE from layman.map import MAP_TYPE from layman.map.filesystem.uuid import get_map_uuid -from layman.map.filesystem.input_file import get_map_json, unquote_urls -from layman.layer import LAYER_TYPE -from layman.layer.geoserver.util import get_gs_proxy_base_url -from layman.util import url_for, WORKSPACE_NAME_ONLY_PATTERN, get_publication_info +from layman.util import url_for, get_publication_info get_publication_uuid = empty_method_returns_none post_map = empty_method @@ -106,50 +104,40 @@ def csw_insert(workspace, mapname, actor_name): return muuid -def map_json_to_operates_on(map_json, operates_on_muuids_filter=None, editor=None): - # Either caller know muuids or wants filter by editor, never both at the same time - assert not operates_on_muuids_filter or not editor - unquote_urls(map_json) - gs_url = get_gs_proxy_base_url() - gs_url = gs_url if gs_url.endswith('/') else f"{gs_url}/" - gs_wms_url_pattern = r'^' + re.escape(gs_url) + r'(' + WORKSPACE_NAME_ONLY_PATTERN + r')' + \ - settings.LAYMAN_GS_WMS_WORKSPACE_POSTFIX + r'/(?:ows|wms|wfs).*$' - layman_layer_names = [] - for map_layer in map_json['layers']: - layer_url = map_layer.get('url', None) - if not layer_url: - continue - # print(f"layer_url={layer_url}") - match = re.match(gs_wms_url_pattern, layer_url) - if not match: - continue - layer_workspace = match.group(1) - if not layer_workspace: - continue - # print(f"layer_workspace={layer_workspace}") - layer_names = [ - n for n in map_layer.get('params', {}).get('LAYERS', '').split(',') - if len(n) > 0 - ] - if not layer_names: +def map_layers_to_operates_on_layers(map_layers): + used_uuids = set() + operates_on = [] + for map_layer in map_layers: + if not map_layer['uuid']: continue - for layername in layer_names: - layman_layer_names.append((layer_workspace, layername)) + if map_layer['uuid'] not in used_uuids: + operates_on.append(map_layer) + used_uuids.add(map_layer['uuid']) + return operates_on + + +def map_to_operates_on(workspace, mapname, operates_on_muuids_filter=None, editor=None): + # Either caller know muuids or wants filter by editor, never both at the same time, at least one must be used + assert (operates_on_muuids_filter is None) != (editor is None) + publ_info = layman_util.get_publication_info(workspace, MAP_TYPE, mapname, context={'keys': ['map_layers']}) + operates_on_layers = map_layers_to_operates_on_layers(publ_info['_map_layers']) + operates_on = [] csw_url = settings.CSW_PROXY_URL - for (layer_workspace, layername) in layman_layer_names: - layer_md_info = get_publication_info(layer_workspace, LAYER_TYPE, layername, context={'keys': ['metadata', ], }) - layer_muuid = layer_md_info.get('metadata', {}).get('identifier') + for internal_layer in operates_on_layers: + layer_workspace = internal_layer['workspace'] + layername = internal_layer['name'] + layer_muuid = get_metadata_uuid(internal_layer['uuid']) + context = {'keys': ['title']} if operates_on_muuids_filter is not None: if layer_muuid not in operates_on_muuids_filter: continue - layer_wms_info = get_publication_info(layer_workspace, LAYER_TYPE, layername, context={'keys': ['wms', ], }) else: - layer_wms_info = get_publication_info(layer_workspace, LAYER_TYPE, layername, context={'keys': ['wfs', ], - 'actor_name': editor, }) - if not (layer_muuid and layer_wms_info): - continue - layer_title = layer_wms_info['title'] + context['actor_name'] = editor + publ_info = get_publication_info(layer_workspace, LAYER_TYPE, layername, context=context) + if not (layer_muuid and publ_info): + continue + layer_title = publ_info['title'] layer_csw_url = f"{csw_url}?SERVICE=CSW&VERSION=2.0.2&REQUEST=GetRecordById&OUTPUTSCHEMA=http://www.isotc211.org/2005/gmd&ID={layer_muuid}#_{layer_muuid}" operates_on.append({ 'xlink:title': layer_title, @@ -158,13 +146,12 @@ def map_json_to_operates_on(map_json, operates_on_muuids_filter=None, editor=Non return operates_on -def get_template_path_and_values(workspace, mapname, http_method=None, actor_name=None): +def get_template_path_and_values(workspace, mapname, *, http_method=None, actor_name): assert http_method in [common.REQUEST_METHOD_POST, common.REQUEST_METHOD_PATCH] uuid_file_path = get_publication_uuid_file(MAP_TYPE, workspace, mapname) publ_datetime = datetime.fromtimestamp(os.path.getmtime(uuid_file_path)) revision_date = datetime.now() - map_json = get_map_json(workspace, mapname) - operates_on = map_json_to_operates_on(map_json, editor=actor_name) + operates_on = map_to_operates_on(workspace, mapname, editor=actor_name) publ_info = get_publication_info(workspace, MAP_TYPE, mapname, context={ 'keys': ['title', 'native_bounding_box', 'description', 'native_crs'], }) diff --git a/src/layman/map/micka/csw_test.py b/src/layman/map/micka/csw_test.py index 3fc6f5368..0e475f6ae 100644 --- a/src/layman/map/micka/csw_test.py +++ b/src/layman/map/micka/csw_test.py @@ -15,7 +15,7 @@ from layman.common.micka import util as common_util from layman.map.rest_workspace_test import wait_till_ready from test_tools.mock.micka import run -from .csw import get_map_info, delete_map +from .csw import get_map_info, delete_map, map_layers_to_operates_on_layers MICKA_PORT = 8020 @@ -184,3 +184,48 @@ def test_public_metadata(provide_map): response = requests.get(micka_url, timeout=settings.DEFAULT_CONNECTION_TIMEOUT) response.raise_for_status() assert muuid in response.text, f"Metadata record {muuid} is not public!" + + +LAYER1_WS1_IDX0_EXISTING = { + 'name': 'layer1', + 'workspace': 'workspace1', + 'index': 0, + 'uuid': '9cfa8262-9910-4c4c-89a8-c665bcd5b88f', +} +LAYER2_WS1_IDX0_NON_EXISTENT = { + 'name': 'layer2', + 'workspace': 'workspace1', + 'index': 0, + 'uuid': None, +} +LAYER3_WS2_IDX2_EXISTING = { + 'name': 'layer3', + 'workspace': 'workspace2', + 'index': 2, + 'uuid': '36a9dec6-1a99-4ea4-88ef-bd88ba715b4c', +} +LAYER1_WS1_IDX2_EXISTING = { + 'name': 'layer1', + 'workspace': 'workspace1', + 'index': 2, + 'uuid': '9cfa8262-9910-4c4c-89a8-c665bcd5b88f', +} + + +@pytest.mark.parametrize('map_layers, exp_result', [ + pytest.param([], [], id='empty_list'), + pytest.param([LAYER1_WS1_IDX0_EXISTING], [LAYER1_WS1_IDX0_EXISTING], id='one_existing_layer'), + pytest.param([LAYER2_WS1_IDX0_NON_EXISTENT], [], id='one_non_existent_layer'), + pytest.param([LAYER1_WS1_IDX0_EXISTING, LAYER3_WS2_IDX2_EXISTING], + [LAYER1_WS1_IDX0_EXISTING, LAYER3_WS2_IDX2_EXISTING], id='two_existing_layers'), + pytest.param([LAYER1_WS1_IDX0_EXISTING, LAYER1_WS1_IDX2_EXISTING], + [LAYER1_WS1_IDX0_EXISTING], id='one_existing_layer_twice'), + pytest.param([LAYER1_WS1_IDX2_EXISTING, LAYER3_WS2_IDX2_EXISTING], + [LAYER1_WS1_IDX2_EXISTING, LAYER3_WS2_IDX2_EXISTING], id='two_existing_layers_at_same_index'), + pytest.param( + [LAYER1_WS1_IDX0_EXISTING, LAYER2_WS1_IDX0_NON_EXISTENT, LAYER3_WS2_IDX2_EXISTING, LAYER1_WS1_IDX2_EXISTING], + [LAYER1_WS1_IDX0_EXISTING, LAYER3_WS2_IDX2_EXISTING], id='complex'), +]) +def test_map_layers_to_operates_on_layers(map_layers, exp_result): + result = map_layers_to_operates_on_layers(map_layers) + assert result == exp_result diff --git a/src/layman/map/rest_workspace_test.py b/src/layman/map/rest_workspace_test.py index 308a2d51e..349449990 100644 --- a/src/layman/map/rest_workspace_test.py +++ b/src/layman/map/rest_workspace_test.py @@ -726,7 +726,8 @@ def test_map_composed_from_local_layers(client): with app.app_context(): # assert metadata file is the same as filled template except for UUID and dates - template_path, prop_values = csw.get_template_path_and_values(workspace, mapname, http_method='post') + template_path, prop_values = csw.get_template_path_and_values(workspace, mapname, http_method='post', + actor_name=settings.ANONYM_USER) xml_file_object = micka_common_util.fill_xml_template_as_pretty_file_object(template_path, prop_values, csw.METADATA_PROPERTIES) expected_path = 'src/layman/map/rest_test_filled_template.xml' diff --git a/src/layman/map/util.py b/src/layman/map/util.py index 651895142..f8d7c2826 100644 --- a/src/layman/map/util.py +++ b/src/layman/map/util.py @@ -20,7 +20,7 @@ from . import get_map_sources, MAP_TYPE, get_map_type_def, get_map_info_keys from .filesystem import input_file from .micka import csw -from .micka.csw import map_json_to_operates_on +from .micka.csw import map_to_operates_on MAPNAME_PATTERN = PUBLICATION_NAME_PATTERN MAPNAME_MAX_LENGTH = PUBLICATION_MAX_LENGTH @@ -299,11 +299,11 @@ def get_crs_from_json(map_json): return map_json['projection'].upper() -def map_file_to_metadata_properties(map_json, operates_on_muuids_filter): +def map_file_to_metadata_properties(workspace, mapname, map_json, operates_on_muuids_filter): result = { 'title': map_json['title'], 'abstract': map_json['abstract'], - 'operates_on': map_json_to_operates_on(map_json, operates_on_muuids_filter=operates_on_muuids_filter), + 'operates_on': map_to_operates_on(workspace, mapname, operates_on_muuids_filter=operates_on_muuids_filter), 'extent': list(get_bbox_from_json(map_json)), 'reference_system': [get_crs_from_json(map_json)], } @@ -325,7 +325,7 @@ def get_metadata_comparison(workspace, mapname): if map_json: soap_operates_on = next(iter(partial_infos[csw].values()))['operates_on'] if partial_infos[csw] else [] operates_on_muuids_filter = micka_util.operates_on_values_to_muuids(soap_operates_on) - layman_file_props = map_file_to_metadata_properties(map_json, operates_on_muuids_filter) + layman_file_props = map_file_to_metadata_properties(workspace, mapname, map_json, operates_on_muuids_filter) map_file_url = url_for('rest_workspace_map_file.get', mapname=mapname, workspace=workspace) all_props[map_file_url] = layman_file_props @@ -387,7 +387,7 @@ def get_layers_from_json(map_json): re.escape(layman_settings.LAYMAN_GS_PATH) + \ r'(?:(?P' + layman_util.WORKSPACE_NAME_ONLY_PATTERN + r')/)?' \ + r'(?:ows|wms|wfs).*$' - found_layers = set() + found_layers = [] for layer_idx, map_layer in enumerate(map_json['layers']): class_name = map_layer.get('className', '').split('.')[-1] layer_url_getter = { @@ -422,5 +422,7 @@ def get_layers_from_json(map_json): if not match: continue layer_workspace = get_layman_workspace(layer_geoserver_workspace) - found_layers.add((layer_workspace, layername, layer_idx)) + layer_def = (layer_workspace, layername, layer_idx) + if layer_def not in found_layers: + found_layers.append(layer_def) return found_layers diff --git a/src/layman/map/util_test.py b/src/layman/map/util_test.py index a1a79b412..f82f4234b 100644 --- a/src/layman/map/util_test.py +++ b/src/layman/map/util_test.py @@ -3,31 +3,31 @@ @pytest.mark.parametrize('json_path, exp_result', [ - pytest.param('sample/layman.map/internal_url.json', { + pytest.param('sample/layman.map/internal_url.json', [ ('testuser1', 'hranice', 1), ('testuser1', 'mista', 2), ('testuser1', 'hranice', 3), - }, id='two_internal_wms_layers,one_internal_wfs_layer'), - pytest.param('sample/layman.map/internal_url_two_wms_layers_in_one.json', { + ], id='two_internal_wms_layers,one_internal_wfs_layer'), + pytest.param('sample/layman.map/internal_url_two_wms_layers_in_one.json', [ ('testuser1', 'hranice', 0), ('testuser1', 'mista', 0), - }, id='two_internal_wms_layers_in_one'), - pytest.param('sample/layman.map/internal_url_wms_workspace_in_layername.json', { + ], id='two_internal_wms_layers_in_one'), + pytest.param('sample/layman.map/internal_url_wms_workspace_in_layername.json', [ ('testuser1', 'hranice', 0), ('testuser2', 'mista', 0), - }, id='two_internal_wms_layers_in_one,workspace_in_layername'), - pytest.param('sample/layman.map/internal_url_wms_layers_with_client_proxy.json', { + ], id='two_internal_wms_layers_in_one,workspace_in_layername'), + pytest.param('sample/layman.map/internal_url_wms_layers_with_client_proxy.json', [ ('testuser1', 'hranice', 0), ('testuser1', 'mista', 1), - }, id='two_internal_wms_layers_with_client_proxy'), - pytest.param('sample/layman.map/internal_url_wms_layer_in_wfs_workspace.json', { + ], id='two_internal_wms_layers_with_client_proxy'), + pytest.param('sample/layman.map/internal_url_wms_layer_in_wfs_workspace.json', [ ('testuser1', 'hranice', 0), - }, id='one_internal_wms_layer_in_wfs_workspace'), - pytest.param('sample/layman.map/internal_url_wfs_workspace_in_layername.json', { + ], id='one_internal_wms_layer_in_wfs_workspace'), + pytest.param('sample/layman.map/internal_url_wfs_workspace_in_layername.json', [ ('testuser1', 'hranice', 0), - }, id='one_internal_wfs_layer,workspace_in_layername'), - pytest.param('sample/layman.map/internal_external_edge_cases.json', set(), id='empty_edge_cases'), - pytest.param('sample/layman.map/full.json', set(), id='external_layers_only'), + ], id='one_internal_wfs_layer,workspace_in_layername'), + pytest.param('sample/layman.map/internal_external_edge_cases.json', [], id='empty_edge_cases'), + pytest.param('sample/layman.map/full.json', [], id='external_layers_only'), ]) def test_get_layers_from_json(json_path, exp_result): with open(json_path, 'r', encoding="utf-8") as map_file: diff --git a/src/layman/upgrade/upgrade_v1_22.py b/src/layman/upgrade/upgrade_v1_22.py index da39adf08..5b965b2ca 100644 --- a/src/layman/upgrade/upgrade_v1_22.py +++ b/src/layman/upgrade/upgrade_v1_22.py @@ -95,7 +95,7 @@ def insert_map_layer_relations(): map_layers = map_util.get_layers_from_json(map_json) except FileNotFoundError: logger.warning(f'File not found for map {workspace}.{map_name}, map file path {map_file_path}') - map_layers = set() + map_layers = [] for layer_workspace, layer_name, layer_index in map_layers: insert_query = f''' insert into {DB_SCHEMA}.map_layer(id_map, layer_workspace, layer_name, layer_index) values (%s, %s, %s, %s); diff --git a/tests/asserts/final/publication/internal.py b/tests/asserts/final/publication/internal.py index c6d1e097f..125c4df01 100644 --- a/tests/asserts/final/publication/internal.py +++ b/tests/asserts/final/publication/internal.py @@ -459,5 +459,5 @@ def consistent_internal_map_layers(workspace, publ_type, name): pub_info = layman_util.get_publication_info(workspace, publ_type, name, {'keys': ['map_layers']}) map_json = map_input_file.get_map_json(workspace, name) layers_from_file = map_util.get_layers_from_json(map_json) - layers_from_info = {(ml['workspace'], ml['name'], ml['index']) for ml in pub_info['_map_layers']} + layers_from_info = [(ml['workspace'], ml['name'], ml['index']) for ml in pub_info['_map_layers']] assert layers_from_file == layers_from_info diff --git a/tests/asserts/final/publication/metadata.py b/tests/asserts/final/publication/metadata.py index 3ca9d2c23..d8f9219d7 100644 --- a/tests/asserts/final/publication/metadata.py +++ b/tests/asserts/final/publication/metadata.py @@ -1,8 +1,9 @@ -from layman import app -from layman.layer.micka import csw as csw_util +from layman import app, settings +from layman.layer.micka import csw as layer_csw_util +from layman.map.micka import csw as map_csw_util from test_tools import process_client, assert_util -METADATA_PROPERTIES = { +LAYER_METADATA_PROPERTIES = { 'abstract', 'extent', 'graphic_url', @@ -20,11 +21,29 @@ 'wms_url', } +MAP_METADATA_PROPERTIES = { + 'abstract', + 'extent', + 'graphic_url', + 'identifier', + 'map_endpoint', + 'map_file_endpoint', + 'operates_on', + 'organisation_name', + 'publication_date', + 'reference_system', + 'revision_date', + 'title', +} + def expected_values_in_micka_metadata(workspace, publ_type, name, expected_values): - assert publ_type == process_client.LAYER_TYPE + md_comparison_method = { + process_client.LAYER_TYPE: layer_csw_util.get_metadata_comparison, + process_client.MAP_TYPE: map_csw_util.get_metadata_comparison, + }[publ_type] with app.app_context(): - md_dict = csw_util.get_metadata_comparison(workspace, name) + md_dict = md_comparison_method(workspace, name) assert len(md_dict) == 1 md_record = next(iter(md_record for md_record in md_dict.values())) @@ -34,19 +53,28 @@ def expected_values_in_micka_metadata(workspace, publ_type, name, expected_value ) -def correct_values_in_layer_metadata(workspace, publ_type, name, http_method): - assert publ_type == process_client.LAYER_TYPE +def correct_values_in_metadata(workspace, publ_type, name, http_method, *, exp_values=None): + exp_values = exp_values or {} + 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_layer_metadata_comparison(workspace, name,) - assert METADATA_PROPERTIES.issubset(set(resp_json['metadata_properties'].keys())) + resp_json = process_client.get_workspace_publication_metadata_comparison(publ_type, workspace, 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}' assert value['equal'] is True, f'key={key}, value={value}' + 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}), + }[publ_type] with app.app_context(): - _, md_values = csw_util.get_template_path_and_values(workspace, - name, - http_method=http_method) - exp_metadata = {key: value for key, value in md_values.items() if key in METADATA_PROPERTIES} - exp_metadata['reference_system'] = [int(crs.split(':')[1]) for crs in exp_metadata['reference_system']] + _, md_values = get_template_path_and_values_method(workspace, name, http_method=http_method, **args) + exp_metadata = {key: value for key, value in md_values.items() if key in md_props} + if publ_type == process_client.LAYER_TYPE: + exp_metadata['reference_system'] = [int(crs.split(':')[1]) for crs in exp_metadata['reference_system']] + for key, value in exp_values.items(): + assert exp_metadata[key] == value, f"Template value differ from expected value, key={key}" expected_values_in_micka_metadata(workspace, publ_type, name, exp_metadata) diff --git a/tests/dynamic_data/publications/layer_timeseries/timeseries_test.py b/tests/dynamic_data/publications/layer_timeseries/timeseries_test.py index 993f4177a..239a205be 100644 --- a/tests/dynamic_data/publications/layer_timeseries/timeseries_test.py +++ b/tests/dynamic_data/publications/layer_timeseries/timeseries_test.py @@ -369,7 +369,7 @@ def test_timeseries_layer(self, layer: Publication, params, rest_method, rest_ar else: raise NotImplementedError(f"Unknown rest_method: {rest_method}") - asserts_publ.metadata.correct_values_in_layer_metadata(layer.workspace, layer.type, layer.name, http_method=http_method) + asserts_publ.metadata.correct_values_in_metadata(layer.workspace, layer.type, layer.name, http_method=http_method) process_client.patch_workspace_layer(layer.workspace, layer.name, 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.py index 320278b12..baf1d6995 100644 --- a/tests/dynamic_data/publications/map_layer_relation/map_layer_relation.py +++ b/tests/dynamic_data/publications/map_layer_relation/map_layer_relation.py @@ -1,8 +1,10 @@ import os from layman import app +from layman.common import REQUEST_METHOD_POST from layman.util import get_publication_info from test_tools import process_client from tests import EnumTestTypes, Publication +from tests.asserts.final import publication as asserts_publ from tests.asserts.final.publication import util as assert_util from tests.dynamic_data import base_test, base_test_classes @@ -18,12 +20,18 @@ 'file_paths': [os.path.join(DIRECTORY, 'internal_wms_and_wfs.json')], }, 'post_before_test_args': {}, - 'exp_map_layers_before_rest_method': None, - 'exp_map_layers_after_rest_method': { - # workspace, layer name, layer index, exists? - ('layer_map_relation_workspace', 'hranice', 1, True), - ('layer_map_relation_workspace', 'mista', 2, False), - ('layer_map_relation_workspace', 'hranice', 3, True), + 'exp_before_rest_method': { + 'map_layers': None, + 'operates_on': None, + }, + 'exp_after_rest_method': { + 'map_layers': { + # workspace, layer name, layer index, exists? + ('layer_map_relation_workspace', 'hranice', 1, True), + ('layer_map_relation_workspace', 'mista', 2, False), + ('layer_map_relation_workspace', 'hranice', 3, True), + }, + 'operates_on': ['hranice'], }, }, 'delete': { @@ -32,12 +40,18 @@ 'post_before_test_args': { 'file_paths': [os.path.join(DIRECTORY, 'internal_wms_and_wfs.json')], }, - 'exp_map_layers_before_rest_method': { - ('layer_map_relation_workspace', 'hranice', 1, True), - ('layer_map_relation_workspace', 'mista', 2, False), - ('layer_map_relation_workspace', 'hranice', 3, True), + 'exp_before_rest_method': { + 'map_layers': { + ('layer_map_relation_workspace', 'hranice', 1, True), + ('layer_map_relation_workspace', 'mista', 2, False), + ('layer_map_relation_workspace', 'hranice', 3, True), + }, + 'operates_on': ['hranice'], + }, + 'exp_after_rest_method': { + 'map_layers': None, + 'operates_on': None, }, - 'exp_map_layers_after_rest_method': None, }, } @@ -71,9 +85,10 @@ def before_class(self): }, scope='class') self.layer_uuids[layer_name] = resp['uuid'] - def assert_exp_map_layers(self, publ_info, exp_map_layers): + def assert_exp_map_layers(self, map, publ_info, exp_map_layers, exp_operates_on): if exp_map_layers is None: assert not publ_info + assert exp_operates_on is None else: found_map_layers = { (ml['workspace'], ml['name'], ml['index'], ml['uuid']) @@ -85,17 +100,31 @@ def assert_exp_map_layers(self, publ_info, 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, + } + for layer_name in exp_operates_on + ] + asserts_publ.metadata.correct_values_in_metadata( + map.workspace, map.type, map.name, http_method=REQUEST_METHOD_POST, exp_values={ + 'operates_on': exp_operates_on, + }) + def test_publication(self, map, rest_method, rest_args, params): with app.app_context(): publ_info = get_publication_info(map.workspace, map.type, map.name, context={'keys': ['map_layers']}) - self.assert_exp_map_layers(publ_info, params['exp_map_layers_before_rest_method']) + self.assert_exp_map_layers(map, publ_info, params['exp_before_rest_method']['map_layers'], + params['exp_before_rest_method']['operates_on']) rest_method(map, args=rest_args) - if params['rest_method'] == base_test_classes.RestMethodAll.POST: + if rest_method == self.post_publication: # pylint: disable=W0143 assert_util.is_publication_valid_and_complete(map) with app.app_context(): publ_info = get_publication_info(map.workspace, map.type, map.name, context={'keys': ['map_layers']}) - self.assert_exp_map_layers(publ_info, params['exp_map_layers_after_rest_method']) + self.assert_exp_map_layers(map, publ_info, params['exp_after_rest_method']['map_layers'], + params['exp_after_rest_method']['operates_on'])