def test_grid_empty_dimension(self, test_app, layer_wms_test_data): from c2cgeoportal_commons.models.main import Dimension layer = layer_wms_test_data['layers'][0] layer.dimensions.append(Dimension(name='Empty', value=None)) json = self.check_search(test_app, layer.name, total=1) row = json['rows'][0] assert 'Empty: NULL' in row['dimensions']
def test_grid_empty_dimension(self, test_app, layer_wms_test_data): from c2cgeoportal_commons.models.main import Dimension layer = layer_wms_test_data["layers"][0] layer.dimensions.append(Dimension(name="Empty", value=None)) json = self.check_search(test_app, layer.name, total=1) row = json["rows"][0] assert "Empty: NULL" in row["dimensions"]
def layer_v1tov2(session, layer): from c2cgeoportal_commons.models.main import OGCServer, LayerWMS, LayerWMTS, \ LayergroupTreeitem, Dimension if layer.layer_type in ["internal WMS", "external WMS"]: # use the first one new_layer = LayerWMS() is_single_tile = layer.is_single_tile if is_single_tile is None: is_single_tile = False image_type = "image/png" if layer.layer_type == "internal WMS": url = "config://internal/mapserv" else: if layer.image_type is not None: image_type = layer.image_type url = layer.url ogc_server = session.query(OGCServer).filter( OGCServer.url == url, OGCServer.image_type == image_type, OGCServer.is_single_tile == is_single_tile).one() new_layer.ogc_server = ogc_server new_layer.layer = layer.layer new_layer.style = layer.style new_layer.time_mode = layer.time_mode new_layer.time_widget = layer.time_widget elif layer.layer_type == "WMTS": new_layer = LayerWMTS() new_layer.url = layer.url new_layer.layer = layer.layer new_layer.style = layer.style new_layer.matrix_set = layer.matrix_set new_layer.image_type = layer.image_type or "image/png" if layer.dimensions is not None: dimensions = loads(layer.dimensions) for name, value in list(dimensions.items()): session.add(Dimension(name, value, new_layer)) new_layer.name = layer.name new_layer.public = layer.public new_layer.geo_table = layer.geo_table new_layer.interfaces = layer.interfaces new_layer.restrictionareas = layer.restrictionareas for link in layer.parents_relation: new_link = LayergroupTreeitem() new_link.ordering = link.ordering new_link.description = link.description new_link.treegroup = link.treegroup new_link.treeitem = new_layer layer_add_metadata(layer, new_layer, session) session.add(new_layer)
def factory_build_layers(layer_builder, dbsession, add_dimension=True): from c2cgeoportal_commons.models.main import \ RestrictionArea, LayergroupTreeitem, \ Interface, Dimension, Metadata, LayerGroup restrictionareas = [RestrictionArea(name='restrictionarea_{}'.format(i)) for i in range(0, 5)] interfaces = [Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']] dimensions_protos = [('Date', '2017'), ('Date', '2018'), ('Date', '1988'), ('CLC', 'all'), ] metadatas_protos = [('copyable', 'true'), ('disclaimer', '© le momo'), ('snappingConfig', '{"tolerance": 50}')] groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)] layers = [] for i in range(0, 25): layer = layer_builder(i) if add_dimension: layer.dimensions = [Dimension(name=dimensions_protos[id][0], value=dimensions_protos[id][1], layer=layer) for id in [i % 3, (i + 2) % 4, (i + 3) % 4]] layer.metadatas = [Metadata(name=metadatas_protos[id][0], value=metadatas_protos[id][1]) for id in [i % 3, (i + 2) % 3]] for metadata in layer.metadatas: metadata.item = layer if i % 10 != 1: layer.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]] layer.restrictionareas = [restrictionareas[i % 5], restrictionareas[(i + 2) % 5]] dbsession.add(LayergroupTreeitem(group=groups[i % 5], item=layer, ordering=len(groups[i % 5].children_relation))) dbsession.add(LayergroupTreeitem(group=groups[(i + 3) % 5], item=layer, ordering=len(groups[(i + 3) % 5].children_relation))) dbsession.add(layer) layers.append(layer) return { 'restrictionareas': restrictionareas, 'layers': layers, 'interfaces': interfaces }
def setup_method(self, _): # Always see the diff # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff self.maxDiff = None from c2cgeoportal_commons.models import DBSession from c2cgeoportal_commons.models.main import ( Dimension, Interface, LayerGroup, LayerWMS, LayerWMTS, Theme, ) ogc_server = create_default_ogcserver() main = Interface(name="main") layer_wms_1 = LayerWMS(name="__test_layer_wms_1", public=True) layer_wms_1.layer = "testpoint_unprotected" layer_wms_1.interfaces = [main] layer_wms_1.ogc_server = ogc_server Dimension("A", "a", layer_wms_1) layer_wms_2 = LayerWMS(name="__test_layer_wms_2", public=True) layer_wms_2.layer = "testpoint_unprotected" layer_wms_2.interfaces = [main] layer_wms_2.ogc_server = ogc_server Dimension("A", "b", layer_wms_2) layer_wms_3 = LayerWMS(name="__test_layer_wms_3", public=True) layer_wms_3.layer = "testpoint_unprotected" layer_wms_3.interfaces = [main] layer_wms_3.ogc_server = ogc_server Dimension("A", None, layer_wms_3) layer_wms_4 = LayerWMS(name="__test_layer_wms_4", public=True) layer_wms_4.layer = "testpoint_unprotected" layer_wms_4.interfaces = [main] layer_wms_4.ogc_server = ogc_server Dimension("A", "a", layer_wms_4) layer_wms_5 = LayerWMS(name="__test_layer_wms_5", public=True) layer_wms_5.layer = "testpoint_unprotected" layer_wms_5.interfaces = [main] layer_wms_5.ogc_server = ogc_server Dimension("B", "b", layer_wms_5) layer_wms_6 = LayerWMS(name="__test_layer_wms_6", public=True) layer_wms_6.layer = "testpoint_unprotected" layer_wms_6.interfaces = [main] layer_wms_6.ogc_server = ogc_server Dimension("FILTER", "countries:\"name\" IN ( 'Germany' , 'Italy' )", layer_wms_6) layer_wms_7 = LayerWMS(name="__test_layer_wms_7", public=True) layer_wms_7.layer = "testpoint_unprotected" layer_wms_7.interfaces = [main] layer_wms_7.ogc_server = ogc_server Dimension("FLOOR", None, layer_wms_7, "floor") layer_wmts = LayerWMTS(name="__test_layer_wmts", public=True) layer_wmts.url = "http://tilecloudchain/1.0.0/WMTSCapabilities.xml" layer_wmts.layer = "map" layer_wmts.interfaces = [main] Dimension("B", "b", layer_wmts) layer_wmts_2 = LayerWMTS(name="__test_layer_wmts_2", public=True) layer_wmts_2.url = "http://tilecloudchain/1.0.0/WMTSCapabilities.xml" layer_wmts_2.layer = "map" layer_wmts_2.interfaces = [main] Dimension("FILTER", "countries:\"name\" IN ( 'Germany' , 'Italy' )", layer_wmts_2) layer_group_1 = LayerGroup(name="__test_layer_group_1") layer_group_1.children = [layer_wms_1, layer_wmts, layer_wmts_2] layer_group_2 = LayerGroup(name="__test_layer_group_2") layer_group_2.children = [layer_wms_1, layer_wms_2] layer_group_3 = LayerGroup(name="__test_layer_group_3") layer_group_3.children = [layer_wms_1, layer_wms_3] layer_group_4 = LayerGroup(name="__test_layer_group_4") layer_group_4.children = [layer_wms_1, layer_wms_4] layer_group_5 = LayerGroup(name="__test_layer_group_5") layer_group_5.children = [layer_wms_1, layer_wms_5, layer_wms_6] layer_group_6 = LayerGroup(name="__test_layer_group_6") layer_group_6.children = [layer_wms_3] layer_group_7 = LayerGroup(name="__test_layer_group_7") layer_group_7.children = [layer_wms_7] theme = Theme(name="__test_theme") theme.interfaces = [main] theme.children = [ layer_group_1, layer_group_2, layer_group_3, layer_group_4, layer_group_5, layer_group_6, layer_group_7, ] DBSession.add(theme) transaction.commit()
def setup_method(self, _): # Always see the diff # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff self.maxDiff = None from c2cgeoportal_commons.models import DBSession from c2cgeoportal_commons.models.main import \ Theme, LayerGroup, Functionality, Interface, OGCServer, LayerWMS, LayerWMTS, \ Metadata, Dimension, OGCSERVER_AUTH_NOAUTH main = Interface(name="desktop") mobile = Interface(name="mobile") min_levels = Interface(name="min_levels") ogc_server_internal, _ = create_default_ogcserver() ogc_server_external = OGCServer(name="__test_ogc_server_chtopo", url="http://wms.geo.admin.ch/", image_type="image/jpeg", auth=OGCSERVER_AUTH_NOAUTH) ogc_server_external.wfs_support = False layer_internal_wms = LayerWMS(name="__test_layer_internal_wms", public=True) layer_internal_wms.layer = "__test_layer_internal_wms" layer_internal_wms.interfaces = [main, min_levels] layer_internal_wms.metadatas = [Metadata("test", "internal_wms")] layer_internal_wms.ogc_server = ogc_server_internal layer_external_wms = LayerWMS(name="__test_layer_external_wms", layer="ch.swisstopo.dreiecksvermaschung", public=True) layer_external_wms.interfaces = [main] layer_external_wms.metadatas = [Metadata("test", "external_wms")] layer_external_wms.ogc_server = ogc_server_external layer_wmts = LayerWMTS(name="__test_layer_wmts", public=True) layer_wmts.url = "http://example.com/1.0.0/WMTSCapabilities.xml" layer_wmts.layer = "map" layer_wmts.interfaces = [main, mobile] layer_wmts.metadatas = [Metadata("test", "wmts")] layer_wmts.dimensions = [Dimension("year", "2015")] layer_group_1 = LayerGroup(name="__test_layer_group_1") layer_group_1.children = [ layer_internal_wms, layer_external_wms, layer_wmts ] layer_group_1.metadatas = [Metadata("test", "group_1")] layer_group_2 = LayerGroup(name="__test_layer_group_2") layer_group_2.children = [ layer_wmts, layer_internal_wms, layer_external_wms ] layer_group_3 = LayerGroup(name="__test_layer_group_3") layer_group_3.children = [ layer_wmts, layer_internal_wms, layer_external_wms ] layer_group_4 = LayerGroup(name="__test_layer_group_4") layer_group_4.children = [layer_group_2] theme = Theme(name="__test_theme") theme.interfaces = [main, mobile] theme.metadatas = [Metadata("test", "theme")] theme.children = [layer_group_1, layer_group_2] theme_layer = Theme(name="__test_theme_layer") theme_layer.interfaces = [min_levels] theme_layer.children = [layer_internal_wms] functionality1 = Functionality(name="test_name", value="test_value_1") functionality2 = Functionality(name="test_name", value="test_value_2") theme.functionalities = [functionality1, functionality2] DBSession.add_all([theme, theme_layer]) transaction.commit()
def factory_build_layers(layer_builder, dbsession, add_dimension=True): from c2cgeoportal_commons.models.main import ( Dimension, Interface, LayerGroup, LayergroupTreeitem, Metadata, RestrictionArea, ) restrictionareas = [ RestrictionArea(name=f"restrictionarea_{i}") for i in range(0, 5) ] interfaces = [ Interface(name) for name in ["desktop", "mobile", "edit", "routing"] ] dimensions_protos = [("Date", "2017"), ("Date", "2018"), ("Date", "1988"), ("CLC", "all")] metadatas_protos = [ ("copyable", "true"), ("disclaimer", "© le momo"), ("snappingConfig", '{"tolerance": 50}'), ] groups = [LayerGroup(name=f"layer_group_{i}") for i in range(0, 5)] layers = [] for i in range(0, 25): layer = layer_builder(i) if add_dimension: layer.dimensions = [ Dimension(name=dimensions_protos[id][0], value=dimensions_protos[id][1], layer=layer) for id in [i % 3, (i + 2) % 4, (i + 3) % 4] ] layer.metadatas = [ Metadata(name=metadatas_protos[id][0], value=metadatas_protos[id][1]) for id in [i % 3, (i + 2) % 3] ] for metadata in layer.metadatas: metadata.item = layer if i % 10 != 1: layer.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]] layer.restrictionareas = [ restrictionareas[i % 5], restrictionareas[(i + 2) % 5] ] dbsession.add( LayergroupTreeitem(group=groups[i % 5], item=layer, ordering=len(groups[i % 5].children_relation))) dbsession.add( LayergroupTreeitem(group=groups[(i + 3) % 5], item=layer, ordering=len(groups[(i + 3) % 5].children_relation))) dbsession.add(layer) layers.append(layer) return { "restrictionareas": restrictionareas, "layers": layers, "interfaces": interfaces }