Skip to content

Commit

Permalink
Define Micka test data in data definition, not hard coded in test
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Aug 3, 2021
1 parent aca8756 commit 407d2a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
17 changes: 17 additions & 0 deletions tests/static_publications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@
'bbox': (-20026376.39, -20048966.1, 20026376.39, 18440002.895114236),
'file_type': settings.FILE_TYPE_VECTOR,
'style_type': 'sld',
'micka_xml': {'filled_template': 'test_tools/data/micka/rest_test_filled_template.xml',
'diff_lines': [
{'plus_line': '+ <gco:CharacterString>m-81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>\n',
'starts_with': '- <gco:CharacterString>m',
'ends_with': '</gco:CharacterString>\n',
},
{'plus_line': '+ <gco:Date>2007-05-25</gco:Date>\n',
'starts_with': '- <gco:Date>',
'ends_with': '</gco:Date>\n',
},
{'plus_line': '+ <gco:Date>2019-12-07</gco:Date>\n',
'starts_with': '- <gco:Date>',
'ends_with': '</gco:Date>\n',
},
],
'diff_lines_len': 29,
},
'micka_filled_template': 'test_tools/data/micka/rest_test_filled_template.xml',
},
},
Expand Down
34 changes: 14 additions & 20 deletions tests/static_publications/single_publication/layers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_gs_data_security(workspace, publ_type, publication):

@pytest.mark.parametrize('workspace, publ_type, publication', [(workspace, publ_type, publication)
for (workspace, publ_type, publication) in data.LIST_LAYERS
if data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('micka_filled_template')])
if data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('micka_xml')])
@pytest.mark.usefixtures('liferay_mock', 'ensure_layman')
def test_micka_xml(workspace, publ_type, publication):
ensure_publication(workspace, publ_type, publication)
Expand All @@ -286,27 +286,21 @@ def test_micka_xml(workspace, publ_type, publication):
template_path, prop_values = csw.get_template_path_and_values(workspace, publication, http_method='post')
xml_file_object = micka_common_util.fill_xml_template_as_pretty_file_object(template_path, prop_values,
csw.METADATA_PROPERTIES)
expected_path = data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('micka_filled_template')
micka_xml_def = data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA]['micka_xml']
expected_path = micka_xml_def['filled_template']
with open(expected_path) as file:
expected_lines = file.readlines()
exp_diff_lines = micka_xml_def['diff_lines']
diff_lines = list(difflib.unified_diff([line.decode('utf-8') for line in xml_file_object.readlines()], expected_lines))
plus_lines = [line for line in diff_lines if line.startswith('+ ')]
assert len(plus_lines) == 3, ''.join(diff_lines)
assert len(plus_lines) == len(exp_diff_lines), ''.join(diff_lines)
minus_lines = [line for line in diff_lines if line.startswith('- ')]
assert len(minus_lines) == 3, ''.join(diff_lines)
plus_line = plus_lines[0]
assert plus_line == '+ <gco:CharacterString>m-81c0debe-b2ea-4829-9b16-581083b29907</gco:CharacterString>\n', ''.join(
diff_lines)
minus_line = minus_lines[0]
assert minus_line.startswith('- <gco:CharacterString>m') and minus_line.endswith(
'</gco:CharacterString>\n'), ''.join(diff_lines)
plus_line = plus_lines[1]
assert plus_line == '+ <gco:Date>2007-05-25</gco:Date>\n', ''.join(diff_lines)
minus_line = minus_lines[1]
assert minus_line.startswith('- <gco:Date>') and minus_line.endswith('</gco:Date>\n'), ''.join(diff_lines)
plus_line = plus_lines[2]
assert plus_line == '+ <gco:Date>2019-12-07</gco:Date>\n', ''.join(diff_lines)
minus_line = minus_lines[2]
assert minus_line.startswith('- <gco:Date>') and minus_line.endswith('</gco:Date>\n'), ''.join(
diff_lines)
assert len(diff_lines) == 29, ''.join(diff_lines)
assert len(minus_lines) == len(exp_diff_lines), ''.join(diff_lines)
for idx, diff_line in enumerate(exp_diff_lines):
plus_line = plus_lines[idx]
minus_line = minus_lines[idx]
assert plus_line == diff_line['plus_line'], f'diff_lines={"".join(diff_lines)}, idx={idx}, diff_line={diff_line}'
assert minus_line.startswith(diff_line['starts_with']), f'diff_lines={"".join(diff_lines)}, idx={idx}, diff_line={diff_line}'
assert minus_line.endswith(diff_line['ends_with']), f'diff_lines={"".join(diff_lines)}, idx={idx}, diff_line={diff_line}'

assert len(diff_lines) == micka_xml_def['diff_lines_len'], ''.join(diff_lines)

0 comments on commit 407d2a0

Please sign in to comment.