Skip to content

Commit

Permalink
Test layer_maps key in map_layer_relation.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jirik committed Sep 12, 2023
1 parent 634fdc5 commit d1b8188
Showing 1 changed file with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

DIRECTORY = os.path.dirname(os.path.abspath(__file__))

WORKSPACE = 'layer_map_relation_workspace'

LAYER_HRANICE = Publication(WORKSPACE, process_client.LAYER_TYPE, 'hranice')

TEST_CASES = {
'post': {
'rest_method': base_test_classes.RestMethodAll.POST,
Expand All @@ -27,9 +31,9 @@
'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),
(WORKSPACE, 'hranice', 1, True),
(WORKSPACE, 'mista', 2, False),
(WORKSPACE, 'hranice', 3, True),
},
'operates_on': ['hranice'],
},
Expand All @@ -42,9 +46,9 @@
},
'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),
(WORKSPACE, 'hranice', 1, True),
(WORKSPACE, 'mista', 2, False),
(WORKSPACE, 'hranice', 3, True),
},
'operates_on': ['hranice'],
},
Expand All @@ -57,7 +61,7 @@


class TestPublication(base_test.TestSingleRestPublication):
workspace = 'layer_map_relation_workspace'
workspace = WORKSPACE
publication_type = process_client.MAP_TYPE

rest_parametrization = []
Expand All @@ -73,8 +77,7 @@ class TestPublication(base_test.TestSingleRestPublication):
layer_uuids = {}

def before_class(self):
layer_name = 'hranice'
resp = self.post_publication(Publication(self.workspace, process_client.LAYER_TYPE, layer_name), args={
resp = 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',
Expand All @@ -83,9 +86,12 @@ def before_class(self):
'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shx',
],
}, scope='class')
self.layer_uuids[layer_name] = resp['uuid']
self.layer_uuids[LAYER_HRANICE.name] = resp['uuid']

def assert_exp_map_layers(self, map, publ_info, exp_map_layers, exp_operates_on):
def assert_exp_map_layers(self, map, exp_map_layers, exp_operates_on):
with app.app_context():
publ_info = get_publication_info(map.workspace, map.type, map.name,
context={'keys': ['map_layers']})
if exp_map_layers is None:
assert not publ_info
assert exp_operates_on is None
Expand All @@ -112,19 +118,29 @@ def assert_exp_map_layers(self, map, publ_info, exp_map_layers, exp_operates_on)
'operates_on': exp_operates_on,
})

def test_publication(self, map, rest_method, rest_args, params):
@staticmethod
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
])
with app.app_context():
publ_info = get_publication_info(map.workspace, map.type, map.name,
context={'keys': ['map_layers']})
self.assert_exp_map_layers(map, publ_info, params['exp_before_rest_method']['map_layers'],
params['exp_before_rest_method']['operates_on'])
found_layer_maps = [
(m['workspace'], m['name'])
for m in get_publication_info(*layer, context={'keys': ['layer_maps']})['_layer_maps']
]
assert found_layer_maps == exp_layer_maps

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 [])])

rest_method(map, args=rest_args)
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(map, publ_info, params['exp_after_rest_method']['map_layers'],
params['exp_after_rest_method']['operates_on'])
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 [])])

0 comments on commit d1b8188

Please sign in to comment.