def test_fill_project_template(workspace, publ_type, publication): ensure_publication(workspace, publ_type, publication) qgs_path = f'{settings.LAYMAN_QGIS_DATA_DIR}/{publication}.qgs' wms_url = f'{settings.LAYMAN_QGIS_URL}?MAP={qgs_path}' wms_version = '1.3.0' layer_info = process_client.get_workspace_publication(publ_type, workspace, publication) layer_uuid = layer_info['uuid'] with pytest.raises(requests.exceptions.HTTPError) as excinfo: WebMapService(wms_url, version=wms_version) assert excinfo.value.response.status_code == 500 with app.app_context(): layer_bbox = layer_db.get_bbox(workspace, publication) layer_crs = layer_db.get_crs(workspace, publication) layer_bbox = layer_bbox if not bbox_util.is_empty(layer_bbox) else crs_def.CRSDefinitions[layer_crs].default_bbox with app.app_context(): qml_path = qgis_util.get_original_style_path(workspace, publication) parser = ET.XMLParser(remove_blank_text=True) qml_xml = ET.parse(qml_path, parser=parser) exp_min_scale = data.PUBLICATIONS[(workspace, publ_type, publication)][data.TEST_DATA].get('min_scale') if exp_min_scale is not None: assert qml_xml.getroot().attrib['minScale'] == exp_min_scale with app.app_context(): db_types = layer_db.get_geometry_types(workspace, publication) db_cols = [ col for col in layer_db.get_all_column_infos(workspace, publication) if col.name not in ['wkb_geometry', 'ogc_fid'] ] qml_geometry = qgis_util.get_qml_geometry_from_qml(qml_xml) source_type = qgis_util.get_source_type(db_types, qml_geometry) with app.app_context(): layer_qml_str = qgis_util.fill_layer_template(workspace, publication, layer_uuid, layer_bbox, layer_crs, qml_xml, source_type, db_cols) layer_qml = ET.fromstring(layer_qml_str.encode('utf-8'), parser=parser) if exp_min_scale is not None: assert layer_qml.attrib['minScale'] == exp_min_scale with app.app_context(): qgs_str = qgis_util.fill_project_template(workspace, publication, layer_uuid, layer_qml_str, layer_crs, settings.LAYMAN_OUTPUT_SRS_LIST, layer_bbox, source_type) with open(qgs_path, "w") as qgs_file: print(qgs_str, file=qgs_file) wmsi = WebMapService(wms_url, version=wms_version) assert publication in wmsi.contents wms_layer = wmsi.contents[publication] exp_output_srs = set(settings.LAYMAN_OUTPUT_SRS_LIST) assert exp_output_srs.issubset(set(wms_layer.crsOptions)) wms_layer_bbox = next((tuple(bbox_crs[:4]) for bbox_crs in wms_layer.crs_list if bbox_crs[4] == layer_crs)) assert_util.assert_same_bboxes(wms_layer_bbox, layer_bbox, 0.1) os.remove(qgs_path) with pytest.raises(requests.exceptions.HTTPError) as excinfo: WebMapService(wms_url, version=wms_version) assert excinfo.value.response.status_code == 500
def test_single_point_table_bbox(single_point_table): username, layername = single_point_table with layman.app_context(): bbox = db.get_bbox(username, layername) assert bbox[0] == bbox[2] and bbox[1] == bbox[3], bbox
def test_empty_table_bbox(empty_table): username, layername = empty_table with layman.app_context(): bbox = db.get_bbox(username, layername) assert bbox_util.is_empty(bbox), bbox