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

169 check more main files #501

Merged
merged 3 commits into from
Oct 27, 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
3 changes: 2 additions & 1 deletion src/layman/layer/filesystem/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ def check_filenames(workspace, layername, filenames, check_crs, ignore_existing_
))
if len(missing_exts) > 0:
detail = {
'missing_extensions': missing_exts
'missing_extensions': missing_exts,
'path': main_filename,
}
if '.prj' in missing_exts:
detail['suggestion'] = 'Missing .prj file can be fixed also ' \
Expand Down
7 changes: 6 additions & 1 deletion src/layman/layer/filesystem/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
delete_layer_subdir = partial(publ_util.delete_publication_subdir, LAYER_TYPE)


def get_filenames_from_zip_storage(zip_file):
def get_filenames_from_zip_storage(zip_file, *, with_zip_in_path=False):
with ZipFile(zip_file) as opened_zip_file:
filenames = opened_zip_file.namelist()
if isinstance(zip_file, FileStorage):
zip_file.seek(0)
zip_name = zip_file.filename
else:
zip_name = os.path.basename(zip_file)
if with_zip_in_path:
filenames = [os.path.join(zip_name, fn) for fn in filenames]
return filenames


Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/rest_workspace_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def patch(workspace, layername):
if use_chunk_upload:
filenames = files
elif zipped_file:
filenames = fs_util.get_filenames_from_zip_storage(zipped_file)
filenames = fs_util.get_filenames_from_zip_storage(zipped_file, with_zip_in_path=True)
else:
filenames = [f.filename for f in files]
input_file.check_filenames(workspace, layername, filenames,
Expand Down
2 changes: 1 addition & 1 deletion src/layman/layer/rest_workspace_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def post(workspace):
elif use_chunk_upload:
filenames = files
elif zipped_file:
filenames = fs_util.get_filenames_from_zip_storage(zipped_file)
filenames = fs_util.get_filenames_from_zip_storage(zipped_file, with_zip_in_path=True)
else:
filenames = [f.filename for f in files]
file_type = input_file.get_file_type(input_file.get_main_file_name(filenames))
Expand Down
Binary file not shown.
56 changes: 56 additions & 0 deletions tests/dynamic_data/publications.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from layman import LaymanError
import tests.asserts.final.publication as publication
import tests.asserts.processing as processing
from test_tools import process_client
Expand Down Expand Up @@ -52,6 +53,61 @@
},
],
Publication(consts.COMMON_WORKSPACE, consts.LAYER_TYPE, 'zipped_sld'): [
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'file_paths': ['test_tools/data/layers/layer_with_two_main_files.zip'],
}),
consts.KEY_CALL_EXCEPTION: {
consts.KEY_EXCEPTION: LaymanError,
consts.KEY_EXCEPTION_ASSERTS: [
Action(processing.exception.response_exception, {'expected': {'http_code': 400,
'code': 2,
'message': 'Wrong parameter value',
'detail': {
'expected': 'At most one file with any of extensions: .geojson, .shp, .tiff, .tif, .jp2, .png, .jpg',
'files': [
'layer_with_two_main_files.zip/layer_with_two_main_files/geojson/small_layer.geojson',
'layer_with_two_main_files.zip/layer_with_two_main_files/raster/sample_tif_rgb.tif'],
'parameter': 'file'},
}, }, ),
],
},
},
consts.KEY_FINAL_ASSERTS: [
Action(publication.internal.does_not_exist, dict())
],
},
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'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.README.html',
'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shp',
'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.shx',
'tmp/naturalearth/110m/cultural/ne_110m_admin_0_boundary_lines_land.VERSION.txt',
],
'compress': True,
}),
consts.KEY_CALL_EXCEPTION: {
consts.KEY_EXCEPTION: LaymanError,
consts.KEY_EXCEPTION_ASSERTS: [
Action(processing.exception.response_exception, {'expected': {'http_code': 400,
'code': 18,
'message': 'Missing one or more ShapeFile files.',
'detail': {'missing_extensions': ['.dbf', '.prj'],
'suggestion': 'Missing .prj file can be fixed also by setting "crs" parameter.',
'path': 'temporary_zip_file.zip/ne_110m_admin_0_boundary_lines_land.shp',
},
}, }, ),
],
},
},
consts.KEY_FINAL_ASSERTS: [
Action(publication.internal.does_not_exist, dict())
],
},
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
Expand Down