Exemplo n.º 1
0
def metadatas_test_data(dbsession):
    from c2cgeoportal_commons.models.main import \
        LayerWMS, LayerWMTS, LayerV1, OGCServer, Metadata, Theme, LayerGroup

    dbsession.begin_nested()

    ogc_server = OGCServer(name='ogc_server')

    layer_wms = LayerWMS(name='layer_wms')
    layer_wms.layer = 'wms_layer'
    layer_wms.ogc_server = ogc_server
    layer_wms.metadatas = [
        Metadata(name, value)
        for name, value in [
            ('_string', 'ceci est un test'),
            ('_liste', 'valeur1,valeur2'),
            ('_boolean', 'true'),
            ('_int', '1'),
            ('_float', '2.5'),
            ('_url', 'https://localhost/test.html'),
            ('_json', '{"key":"value"}'),
            ('_color', '#FFFFFF'),
            ('_unknown', 'This is a unknown format')
        ]
    ]
    for metadata in layer_wms.metadatas:
        metadata.item = layer_wms
    dbsession.add(layer_wms)

    layer_wmts = LayerWMTS(name='layer_wmts')
    layer_wmts.url = 'https://localhost'
    layer_wmts.layer = 'wmts_layer'
    dbsession.add(layer_wmts)

    layer_v1 = LayerV1(name='layer_v1')
    dbsession.add(layer_v1)

    theme = Theme(name='theme')
    dbsession.add(theme)

    group = LayerGroup(name='groups')
    dbsession.add(group)

    dbsession.flush()

    yield {
        'ogc_server': ogc_server,
        'layer_wms': layer_wms,
        'layer_wmts': layer_wmts,
        'layer_v1': layer_v1,
        'theme': theme,
        'group': group
    }

    dbsession.rollback()
Exemplo n.º 2
0
def metadatas_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        LayerWMS, LayerWMTS, LayerV1, OGCServer, Metadata, Theme, LayerGroup

    ogc_server = OGCServer(name='ogc_server')

    layer_wms = LayerWMS(name='layer_wms')
    layer_wms.layer = 'wms_layer'
    layer_wms.ogc_server = ogc_server
    layer_wms.metadatas = [
        Metadata(name, value) for name, value in
        [('_string',
          'ceci est un test'), ('_liste',
                                'valeur1,valeur2'), ('_boolean',
                                                     'true'), ('_int', '1'),
         ('_float',
          '2.5'), ('_url',
                   'https://localhost/test.html'), ('_json',
                                                    '{"key":"value"}'),
         ('_color', '#FFFFFF'), ('_unknown', 'This is a unknown format')]
    ]
    for metadata in layer_wms.metadatas:
        metadata.item = layer_wms
    dbsession.add(layer_wms)

    layer_wmts = LayerWMTS(name='layer_wmts')
    layer_wmts.url = 'https://localhost'
    layer_wmts.layer = 'wmts_layer'
    dbsession.add(layer_wmts)

    layer_v1 = LayerV1(name='layer_v1')
    dbsession.add(layer_v1)

    theme = Theme(name='theme')
    dbsession.add(theme)

    group = LayerGroup(name='groups')
    dbsession.add(group)

    dbsession.flush()

    yield {
        'ogc_server': ogc_server,
        'layer_wms': layer_wms,
        'layer_wmts': layer_wmts,
        'layer_v1': layer_v1,
        'theme': theme,
        'group': group
    }
Exemplo n.º 3
0
    def setUp(self):  # noqa
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None

        self.clean()

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User
        from c2cgeoportal_commons.models.main import \
            Theme, LayerGroup, Interface, LayerWMS, LayerWMTS, Role, RestrictionArea

        main = Interface(name=u"desktop")
        role = Role(name=u"__test_role")
        user = User(username=u"__test_user", password=u"__test_user", role=role)
        user.email = "*****@*****.**"
        ogc_server_internal, _ = create_default_ogcserver()

        layer_wms = LayerWMS(name=u"__test_layer_wms", public=True)
        layer_wms.layer = "__test_public_layer"
        layer_wms.interfaces = [main]
        layer_wms.ogc_server = ogc_server_internal

        layer_wms_private = LayerWMS(name=u"__test_layer_wms_private", public=True)
        layer_wms_private.layer = "__test_private_layer"
        layer_wms_private.public = False
        layer_wms_private.interfaces = [main]
        layer_wms_private.ogc_server = ogc_server_internal

        layer_wmts = LayerWMTS(name=u"__test_layer_wmts", public=True)
        layer_wmts.url = "http://example.com/1.0.0/WMTSCapabilities.xml"
        layer_wmts.layer = "map"
        layer_wmts.interfaces = [main]

        layer_wmts_private = LayerWMTS(name=u"__test_layer_wmts_private", public=True)
        layer_wmts_private.url = "http://example.com/1.0.0/WMTSCapabilities.xml"
        layer_wmts_private.layer = "map"
        layer_wmts_private.public = False
        layer_wmts_private.interfaces = [main]

        layer_group = LayerGroup(name=u"__test_layer_group")
        layer_group.children = [layer_wms, layer_wms_private, layer_wmts, layer_wmts_private]

        theme = Theme(name=u"__test_theme")
        theme.interfaces = [main]
        theme.children = [layer_group]

        restriction_area = RestrictionArea(
            name=u"__test_ra1", layers=[layer_wms_private, layer_wmts_private], roles=[role]
        )

        DBSession.add_all([theme, restriction_area, user])

        transaction.commit()
Exemplo n.º 4
0
def get_test_default_layers(dbsession, default_ogc_server):
    from c2cgeoportal_commons.models.main import LayerWMTS, LayerWMS
    default_wms = LayerWMS('wms-defaults')
    default_wms.ogc_server = default_ogc_server
    default_wms.time_widget = 'datepicker'
    default_wms.time_mode = 'value'
    dbsession.add(default_wms)
    default_wmts = LayerWMTS('wmts-defaults')
    default_wmts.url = 'https:///wmts.geo.admin_default.ch.org?service=wms&request=GetCapabilities'
    default_wmts.layer = 'default'
    default_wmts.matrix_set = 'matrix'

    dbsession.add(default_wmts)
    dbsession.flush()
    return {'wms': default_wms, 'wmts': default_wmts}
Exemplo n.º 5
0
def metadatas_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import LayerWMS, LayerWMTS, OGCServer, Metadata, Theme, LayerGroup

    ogc_server = OGCServer(name="ogc_server")

    layer_wms = LayerWMS(name="layer_wms")
    layer_wms.layer = "wms_layer"
    layer_wms.ogc_server = ogc_server
    layer_wms.metadatas = [
        Metadata(name, value)
        for name, value in [
            ("_string", "ceci est un test"),
            ("_liste", "valeur1,valeur2"),
            ("_boolean", "true"),
            ("_int", "1"),
            ("_float", "2.5"),
            ("_url", "https://localhost/test.html"),
            ("_json", '{"key":"value"}'),
            ("_color", "#FFFFFF"),
            ("_unknown", "This is a unknown format"),
        ]
    ]
    for metadata in layer_wms.metadatas:
        metadata.item = layer_wms
    dbsession.add(layer_wms)

    layer_wmts = LayerWMTS(name="layer_wmts")
    layer_wmts.url = "https://localhost"
    layer_wmts.layer = "wmts_layer"
    dbsession.add(layer_wmts)

    theme = Theme(name="theme")
    dbsession.add(theme)

    group = LayerGroup(name="groups")
    dbsession.add(group)

    dbsession.flush()

    yield {
        "ogc_server": ogc_server,
        "layer_wms": layer_wms,
        "layer_wmts": layer_wmts,
        "theme": theme,
        "group": group,
    }
Exemplo n.º 6
0
 def view(self):
     if self._is_new():
         dbsession = self._request.dbsession
         default_wmts = LayerWMTS.get_default(dbsession)
         if default_wmts:
             return self.copy(default_wmts, excludes=["name", "layer"])
     return super().edit()
Exemplo n.º 7
0
 def test_convert_without_wmts_defaults(self, test_app, layer_wms_test_data,
                                        dbsession):
     from c2cgeoportal_commons.models.main import LayerWMTS
     dbsession.delete(LayerWMTS.get_default(dbsession))
     layer = layer_wms_test_data['layers'][3]
     test_app.post("/layers_wms/{}/convert_to_wmts".format(layer.id),
                   status=200)
Exemplo n.º 8
0
 def view(self) -> Dict[str, Any]:
     if self._is_new():
         dbsession = self._request.dbsession
         default_wmts = LayerWMTS.get_default(dbsession)
         if default_wmts:
             return self.copy(default_wmts,
                              excludes=["name", "layer"])  # type: ignore
     return super().edit()  # type: ignore
Exemplo n.º 9
0
 def layer_builder(i):
     name = 'layer_wmts_{}'.format(i)
     layer = LayerWMTS(name=name)
     layer.layer = name
     layer.url = 'https:///wms.geo.admin.ch_{}.org?service=wms&request=GetCapabilities'.format(i)
     layer.public = 1 == i % 2
     layer.geo_table = 'geotable_{}'.format(i)
     layer.image_type = 'image/jpeg'
     layer.style = 'décontrasté'
     return layer
Exemplo n.º 10
0
 def layer_builder(i):
     name = f"layer_wmts_{i}"
     layer = LayerWMTS(name=name)
     layer.layer = name
     layer.url = f"https:///wms.geo.admin.ch_{i}.org?service=wms&request=GetCapabilities"
     layer.public = 1 == i % 2
     layer.geo_table = f"geotable_{i}"
     layer.image_type = "image/jpeg"
     layer.style = "décontrasté"
     return layer
Exemplo n.º 11
0
def layer_wmts_test_data(dbsession):
    from c2cgeoportal_commons.models.main import \
        LayerWMTS, RestrictionArea, Interface

    dbsession.begin_nested()

    restrictionareas = [RestrictionArea(name='restrictionarea_{}'.format(i))
                        for i in range(0, 5)]

    interfaces = [Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']]

    layers = []
    for i in range(0, 25):
        name = 'layer_wmts_{}'.format(i)
        layer = LayerWMTS(name=name)
        layer.layer = name
        layer.url = 'https://server{}.net/wmts'.format(i)
        layer.restrictionareas = [restrictionareas[i % 5],
                                  restrictionareas[(i + 2) % 5]]
        if i % 10 != 1:
            layer.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        layer.public = 1 == i % 2
        layer.image_type = 'image/jpeg'
        dbsession.add(layer)
        layers.append(layer)

    dbsession.flush()
    yield {
        'layers': layers,
        'restrictionareas': restrictionareas,
        'interfaces': interfaces
    }

    dbsession.rollback()
Exemplo n.º 12
0
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)
Exemplo n.º 13
0
def get_test_default_layers(dbsession, default_ogc_server):
    from c2cgeoportal_commons.models.main import LayerVectorTiles, LayerWMS, LayerWMTS

    default_wms = LayerWMS("wms-defaults")
    default_wms.ogc_server = default_ogc_server
    default_wms.time_widget = "datepicker"
    default_wms.time_mode = "value"
    dbsession.add(default_wms)
    default_wmts = LayerWMTS("wmts-defaults")
    default_wmts.url = "https:///wmts.geo.admin_default.ch.org?service=wms&request=GetCapabilities"
    default_wmts.layer = "default"
    default_wmts.matrix_set = "matrix"
    dbsession.add(default_wmts)
    default_vectortiles = LayerVectorTiles("vectortiles-defaults")
    default_vectortiles.style = "https://vectortiles-staging.geoportail.lu/styles/roadmap/style.json"
    dbsession.add(default_vectortiles)
    dbsession.flush()
    return {
        "wms": default_wms,
        "wmts": default_wmts,
        "vectortiles": default_vectortiles
    }
Exemplo n.º 14
0
    def convert_to_wmts(self) -> Dict[str, Any]:
        src = self._get_object()
        dbsession = self._request.dbsession
        default_wmts = LayerWMTS.get_default(dbsession)
        values = ({
            "url": default_wmts.url,
            "matrix_set": default_wmts.matrix_set
        } if default_wmts else {
            "url": "",
            "matrix_set": ""
        })
        with dbsession.no_autoflush:
            d = delete(LayerWMS.__table__)
            d = d.where(LayerWMS.__table__.c.id == src.id)
            i = insert(LayerWMTS.__table__)
            values.update({
                "id": src.id,
                "layer": src.layer,
                "image_type": src.ogc_server.image_type,
                "style": src.style,
            })
            i = i.values(values)
            u = update(TreeItem.__table__)
            u = u.where(TreeItem.__table__.c.id == src.id)
            u = u.values({"type": "l_wmts"})
            dbsession.execute(d)
            dbsession.execute(i)
            dbsession.execute(u)
            dbsession.expunge(src)

        dbsession.flush()
        mark_changed(dbsession)

        return {
            "success":
            True,
            "redirect":
            self._request.route_url(
                "c2cgeoform_item",
                table="layers_wmts",
                id=self._request.matchdict["id"],
                _query=[("msg_col", "submit_ok")],
            ),
        }
Exemplo n.º 15
0
    def convert_to_wmts(self):
        src = self._get_object()
        dbsession = self._request.dbsession
        default_wmts = LayerWMTS.get_default(dbsession)
        values = {
            'url': default_wmts.url,
            'matrix_set': default_wmts.matrix_set
        } if default_wmts else {
            'url': '',
            'matrix_set': ''
        }
        with dbsession.no_autoflush:
            d = delete(LayerWMS.__table__)
            d = d.where(LayerWMS.__table__.c.id == src.id)
            i = insert(LayerWMTS.__table__)
            values.update({
                'id': src.id,
                'layer': src.layer,
                'image_type': src.ogc_server.image_type,
                'style': src.style
            })
            i = i.values(values)
            u = update(TreeItem.__table__)
            u = u.where(TreeItem.__table__.c.id == src.id)
            u = u.values({'type': 'l_wmts'})
            dbsession.execute(d)
            dbsession.execute(i)
            dbsession.execute(u)
            dbsession.expunge(src)

        dbsession.flush()
        mark_changed(dbsession)

        return {
            'success':
            True,
            'redirect':
            self._request.route_url('c2cgeoform_item',
                                    table='layers_wmts',
                                    id=self._request.matchdict['id'],
                                    _query=[('msg_col', 'submit_ok')])
        }
Exemplo n.º 16
0
    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, Interface, LayerWMS, LayerWMTS, Dimension

        ogc_server, _ = create_default_ogcserver()
        main = Interface(name="main")

        layer_wms_1 = LayerWMS(name="__test_layer_wms_1", public=True)
        layer_wms_1.layer = "__test_layer_wms_1"
        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 = "__test_layer_wms_2"
        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 = "__test_layer_wms_3"
        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 = "__test_layer_wms_4"
        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 = "__test_layer_wms_5"
        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 = "__test_layer_wms_6"
        layer_wms_6.interfaces = [main]
        layer_wms_6.ogc_server = ogc_server
        Dimension("FILTER", "countries:\"name\" IN ( 'Germany' , 'Italy' )", layer_wms_6)

        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]
        Dimension("B", "b", layer_wmts)

        layer_wmts_2 = LayerWMTS(name="__test_layer_wmts_2", public=True)
        layer_wmts_2.url = "http://example.com/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]

        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,
        ]

        DBSession.add(theme)

        transaction.commit()
Exemplo n.º 17
0
def layertree_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import (
        LayerGroup,
        LayergroupTreeitem,
        LayerWMS,
        LayerWMTS,
        OGCServer,
        Theme,
    )

    layers_wms = []
    ogc_server = OGCServer(name="ogc_server")
    dbsession.add(ogc_server)
    for i in range(0, 10):
        layer_wms = LayerWMS(name="layer_wms_{}".format(i))
        layer_wms.ogc_server = ogc_server
        layers_wms.append(layer_wms)
        dbsession.add(layer_wms)

    layers_wmts = []
    for i in range(0, 10):
        layer_wmts = LayerWMTS(name="layer_wmts_{}".format(i))
        layer_wmts.url = "http://localhost/wmts"
        layer_wmts.layer = layer_wmts.name
        layers_wmts.append(layer_wmts)
        dbsession.add(layer_wmts)

    groups = []
    for i in range(0, 10):
        group = LayerGroup(name="layer_group_{}".format(i))
        groups.append(group)
        dbsession.add(group)

        for j, items in enumerate((layers_wms, layers_wmts)):
            dbsession.add(LayergroupTreeitem(group=group, item=items[i], ordering=j))

    # a group in a group
    dbsession.add(LayergroupTreeitem(group=groups[9], item=groups[8], ordering=3))

    themes = []
    for i in range(0, 5):
        theme = Theme(name="theme_{}".format(i))
        themes.append(theme)
        dbsession.add(theme)

        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i], ordering=0))
        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i + 5], ordering=1))

    themes[0].ordering = 1
    themes[3].ordering = 2
    themes[1].ordering = 3
    themes[2].ordering = 4
    themes[4].ordering = 5

    dbsession.flush()

    yield (
        {
            "themes": themes,
            "groups": groups,
            "layers_wms": layers_wms,
            "layers_wmts": layers_wmts,
            "ogc_servers": [ogc_server],
        }
    )
Exemplo n.º 18
0
def layertree_test_data(dbsession):
    from c2cgeoportal_commons.models.main import \
        LayerGroup, LayergroupTreeitem, LayerV1, LayerWMS, LayerWMTS, OGCServer, Theme

    dbsession.begin_nested()

    layers_v1 = []
    for i in range(0, 10):
        layer_v1 = LayerV1(name='layer_v1_{}'.format(i))
        layers_v1.append(layer_v1)
        dbsession.add(layer_v1)

    layers_wms = []
    ogc_server = OGCServer(name='ogc_server')
    dbsession.add(ogc_server)
    for i in range(0, 10):
        layer_wms = LayerWMS(name='layer_wms_{}'.format(i))
        layer_wms.ogc_server = ogc_server
        layers_wms.append(layer_wms)
        dbsession.add(layer_wms)

    layers_wmts = []
    for i in range(0, 10):
        layer_wmts = LayerWMTS(name='layer_wmts_{}'.format(i))
        layer_wmts.url = 'http://localhost/wmts'
        layer_wmts.layer = layer_wmts.name
        layers_wmts.append(layer_wmts)
        dbsession.add(layer_wmts)

    groups = []
    for i in range(0, 10):
        group = LayerGroup(name='layer_group_{}'.format(i))
        groups.append(group)
        dbsession.add(group)

        for j, items in enumerate((layers_v1, layers_wms, layers_wmts)):
            dbsession.add(LayergroupTreeitem(group=group, item=items[i], ordering=j))

    # a group in a group
    dbsession.add(LayergroupTreeitem(group=groups[9], item=groups[8], ordering=3))

    themes = []
    for i in range(0, 5):
        theme = Theme(name='theme_{}'.format(i))
        themes.append(theme)
        dbsession.add(theme)

        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i], ordering=0))
        dbsession.add(LayergroupTreeitem(group=theme, item=groups[i + 5], ordering=1))

    themes[0].ordering = 1
    themes[3].ordering = 2
    themes[1].ordering = 3
    themes[2].ordering = 4
    themes[4].ordering = 5

    dbsession.flush()

    yield({
        'themes': themes,
        'groups': groups,
        'layers_v1': layers_v1,
        'layers_wms': layers_wms,
        'layers_wmts': layers_wmts,
    })

    dbsession.rollback()
Exemplo n.º 19
0
    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, Interface, OGCServer, LayerWMS, LayerWMTS

        main = Interface(name="main")

        ogc_server_internal = create_default_ogcserver()
        ogc_server_external = OGCServer(name="__test_ogc_server_external", url="http://wms.geo.admin.ch/", image_type="image/jpeg")

        layer_internal_wms = LayerWMS(name="__test_layer_internal_wms", public=True)
        layer_internal_wms.layer = "__test_layer_internal_wms"
        layer_internal_wms.interfaces = [main]
        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.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]

        layer_group_1 = LayerGroup(name="__test_layer_group_1")
        layer_group_1.children = [layer_internal_wms]

        layer_group_2 = LayerGroup(name="__test_layer_group_2")
        layer_group_2.children = [layer_external_wms]

        layer_group_3 = LayerGroup(name="__test_layer_group_3")
        layer_group_3.children = [layer_wmts]

        layer_group_4 = LayerGroup(name="__test_layer_group_4")
        layer_group_4.children = [layer_group_1, layer_group_2]

        layer_group_5 = LayerGroup(name="__test_layer_group_5")
        layer_group_5.children = [layer_group_1, layer_group_3]

        layer_group_6 = LayerGroup(name="__test_layer_group_6")
        layer_group_6.children = [layer_internal_wms]

        layer_group_7 = LayerGroup(name="__test_layer_group_7")
        layer_group_7.children = [layer_group_1, layer_group_6]

        layer_group_8 = LayerGroup(name="__test_layer_group_8")
        layer_group_8.children = [layer_group_2, layer_group_6]

        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_7, layer_group_8,
        ]

        DBSession.add(theme)

        transaction.commit()
Exemplo n.º 20
0
def edit_url_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        LayerWMTS, RestrictionArea, Interface, Role, \
        LayerWMS, LayerGroup, Theme, OGCServer, Functionality

    restrictionareas = [
        RestrictionArea(name='restrictionarea_{}'.format(i))
        for i in range(0, 5)
    ]
    functionalities = {}
    for name in ('default_basemap', 'location'):
        functionalities[name] = []
        for v in range(0, 4):
            functionality = Functionality(name=name,
                                          value='value_{}'.format(v))
            dbsession.add(functionality)
            functionalities[name].append(functionality)

    interfaces = [
        Interface(name) for name in ['desktop', 'mobile', 'edit', 'routing']
    ]
    ogc_server = OGCServer(name='ogc_server')

    layers_wmts = []
    for i in range(0, 5):
        name = 'layer_wmts_{}'.format(i)
        layer_wmts = LayerWMTS(name=name)
        layer_wmts.layer = name
        layer_wmts.url = 'https://server{}.net/wmts'.format(i)
        layer_wmts.restrictionareas = [
            restrictionareas[i % 5], restrictionareas[(i + 2) % 5]
        ]
        if i % 10 != 1:
            layer_wmts.interfaces = [
                interfaces[i % 4], interfaces[(i + 2) % 4]
            ]
        layer_wmts.public = 1 == i % 2
        layer_wmts.image_type = 'image/jpeg'
        dbsession.add(layer_wmts)
        layers_wmts.append(layer_wmts)

    layers_wms = []
    for i in range(0, 5):
        layer_wms = LayerWMS(name='layer_wms_{}'.format(i))
        layer_wms.layer = 'wms_layer_{}'.format(i)
        layer_wms.ogc_server = ogc_server
        layers_wms.append(layer_wms)
        dbsession.add(layer_wms)
        layers_wms.append(layer_wms)

    roles = []
    for i in range(0, 5):
        role = Role('secretary_' + str(i))
        role.functionalities = [
            functionalities['default_basemap'][0],
            functionalities['location'][0], functionalities['location'][1]
        ]
        role.restrictionareas = [restrictionareas[0], restrictionareas[1]]
        dbsession.add(role)
        roles.append(role)

    dbsession.flush()

    group = LayerGroup(name='groups')
    dbsession.add(group)
    theme = Theme(name='theme')
    dbsession.add(theme)

    dbsession.flush()

    yield {
        'ogc_server': ogc_server,
        'layers_wmts': layers_wmts,
        'layers_wms': layers_wms,
        'restrictionareas': restrictionareas,
        'interfaces': interfaces,
        'themes': [theme],
        'group': group,
        'roles': roles
    }
Exemplo n.º 21
0
    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()
Exemplo n.º 22
0
    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, Interface, LayerWMS, LayerWMTS

        PointTest.__table__.create(bind=DBSession.bind, checkfirst=True)

        main = Interface(name="desktop")
        ogc_server = create_default_ogcserver()

        layer_wms_1 = LayerWMS(name="__test_layer_time_1", public=True)
        layer_wms_1.layer = "test_wmstime"
        layer_wms_1.time_mode = "value"
        layer_wms_1.interfaces = [main]
        layer_wms_1.ogc_server = ogc_server

        layer_wms_2 = LayerWMS(name="__test_layer_time_2", public=True)
        layer_wms_2.layer = "test_wmstime2"
        layer_wms_2.time_mode = "value"
        layer_wms_2.interfaces = [main]
        layer_wms_2.ogc_server = ogc_server

        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]

        layer_wms_group = LayerWMS(name="__test_layer_time_group", public=True)
        layer_wms_group.layer = "test_wmstimegroup"
        layer_wms_group.time_mode = "range"
        layer_wms_group.time_widget = "datepicker"
        layer_wms_group.interfaces = [main]
        layer_wms_group.ogc_server = ogc_server

        layer_group_1 = LayerGroup(name="__test_layer_group_1")
        layer_group_1.children = [layer_wms_1, layer_wms_2]

        layer_group_2 = LayerGroup(name="__test_layer_group_2")
        layer_group_2.children = [layer_wms_1]

        layer_group_3 = LayerGroup(name="__test_layer_group_3")
        layer_group_3.children = [layer_wms_1, layer_wms_2, layer_wms_group]

        layer_group_4 = LayerGroup(name="__test_layer_group_4")
        layer_group_4.children = [layer_wms_group]

        layer_group_5 = LayerGroup(name="__test_layer_group_5")
        layer_group_5.children = [layer_wms_1, layer_wms_2]

        layer_group_6 = LayerGroup(name="__test_layer_group_6")
        layer_group_6.children = [layer_wms_1, layer_wms_2, layer_wmts]

        layer_group_7 = LayerGroup(name="__test_layer_group_7")
        layer_group_7.children = [layer_wms_1]

        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_all([theme])

        transaction.commit()
Exemplo n.º 23
0
    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, \
            LayerV1, OGCServer, LayerWMS, LayerWMTS, \
            Metadata, Dimension, OGCSERVER_AUTH_NOAUTH

        main = Interface(name="desktop")
        mobile = Interface(name="mobile")
        min_levels = Interface(name="min_levels")

        layer_v1 = LayerV1(name="__test_layer_v1", public=True)
        layer_v1.interfaces = [main]
        layer_v1.metadatas = [Metadata("test", "v1")]

        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_v1, 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()
Exemplo n.º 24
0
def edit_url_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import (
        Functionality,
        Interface,
        LayerGroup,
        LayerWMS,
        LayerWMTS,
        OGCServer,
        RestrictionArea,
        Role,
        Theme,
    )

    restrictionareas = [
        RestrictionArea(name=f"restrictionarea_{i}") for i in range(0, 5)
    ]
    functionalities = {}
    for name in ("default_basemap", "default_theme"):
        functionalities[name] = []
        for v in range(0, 4):
            functionality = Functionality(name=name, value=f"value_{v}")
            dbsession.add(functionality)
            functionalities[name].append(functionality)

    interfaces = [
        Interface(name) for name in ["desktop", "mobile", "edit", "routing"]
    ]
    ogc_server = OGCServer(name="ogc_server")

    layers_wmts = []
    for i in range(0, 5):
        name = f"layer_wmts_{i}"
        layer_wmts = LayerWMTS(name=name)
        layer_wmts.layer = name
        layer_wmts.url = f"https://server{i}.net/wmts"
        layer_wmts.restrictionareas = [
            restrictionareas[i % 5], restrictionareas[(i + 2) % 5]
        ]
        if i % 10 != 1:
            layer_wmts.interfaces = [
                interfaces[i % 4], interfaces[(i + 2) % 4]
            ]
        layer_wmts.public = 1 == i % 2
        layer_wmts.image_type = "image/jpeg"
        dbsession.add(layer_wmts)
        layers_wmts.append(layer_wmts)

    layers_wms = []
    for i in range(0, 5):
        layer_wms = LayerWMS(name=f"layer_wms_{i}")
        layer_wms.layer = f"wms_layer_{i}"
        layer_wms.ogc_server = ogc_server
        layers_wms.append(layer_wms)
        dbsession.add(layer_wms)
        layers_wms.append(layer_wms)

    roles = []
    for i in range(0, 5):
        role = Role("secretary_" + str(i))
        role.functionalities = [
            functionalities["default_theme"][0],
        ]
        role.restrictionareas = [restrictionareas[0], restrictionareas[1]]
        dbsession.add(role)
        roles.append(role)

    dbsession.flush()

    group = LayerGroup(name="groups")
    dbsession.add(group)
    theme = Theme(name="theme")
    dbsession.add(theme)

    dbsession.flush()

    yield {
        "ogc_server": ogc_server,
        "layers_wmts": layers_wmts,
        "layers_wms": layers_wms,
        "restrictionareas": restrictionareas,
        "interfaces": interfaces,
        "themes": [theme],
        "group": group,
        "roles": roles,
    }
Exemplo n.º 25
0
    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 Interface, LayerGroup, LayerWMS, LayerWMTS, Theme

        DBSession.query(PointTest).delete()

        main = Interface(name="desktop")
        ogc_server = create_default_ogcserver()

        layer_wms_1 = LayerWMS(name="__test_layer_time_1", public=True)
        layer_wms_1.layer = "test_wmstime"
        layer_wms_1.time_mode = "value"
        layer_wms_1.interfaces = [main]
        layer_wms_1.ogc_server = ogc_server

        layer_wms_2 = LayerWMS(name="__test_layer_time_2", public=True)
        layer_wms_2.layer = "test_wmstime2"
        layer_wms_2.time_mode = "value"
        layer_wms_2.interfaces = [main]
        layer_wms_2.ogc_server = ogc_server

        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]

        layer_wms_group_1 = LayerWMS(name="__test_layer_time_group_1", public=True)
        layer_wms_group_1.layer = "test_wmstimegroup"
        layer_wms_group_1.time_mode = "range"
        layer_wms_group_1.time_widget = "datepicker"
        layer_wms_group_1.interfaces = [main]
        layer_wms_group_1.ogc_server = ogc_server

        layer_wms_group_2 = LayerWMS(name="__test_layer_time_group_2", public=True)
        layer_wms_group_2.layer = "test_wmstimegroup"
        layer_wms_group_2.time_mode = "value"
        layer_wms_group_2.interfaces = [main]
        layer_wms_group_2.ogc_server = ogc_server

        layer_wms_no_time = LayerWMS(name="__test_layer_without_time_info", public=True)
        layer_wms_no_time.layer = "test_wmsfeatures"
        layer_wms_no_time.time_mode = "value"
        layer_wms_no_time.interfaces = [main]
        layer_wms_no_time.ogc_server = ogc_server

        # Expect merge of times
        layer_group_1 = LayerGroup(name="__test_layer_group_1")
        layer_group_1.children = [layer_wms_1, layer_wms_2]

        # Expect time from layer.
        layer_group_2 = LayerGroup(name="__test_layer_group_2")
        layer_group_2.children = [layer_wms_1]

        # Expect merge of wms 1 and 2, layer_wms_group_1 excluded and in errors as its mode don't match.
        layer_group_3 = LayerGroup(name="__test_layer_group_3")
        layer_group_3.children = [layer_wms_1, layer_wms_2, layer_wms_group_1]

        # Expect time from layers in wms layer group
        layer_group_4 = LayerGroup(name="__test_layer_group_4")
        layer_group_4.children = [layer_wms_group_1]

        # Expect merge of wms 1 and 2 and group.
        layer_group_5 = LayerGroup(name="__test_layer_group_5")
        layer_group_5.children = [layer_wms_1, layer_wms_2, layer_wms_group_2]

        # Expect individual layers
        layer_group_6 = LayerGroup(name="__test_layer_group_6")
        layer_group_6.children = [layer_wms_1, layer_wms_2, layer_wmts]

        # Expect layer_wms_no_time excluded and in errors as it has no time info
        layer_group_7 = LayerGroup(name="__test_layer_group_7")
        layer_group_7.children = [layer_wms_1, layer_wms_no_time]

        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_all([theme])

        transaction.commit()
Exemplo n.º 26
0
    def test_convert_without_wmts_defaults(self, test_app, layer_wms_test_data, dbsession):
        from c2cgeoportal_commons.models.main import LayerWMTS

        dbsession.delete(LayerWMTS.get_default(dbsession))
        layer = layer_wms_test_data["layers"][3]
        test_app.post(f"/admin/layers_wms/{layer.id}/convert_to_wmts", status=200)
Exemplo n.º 27
0
    def setUp(self):  # noqa
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None

        self.clean()

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.static import User
        from c2cgeoportal_commons.models.main import \
            Theme, LayerGroup, Interface, LayerWMS, LayerWMTS, Role, RestrictionArea

        main = Interface(name=u"desktop")
        role = Role(name=u"__test_role")
        user = User(username=u"__test_user",
                    password=u"__test_user",
                    role=role)
        user.email = "*****@*****.**"
        ogc_server_internal, _ = create_default_ogcserver()

        layer_wms = LayerWMS(name=u"__test_layer_wms", public=True)
        layer_wms.layer = "__test_public_layer"
        layer_wms.interfaces = [main]
        layer_wms.ogc_server = ogc_server_internal

        layer_wms_private = LayerWMS(name=u"__test_layer_wms_private",
                                     public=True)
        layer_wms_private.layer = "__test_private_layer"
        layer_wms_private.public = False
        layer_wms_private.interfaces = [main]
        layer_wms_private.ogc_server = ogc_server_internal

        layer_wmts = LayerWMTS(name=u"__test_layer_wmts", public=True)
        layer_wmts.url = "http://example.com/1.0.0/WMTSCapabilities.xml"
        layer_wmts.layer = "map"
        layer_wmts.interfaces = [main]

        layer_wmts_private = LayerWMTS(name=u"__test_layer_wmts_private",
                                       public=True)
        layer_wmts_private.url = "http://example.com/1.0.0/WMTSCapabilities.xml"
        layer_wmts_private.layer = "map"
        layer_wmts_private.public = False
        layer_wmts_private.interfaces = [main]

        layer_group = LayerGroup(name=u"__test_layer_group")
        layer_group.children = [
            layer_wms, layer_wms_private, layer_wmts, layer_wmts_private
        ]

        theme = Theme(name=u"__test_theme")
        theme.interfaces = [main]
        theme.children = [layer_group]

        restriction_area = RestrictionArea(
            name=u"__test_ra1",
            layers=[layer_wms_private, layer_wmts_private],
            roles=[role])

        DBSession.add_all([theme, restriction_area, user])

        transaction.commit()
Exemplo n.º 28
0
    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()
Exemplo n.º 29
0
    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, Interface, OGCServer, LayerWMS, LayerWMTS

        main = Interface(name="main")

        ogc_server_internal, _ = create_default_ogcserver()
        ogc_server_external = OGCServer(name="__test_ogc_server_external", url="http://wms.geo.admin.ch/", image_type="image/jpeg")

        layer_internal_wms = LayerWMS(name="__test_layer_internal_wms", public=True)
        layer_internal_wms.layer = "__test_layer_internal_wms"
        layer_internal_wms.interfaces = [main]
        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.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]

        layer_group_1 = LayerGroup(name="__test_layer_group_1")
        layer_group_1.children = [layer_internal_wms]

        layer_group_2 = LayerGroup(name="__test_layer_group_2")
        layer_group_2.children = [layer_external_wms]

        layer_group_3 = LayerGroup(name="__test_layer_group_3")
        layer_group_3.children = [layer_wmts]

        layer_group_4 = LayerGroup(name="__test_layer_group_4")
        layer_group_4.children = [layer_group_1, layer_group_2]

        layer_group_5 = LayerGroup(name="__test_layer_group_5")
        layer_group_5.children = [layer_group_1, layer_group_3]

        layer_group_6 = LayerGroup(name="__test_layer_group_6")
        layer_group_6.children = [layer_internal_wms]

        layer_group_7 = LayerGroup(name="__test_layer_group_7")
        layer_group_7.children = [layer_group_1, layer_group_6]

        layer_group_8 = LayerGroup(name="__test_layer_group_8")
        layer_group_8.children = [layer_group_2, layer_group_6]

        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_7, layer_group_8,
        ]

        DBSession.add(theme)

        transaction.commit()