Skip to content

Commit

Permalink
Encapsulate definition of expected rest response
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git authored and jirik committed Sep 13, 2023
1 parent 5b97447 commit 6b64cf7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 57 deletions.
68 changes: 55 additions & 13 deletions tests/asserts/final/publication/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,46 @@

from celery import states
from layman import settings
from test_tools import process_client, util as test_util
from test_tools import process_client, util as test_util, assert_util

PROXY_PREFIX = '/layman-proxy'


def get_expected_urls_in_rest_response(workspace, publ_type, name, *, rest_method, proxy_prefix, geodata_type=None):
assert rest_method in {'post', 'patch', 'get', 'delete', 'multi_delete'}
publ_type_directory = f'{publ_type.split(".")[1]}s'
result = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}'
}
if rest_method in ['patch', 'get']:
result['thumbnail'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}/thumbnail'
}
result['metadata'] = {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}/metadata-comparison',
}
if publ_type == process_client.LAYER_TYPE:
result['wms'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{workspace}_wms/ows',
}
result['sld'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}/style',
}
result['style'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}/style',
}
if geodata_type == settings.GEODATA_TYPE_VECTOR:
result['wfs'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{workspace}/wfs'
}
else:
result['file'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/{publ_type_directory}/{name}/file',
}

return result


def is_complete_in_rest(rest_publication_detail):
assert 'layman_metadata' in rest_publication_detail, f'rest_publication_detail={rest_publication_detail}'
assert rest_publication_detail['layman_metadata']['publication_status'] == 'COMPLETE', f'rest_publication_detail={rest_publication_detail}'
Expand Down Expand Up @@ -101,15 +136,17 @@ def get_layer_with_x_forwarded_prefix(workspace, name, headers, ):
'X-Forwarded-Prefix': proxy_prefix,
}
rest_layer_info = process_client.get_workspace_layer(workspace, name, headers=headers)
assert rest_layer_info['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/layers/{name}'
assert rest_layer_info['thumbnail']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/layers/{name}/thumbnail'
assert rest_layer_info['metadata']['comparison_url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/layers/{name}/metadata-comparison'
assert rest_layer_info['wms']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{workspace}_wms/ows'
geodata_type = rest_layer_info['geodata_type']
if geodata_type == settings.GEODATA_TYPE_VECTOR:
assert rest_layer_info['wfs']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{workspace}/wfs'
assert rest_layer_info['sld']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/layers/{name}/style'
assert rest_layer_info['style']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/layers/{name}/style'

exp_resp = get_expected_urls_in_rest_response(workspace, process_client.LAYER_TYPE, name,
rest_method='get',
proxy_prefix=proxy_prefix,
geodata_type=geodata_type,
)
assert_util.assert_same_values_for_keys(
expected=exp_resp,
tested=rest_layer_info,
)


def get_map_with_x_forwarded_prefix(workspace, name, headers, ):
Expand All @@ -119,7 +156,12 @@ def get_map_with_x_forwarded_prefix(workspace, name, headers, ):
'X-Forwarded-Prefix': proxy_prefix,
}
rest_map_info = process_client.get_workspace_map(workspace, name, headers=headers)
assert rest_map_info['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/maps/{name}'
assert rest_map_info['file']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/maps/{name}/file'
assert rest_map_info['thumbnail']['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/maps/{name}/thumbnail'
assert rest_map_info['metadata']['comparison_url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{workspace}/maps/{name}/metadata-comparison'
exp_resp = get_expected_urls_in_rest_response(workspace, process_client.MAP_TYPE, name,
rest_method='get',
proxy_prefix=proxy_prefix,
geodata_type=None,
)
assert_util.assert_same_values_for_keys(
expected=exp_resp,
tested=rest_map_info,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from layman import settings
from tests import EnumTestTypes, Publication
from tests.asserts.final.publication import rest as assert_rest
from tests.dynamic_data import base_test, base_test_classes
from tests.dynamic_data.publications import common_publications
from test_tools import assert_util, process_client
from test_tools import assert_util

pytest_generate_tests = base_test.pytest_generate_tests

Expand Down Expand Up @@ -32,48 +32,12 @@ def test_publication(self, publication, rest_method):
proxy_prefix = '/layman-proxy'
response = rest_method.fn(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
publication_response = response[0] if isinstance(response, list) and len(response) == 1 else response
if rest_method == self.patch_publication: # pylint: disable=W0143
if publication.type == process_client.LAYER_TYPE:
exp_resp = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}',
'thumbnail': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail'
},
'metadata': {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison',
},
'wms': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}_wms/ows',
},
'sld': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
'style': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
}

geodata_type = response['geodata_type']
if geodata_type == settings.GEODATA_TYPE_VECTOR:
exp_resp['wfs'] = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/geoserver/{publication.workspace}/wfs'
}
else:
exp_resp = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}',
'thumbnail': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/thumbnail'
},
'file': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/file'
},
'metadata': {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}/metadata-comparison',
},
}

else:
exp_resp = {'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'}
geodata_type = publication_response.get('geodata_type')
exp_resp = assert_rest.get_expected_urls_in_rest_response(publication.workspace, publication.type, publication.name,
rest_method=rest_method.enum_item.publ_name_part,
proxy_prefix=proxy_prefix,
geodata_type=geodata_type,
)

assert_util.assert_same_values_for_keys(
expected=exp_resp,
Expand Down

0 comments on commit 6b64cf7

Please sign in to comment.