Skip to content

Commit

Permalink
Prepare rest_endpoints_test.py for PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Sep 13, 2023
1 parent 9d2cbba commit a124405
Showing 1 changed file with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from layman import settings
from tests import EnumTestTypes
from tests import EnumTestTypes, Publication
from tests.dynamic_data import base_test, base_test_classes
from tests.dynamic_data.publications import common_publications
from tests import Publication
from test_tools import assert_util

pytest_generate_tests = base_test.pytest_generate_tests


class RestMethodLocal(base_test_classes.RestMethodBase):
POST = ('post_publication', 'post')
DELETE = ('delete_workspace_publication', 'delete')
MULTI_DELETE = ('delete_workspace_publications', 'multi_delete')


class PublicationTypes(base_test_classes.PublicationByDefinitionBase):
LAYER = (common_publications.LAYER_VECTOR_SLD, 'layer')
MAP = (common_publications.MAP_EMPTY, 'map')
Expand All @@ -23,7 +17,7 @@ class TestPublication(base_test.TestSingleRestPublication):
publication_type = None

rest_parametrization = [
RestMethodLocal,
base_test_classes.RestMethodAll,
PublicationTypes,
]

Expand All @@ -32,11 +26,44 @@ class TestPublication(base_test.TestSingleRestPublication):
publ_def.type,
None),
type=EnumTestTypes.MANDATORY,
specific_types={
(base_test_classes.RestMethodAll.PATCH, PublicationTypes.MAP): EnumTestTypes.IGNORE,
}
)]

@staticmethod
def test_publication(publication, rest_method):
def test_publication(self, publication, rest_method):
proxy_prefix = '/layman-proxy'
response = rest_method(publication, args={'headers': {'X-Forwarded-Prefix': proxy_prefix}})
publication_response = response[0] if isinstance(response, list) and len(response) == 1 else response
assert publication_response['url'] == f'http://{settings.LAYMAN_PROXY_SERVER_NAME}{proxy_prefix}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}'
if rest_method == self.patch_publication:
exp_resp = {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/{publication.type.split(".")[1]}s/{publication.name}',
'thumbnail': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/thumbnail'
},
'metadata': {
'comparison_url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/metadata-comparison',
},
'wms': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/geoserver/{publication.workspace}_wms/ows',
},
'sld': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{publication.workspace}/layers/{publication.name}/style',
},
'style': {
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/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}/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}'}

assert_util.assert_same_values_for_keys(
expected=exp_resp,
tested=publication_response,
)

0 comments on commit a124405

Please sign in to comment.