def test_custom_srs_list(ensure_layer): workspace = 'test_custom_srs_list_workspace' layer_sld1 = 'test_custom_srs_list_sld_layer1' layer_sld2 = 'test_custom_srs_list_sld_layer2' layer_qgis1 = 'test_custom_srs_list_qgis_layer1' layer_qgis2 = 'test_custom_srs_list_qgis_layer2' source_style_file_path = 'sample/style/small_layer.qml' output_crs_list = {f'EPSG:{srid}' for srid in OUTPUT_SRS_LIST} assert settings.LAYMAN_OUTPUT_SRS_LIST != output_crs_list process.ensure_layman_function(process.LAYMAN_DEFAULT_SETTINGS) ensure_layer(workspace, layer_sld1) ensure_layer(workspace, layer_qgis1, style_file=source_style_file_path) with app.app_context(): init_output_epsg_codes_set = { crs.replace(':', '::') for crs in settings.LAYMAN_OUTPUT_SRS_LIST } assert_gs_wms_output_srs_list(workspace, layer_sld1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer_sld1, init_output_epsg_codes_set) assert not qgis_wms.get_layer_info(workspace, layer_sld1) assert_gs_wms_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer_qgis1, init_output_epsg_codes_set) assert_qgis_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_qgis_wms_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) process.ensure_layman_function({ 'LAYMAN_OUTPUT_SRS_LIST': ','.join([str(code) for code in OUTPUT_SRS_LIST]) }) ensure_layer(workspace, layer_sld2) ensure_layer(workspace, layer_qgis2, style_file=source_style_file_path) output_epsg_codes_set = {crs.replace(':', '::') for crs in output_crs_list} with app.app_context(): for layer in [ layer_sld1, layer_sld2, ]: assert_gs_wms_output_srs_list(workspace, layer, output_crs_list) assert_wfs_output_srs_list(workspace, layer, output_epsg_codes_set) assert not qgis_wms.get_layer_info(workspace, layer) for layer in [ layer_qgis1, layer_qgis2, ]: assert_gs_wms_output_srs_list(workspace, layer, output_crs_list) assert_wfs_output_srs_list(workspace, layer, output_epsg_codes_set) assert_qgis_output_srs_list(workspace, layer, output_crs_list) assert_qgis_wms_output_srs_list(workspace, layer, output_crs_list)
def test_custom_srs_list(ensure_layer): workspace = 'test_custom_srs_list_workspace' layer_sld1 = 'test_custom_srs_list_sld_layer1' layer_sld2 = 'test_custom_srs_list_sld_layer2' layer_qgis1 = 'test_custom_srs_list_qgis_layer1' layer_qgis2 = 'test_custom_srs_list_qgis_layer2' source_style_file_path = 'sample/style/small_layer.qml' assert settings.LAYMAN_OUTPUT_SRS_LIST != OUTPUT_SRS_LIST process.ensure_layman_function(process.LAYMAN_DEFAULT_SETTINGS) ensure_layer(workspace, layer_sld1) ensure_layer(workspace, layer_qgis1, style_file=source_style_file_path) with app.app_context(): assert_gs_wms_output_srs_list(workspace, layer_sld1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer_sld1, settings.LAYMAN_OUTPUT_SRS_LIST) assert not qgis_wms.get_layer_info(workspace, layer_sld1) assert_gs_wms_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_qgis_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) assert_qgis_wms_output_srs_list(workspace, layer_qgis1, settings.LAYMAN_OUTPUT_SRS_LIST) process.ensure_layman_function({ 'LAYMAN_OUTPUT_SRS_LIST': ','.join([str(code) for code in OUTPUT_SRS_LIST]) }) ensure_layer(workspace, layer_sld2) ensure_layer(workspace, layer_qgis2, style_file=source_style_file_path) with app.app_context(): for layer in [ layer_sld1, layer_sld2, ]: assert_gs_wms_output_srs_list(workspace, layer, OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer, OUTPUT_SRS_LIST) assert not qgis_wms.get_layer_info(workspace, layer) for layer in [ layer_qgis1, layer_qgis2, ]: assert_gs_wms_output_srs_list(workspace, layer, OUTPUT_SRS_LIST) assert_wfs_output_srs_list(workspace, layer, OUTPUT_SRS_LIST) assert_qgis_output_srs_list(workspace, layer, OUTPUT_SRS_LIST) assert_qgis_wms_output_srs_list(workspace, layer, OUTPUT_SRS_LIST)
def test_qml_files(workspace, publ_type, publication): ensure_publication(workspace, publ_type, publication) workspace_directory = f'{settings.LAYMAN_QGIS_DATA_DIR}/workspaces/{workspace}' layer_directory = f'{workspace_directory}/layers/{publication}' assert os.path.exists(workspace_directory) assert os.path.exists(layer_directory) with app.app_context(): url = url_for('rest_workspace_layer_style.get', workspace=workspace, layername=publication, internal=False) assert wms.get_layer_info(workspace, publication) == { 'name': publication, 'style': { 'type': 'qml', 'url': url }, '_wms': { 'qgis_capabilities_url': f'{settings.LAYMAN_QGIS_URL}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1&' f'map=/qgis/data/test/workspaces/{workspace}/layers/{publication}/{publication}.qgis' } } assert workspace in qgis.get_workspaces()
def test_qgis_rest(): workspace = 'test_qgis_rest_workspace' layer = 'test_qgis_rest_workspace_layer' source_style_file_path = 'sample/style/small_layer.qml' workspace_directory = f'{settings.LAYMAN_QGIS_DATA_DIR}/workspaces/{workspace}' layer_directory = f'{workspace_directory}/layers/{layer}' assert not os.path.exists(workspace_directory) assert not os.path.exists(layer_directory) process_client.publish_workspace_layer(workspace, layer, style_file=source_style_file_path) assert os.path.exists(workspace_directory) assert os.path.exists(layer_directory) with app.app_context(): url = url_for('rest_workspace_layer_style.get', workspace=workspace, layername=layer, internal=False) assert wms.get_layer_info(workspace, layer) == { 'name': layer, 'style': { 'type': 'qml', 'url': url }, '_wms': { 'qgis_capabilities_url': f'{settings.LAYMAN_QGIS_URL}?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1&map=/qgis/data/test/workspaces/{workspace}/layers/{layer}/{layer}.qgis' } } assert workspace in qgis.get_workspaces() process_client.delete_workspace_layer(workspace, layer) assert os.path.exists(workspace_directory) assert not os.path.exists(layer_directory) with app.app_context(): assert wms.get_layer_info(workspace, layer) == {} assert workspace in qgis.get_workspaces()
def wfs_post(workspace, attr_names_list, data_xml): with app.app_context(): wfs_url = f"http://{settings.LAYMAN_SERVER_NAME}/geoserver/{workspace}/wfs" old_db_attributes = {} old_wfs_properties = {} for layer, attr_names in attr_names_list: # test that all attr_names are not yet presented in DB table old_db_attributes[layer] = db.get_all_column_names( workspace, layer) for attr_name in attr_names: assert attr_name not in old_db_attributes[ layer], f"old_db_attributes={old_db_attributes[layer]}, attr_name={attr_name}" layer_schema = get_wfs_schema(wfs_url, typename=f"{workspace}:{layer}", version=geoserver_wfs.VERSION, headers=authn_headers) old_wfs_properties[layer] = sorted( layer_schema['properties'].keys()) if style_type == 'qml': assert qgis_wms.get_layer_info(workspace, layer) old_qgis_attributes = qgis_util.get_layer_attribute_names( workspace, layer) assert all( attr_name not in old_qgis_attributes for attr_name in attr_names), (attr_names, old_qgis_attributes) process_client.post_wfst(data_xml, headers=authn_headers, workspace=username) new_db_attributes = {} new_wfs_properties = {} for layer, attr_names in attr_names_list: # test that exactly all attr_names were created in DB table new_db_attributes[layer] = db.get_all_column_names( workspace, layer) for attr_name in attr_names: assert attr_name in new_db_attributes[ layer], f"new_db_attributes={new_db_attributes[layer]}, attr_name={attr_name}" assert set(attr_names).union(set( old_db_attributes[layer])) == set(new_db_attributes[layer]) # test that exactly all attr_names were distinguished also in WFS feature type layer_schema = get_wfs_schema(wfs_url, typename=f"{workspace}:{layer}", version=geoserver_wfs.VERSION, headers=authn_headers) new_wfs_properties[layer] = sorted( layer_schema['properties'].keys()) for attr_name in attr_names: assert attr_name in new_wfs_properties[ layer], f"new_wfs_properties={new_wfs_properties[layer]}, attr_name={attr_name}" assert set(attr_names).union(set(old_wfs_properties[layer])) == set(new_wfs_properties[layer]),\ set(new_wfs_properties[layer]).difference(set(attr_names).union(set(old_wfs_properties[layer]))) if style_type == 'qml': assert qgis_wms.get_layer_info(workspace, layer) new_qgis_attributes = qgis_util.get_layer_attribute_names( workspace, layer) assert all( attr_name in new_qgis_attributes for attr_name in attr_names), (attr_names, new_qgis_attributes) else: assert not qgis_wms.get_layer_info(workspace, layer)