Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More post zip variants #494

Merged
merged 6 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#### Schema migrations
#### Data migrations
### Changes
- [#169](https://github.com/LayerManager/layman/issues/169) [POST Workspace Layers](doc/rest.md#post-workspace-layers) accepts also compressed data files in ZIP format (`*.zip`) in `file` parameter. Currently, only zipped GeoJSON sent synchronously is tested.
- [#169](https://github.com/LayerManager/layman/issues/169) [POST Workspace Layers](doc/rest.md#post-workspace-layers) accepts also compressed data files in ZIP format (`*.zip`) in `file` parameter. Currently, only zipped GeoJSON and ShapeFile sent synchronously is tested.
- [#169](https://github.com/LayerManager/layman/issues/169) [GET Workspace Layer](doc/rest.md#get-workspace-layer) returns path to main file inside archive if zipped file was sent (key `file.path`).
- [#465](https://github.com/LayerManager/layman/issues/465) Fix situation, when Layman does not start if *.qgis file of the first layer with QML style does not exist. It was already fixed in v1.14.1.
- [#464](https://github.com/LayerManager/layman/issues/464) Fix publishing layers with unusual attribute names (e.g. `x,` or `Číslo`) and QML styles. It was already fixed in v1.14.1.
Expand Down
2 changes: 1 addition & 1 deletion doc/rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Body parameters:
- JPEG 2000 (.jp2, with or without .j2w)
- PNG (.png, with .png.aux.xml or .pgw)
- JPEG (.jpg, with .jpg.aux.xml or .jgw)
- GeoJSON in single ZIP file (.zip)
- GeoJSON or ShapeFile in single ZIP file (.zip)
- file names, i.e. array of strings (not supported for ZIP file)
- if file names are provided, files must be uploaded subsequently using [POST Workspace Layer Chunk](#post-workspace-layer-chunk)
- in case of raster data input, following input combinations of bands and color interpretations are supported:
Expand Down
Binary file not shown.
14 changes: 14 additions & 0 deletions test_tools/assert_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,17 @@ def assert_all_sources_bbox(workspace, layer, expected_bbox):
assert md_props[prop_key]['equal_or_null'] is True, md_props[prop_key]
csw_bbox_4326 = tuple(md_props[prop_key]['values'][csw_src_key])
assert_same_bboxes(expected_bbox_4326, csw_bbox_4326, 0.001)


def assert_same_values_for_keys(*, expected, tested, missing_key_is_ok=False, path=''):
if isinstance(tested, dict) and isinstance(expected, dict):
for key in expected:
key_path = path + f'.{key}'
if not missing_key_is_ok or key in tested:
assert key in tested, f'key_path={key_path}, expected={expected}, tested={tested}'
assert_same_values_for_keys(expected=expected[key],
tested=tested[key],
missing_key_is_ok=missing_key_is_ok,
path=key_path)
else:
assert expected == tested, f'path={path}, expected={expected}, tested={tested}'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 13 additions & 11 deletions tests/asserts/final/publication/internal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from layman import app, util as layman_util, settings
from test_tools import process_client, util as test_util
from ... import util as assert_util
from test_tools import process_client, util as test_util, assert_util
from ... import util


def source_has_its_key_or_it_is_empty(workspace, publ_type, name):
Expand Down Expand Up @@ -42,9 +42,11 @@ def same_value_of_key_in_all_sources(workspace, publ_type, name):
for source, source_info in partial_infos.items():
for key, value in source_info.items():
if key in info:
assert assert_util.same_value_for_keys(expected=info[key], tested=value,
missing_key_is_ok=True), f'{source}: key={key}, info={info[key]}, source={value}, ' \
f'all={[(lsource, lsource_info[key]) for lsource, lsource_info in partial_infos.items() if key in lsource_info]}'
assert_util.assert_same_values_for_keys(expected=info[key],
tested=value,
missing_key_is_ok=True,
path=f'[{source}]',
)


def mandatory_keys_in_all_sources(workspace, publ_type, name):
Expand Down Expand Up @@ -91,11 +93,11 @@ def thumbnail_equals(workspace, publ_type, name, exp_thumbnail, ):
pub_info = layman_util.get_publication_info(workspace, publ_type, name, {'keys': ['thumbnail']})

diffs = test_util.compare_images(exp_thumbnail, pub_info['_thumbnail']['path'])
assert diffs < 1000
assert diffs < 500


def correct_values_in_detail(workspace, publ_type, name, exp_publication_detail):
publ_type_dir = assert_util.get_directory_name_from_publ_type(publ_type)
publ_type_dir = util.get_directory_name_from_publ_type(publ_type)
expected_detail = {
'name': name,
'title': name,
Expand All @@ -118,12 +120,12 @@ def correct_values_in_detail(workspace, publ_type, name, exp_publication_detail)
'_wms': {'url': f'{settings.LAYMAN_GS_URL}{workspace}{settings.LAYMAN_GS_WMS_WORKSPACE_POSTFIX}/ows',
'workspace': f'{workspace}{settings.LAYMAN_GS_WMS_WORKSPACE_POSTFIX}'},
})
expected_detail = assert_util.recursive_dict_update(expected_detail, exp_publication_detail)
expected_detail = util.recursive_dict_update(expected_detail, exp_publication_detail)
with app.app_context():
pub_info = layman_util.get_publication_info(workspace, publ_type, name)
assert assert_util.same_value_for_keys(expected=expected_detail,
tested=pub_info), f'expected_detail={expected_detail}\npub_info={pub_info}\n' \
f'exp_publication_detail={exp_publication_detail}'
assert_util.assert_same_values_for_keys(expected=expected_detail,
tested=pub_info,
)


def does_not_exist(workspace, publ_type, name, ):
Expand Down
12 changes: 7 additions & 5 deletions tests/asserts/processing/response.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from layman import settings
from .. import util as assert_util
from test_tools import assert_util
from .. import util


def valid_post(workspace, publ_type, name, response, expected=None):
expected = expected or dict()
publ_type_dir = assert_util.get_directory_name_from_publ_type(publ_type)
publ_type_dir = util.get_directory_name_from_publ_type(publ_type)
exp_response = {
'name': name,
'url': f'http://{settings.LAYMAN_PROXY_SERVER_NAME}/rest/workspaces/{workspace}/{publ_type_dir}/{name}'
}
exp_response = assert_util.recursive_dict_update(exp_response, expected)
assert assert_util.same_value_for_keys(expected=exp_response,
tested=response), f'exp_response={exp_response}\nresponse={response}\nexpected={expected}'
exp_response = util.recursive_dict_update(exp_response, expected)
assert_util.assert_same_values_for_keys(expected=exp_response,
tested=response,
)
11 changes: 0 additions & 11 deletions tests/asserts/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,6 @@ def get_publication_actor(publication):
return actor


def same_value_for_keys(*, expected, tested, missing_key_is_ok=False):
if isinstance(tested, dict) and isinstance(expected, dict):
return all(
key in tested and same_value_for_keys(expected=expected[key],
tested=tested.get(key),
missing_key_is_ok=missing_key_is_ok)
for key in expected if
not missing_key_is_ok or key in tested)
return expected == tested or (missing_key_is_ok and not tested)


def get_directory_name_from_publ_type(publ_type):
return publ_type.split('.')[1] + 's'

Expand Down
32 changes: 31 additions & 1 deletion tests/dynamic_data/publications.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,35 @@
}),
],
},
]
],
Publication(consts.COMMON_WORKSPACE, consts.LAYER_TYPE, 'zipped_shp_sld'): [
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'file_paths': ['sample/layman.layer/ne_110m_admin_0_boundary lines land +ěščřžýáí.zip'],
}),
consts.KEY_RESPONSE_ASSERTS: [
Action(processing.response.valid_post, dict()),
],
},
consts.KEY_FINAL_ASSERTS: [
*publication.IS_LAYER_COMPLETE_AND_CONSISTENT,
Action(publication.internal.correct_values_in_detail, {
'exp_publication_detail': {
**predefined_infos.BASIC_SLD_LAYER,
'_file': {
'path': '/layman_data_test/workspaces/dynamic_test_workspace/layers/zipped_shp_sld/input_file/zipped_shp_sld.zip/ne_110m_admin_0_boundary lines land +ěščřžýáí/ne_110m_admin 0 boundary_lines_land ížě.shp'
},
'file': {
'path': 'layers/zipped_shp_sld/input_file/zipped_shp_sld.zip/ne_110m_admin_0_boundary lines land +ěščřžýáí/ne_110m_admin 0 boundary_lines_land ížě.shp'
},
'bounding_box': [-15695801.072582014, -7341864.739114417, 15699816.562538767, 11122367.192100529],
},
}),
Action(publication.internal.thumbnail_equals, {
'exp_thumbnail': 'test_tools/data/thumbnail/ne_110m_admin_0_boundary_lines_land.png',
}),
],
},
],
}