Skip to content

Commit

Permalink
Extend correct_values_in_metadata also for maps
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Sep 8, 2023
1 parent 19c2496 commit 765a0b1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
53 changes: 39 additions & 14 deletions tests/asserts/final/publication/metadata.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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()))
Expand All @@ -34,19 +53,25 @@ 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):
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']]
expected_values_in_micka_metadata(workspace, publ_type, name, exp_metadata)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -94,6 +96,8 @@ def test_publication(self, map, rest_method, rest_args, params):
rest_method(map, args=rest_args)
if rest_method == self.post_publication: # pylint: disable=W0143
assert_util.is_publication_valid_and_complete(map)
asserts_publ.metadata.correct_values_in_metadata(map.workspace, map.type, map.name,
http_method=REQUEST_METHOD_POST)

with app.app_context():
publ_info = get_publication_info(map.workspace, map.type, map.name,
Expand Down

0 comments on commit 765a0b1

Please sign in to comment.