Skip to content

Commit

Permalink
Test layer POST without explicit name for zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
index-git committed Nov 3, 2021
1 parent f43caa1 commit 29a86e2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/layman/layer/filesystem/input_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,12 @@ def save_layer_files(workspace, layername, input_files, check_crs, *, output_dir
check_main_file(main_filepath, check_crs=check_crs)


def get_unsafe_layername(filenames):
main_filename = get_main_file_name(filenames)
def get_unsafe_layername(input_files):
main_filepath = input_files.raw_or_archived_main_file_path or input_files.raw_paths_to_archives[0]
unsafe_layername = ''
if main_filename is not None:
unsafe_layername = os.path.splitext(main_filename)[0]
if main_filepath is not None:
basename = os.path.basename(main_filepath)
unsafe_layername = os.path.splitext(basename)[0]
return unsafe_layername


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 @@ -59,7 +59,7 @@ def post(workspace):
# NAME
unsafe_layername = request.form.get('name', '')
if len(unsafe_layername) == 0:
unsafe_layername = input_file.get_unsafe_layername(input_files.raw_paths)
unsafe_layername = input_file.get_unsafe_layername(input_files)
layername = util.to_safe_layer_name(unsafe_layername)
util.check_layername(layername)
info = util.get_layer_info(workspace, layername)
Expand Down
95 changes: 95 additions & 0 deletions tests/dynamic_data/publications/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,101 @@
],
},
],
Publication(consts.COMMON_WORKSPACE, consts.LAYER_TYPE, 'zip_without_explicit_name'): [
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'name': None,
'file_paths': ['sample/layman.layer/small_layer_with_id.geojson'],
'compress': True,
'compress_settings': process_client.CompressTypeDef(archive_name='small_zip_layer'),
}),
consts.KEY_RESPONSE_ASSERTS: [
Action(processing.response.valid_post, {'name': 'small_layer_with_id'}),
],
},
consts.KEY_FINAL_ASSERTS: [
Action(publication.internal.source_has_its_key_or_it_is_empty, {'name': 'small_layer_with_id'}),
Action(publication.internal.source_internal_keys_are_subset_of_source_sibling_keys, {'name': 'small_layer_with_id'}),
Action(publication.internal_rest.same_title_in_source_and_rest_multi, {'name': 'small_layer_with_id'}),
Action(publication.internal_rest.same_values_in_internal_and_rest, {'name': 'small_layer_with_id'}),
Action(publication.rest.is_in_rest_multi, {'name': 'small_layer_with_id'}),
Action(publication.rest.correct_url_in_rest_multi, {'name': 'small_layer_with_id'}),
Action(publication.internal.same_value_of_key_in_all_sources, {'name': 'small_layer_with_id'}),
Action(publication.internal.mandatory_keys_in_all_sources, {'name': 'small_layer_with_id'}),
Action(publication.internal.metadata_key_sources_do_not_contain_other_keys, {'name': 'small_layer_with_id'}),
Action(publication.internal.thumbnail_key_sources_do_not_contain_other_keys, {'name': 'small_layer_with_id'}),
Action(publication.internal.mandatory_keys_in_primary_db_schema_of_actor, {'name': 'small_layer_with_id'}),
Action(publication.internal.other_keys_not_in_primary_db_schema_of_actor, {'name': 'small_layer_with_id'}),
Action(publication.internal.mandatory_keys_in_all_sources_of_actor, {'name': 'small_layer_with_id'}),
Action(publication.rest.is_complete_in_rest, {'name': 'small_layer_with_id'}),
Action(publication.rest.mandatory_keys_in_rest, {'name': 'small_layer_with_id'}),
Action(publication.geoserver.workspace_wms_1_3_0_capabilities_available, {'name': 'small_layer_with_id'}),
Action(publication.geoserver.workspace_wfs_2_0_0_capabilities_available_if_vector, {'name': 'small_layer_with_id'}),
Action(publication.internal.correct_values_in_detail, {
'name': 'small_layer_with_id',
'exp_publication_detail': {
'bounding_box': [1571204.369948366, 6268896.225570714, 1572590.854206196, 6269876.33561699],
},
'file_extension': 'zip/small_layer_with_id.geojson',
'gdal_prefix': '/vsizip/',
'publ_type_detail': ('vector', 'sld'),
}),
Action(publication.internal.thumbnail_equals, {
'name': 'small_layer_with_id',
'exp_thumbnail': 'sample/style/basic_sld.png',
}),
],
},
],
Publication(consts.COMMON_WORKSPACE, consts.LAYER_TYPE, 'zip_chunks_without_explicit_name'): [
{
consts.KEY_ACTION: {
consts.KEY_CALL: Action(process_client.publish_workspace_publication, {
'name': None,
'file_paths': ['sample/layman.layer/small_layer.geojson'],
'compress': True,
'compress_settings': process_client.CompressTypeDef(archive_name='small_zip_layer'),
'with_chunks': True,
}),
consts.KEY_RESPONSE_ASSERTS: [
Action(processing.response.valid_post, {'name': 'small_zip_layer'}),
],
},
consts.KEY_FINAL_ASSERTS: [
Action(publication.internal.source_has_its_key_or_it_is_empty, {'name': 'small_zip_layer'}),
Action(publication.internal.source_internal_keys_are_subset_of_source_sibling_keys, {'name': 'small_zip_layer'}),
Action(publication.internal_rest.same_title_in_source_and_rest_multi, {'name': 'small_zip_layer'}),
Action(publication.internal_rest.same_values_in_internal_and_rest, {'name': 'small_zip_layer'}),
Action(publication.rest.is_in_rest_multi, {'name': 'small_zip_layer'}),
Action(publication.rest.correct_url_in_rest_multi, {'name': 'small_zip_layer'}),
Action(publication.internal.same_value_of_key_in_all_sources, {'name': 'small_zip_layer'}),
Action(publication.internal.mandatory_keys_in_all_sources, {'name': 'small_zip_layer'}),
Action(publication.internal.metadata_key_sources_do_not_contain_other_keys, {'name': 'small_zip_layer'}),
Action(publication.internal.thumbnail_key_sources_do_not_contain_other_keys, {'name': 'small_zip_layer'}),
Action(publication.internal.mandatory_keys_in_primary_db_schema_of_actor, {'name': 'small_zip_layer'}),
Action(publication.internal.other_keys_not_in_primary_db_schema_of_actor, {'name': 'small_zip_layer'}),
Action(publication.internal.mandatory_keys_in_all_sources_of_actor, {'name': 'small_zip_layer'}),
Action(publication.rest.is_complete_in_rest, {'name': 'small_zip_layer'}),
Action(publication.rest.mandatory_keys_in_rest, {'name': 'small_zip_layer'}),
Action(publication.geoserver.workspace_wms_1_3_0_capabilities_available, {'name': 'small_zip_layer'}),
Action(publication.geoserver.workspace_wfs_2_0_0_capabilities_available_if_vector, {'name': 'small_zip_layer'}),
Action(publication.internal.correct_values_in_detail, {
'name': 'small_zip_layer',
'exp_publication_detail': {
'bounding_box': [1571204.369948366, 6268896.225570714, 1572590.854206196, 6269876.33561699],
},
'file_extension': 'zip/small_layer.geojson',
'gdal_prefix': '/vsizip/',
'publ_type_detail': ('vector', 'sld'),
}),
Action(publication.internal.thumbnail_equals, {
'name': 'small_zip_layer',
'exp_thumbnail': 'sample/style/basic_sld.png',
}),
],
},
],
**wrong_input.generate(consts.COMMON_WORKSPACE + '_generated_wrong_input'),
**file_input.generate(consts.COMMON_WORKSPACE + '_generated_file_input'),
}
Expand Down

0 comments on commit 29a86e2

Please sign in to comment.