Esempio n. 1
0
def theme_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        Theme, Role, Functionality, LayergroupTreeitem, \
        Interface, Metadata, LayerGroup, LayerWMS, OGCServer

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

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layer = LayerWMS(name='layer_wms')
    layer.ogc_server = OGCServer(name='server')
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value='value_{}'.format(v))
        for name in ('default_basemap', 'location') for v in range(0, 4)
    ]

    roles = [Role('secretary_' + str(i)) for i in range(0, 4)]

    metadatas_protos = [('copyable', 'true'), ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]
    themes = []
    for i in range(0, 25):
        theme = Theme(name='theme_{}'.format(i),
                      ordering=1,
                      icon='icon_{}'.format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        'themes': themes,
        'interfaces': interfaces,
        'groups': groups,
        'layers': layers,
        'functionalities': functionalities,
        'roles': roles,
    }
Esempio n. 2
0
def theme_test_data(dbsession, transact):
    del transact

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

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

    groups = [LayerGroup(name="layer_group_{}".format(i)) for i in range(0, 5)]

    layer = LayerWMS(name="layer_wms")
    layer.ogc_server = OGCServer(name="server")
    dbsession.add(layer)
    layers = [layer]

    functionalities = [
        Functionality(name=name, value="value_{}".format(v))
        for name in ("default_basemap", "location") for v in range(0, 4)
    ]

    roles = [Role("secretary_" + str(i)) for i in range(0, 4)]

    metadatas_protos = [
        ("copyable", "true"),
        ("disclaimer", "© le momo"),
        ("snappingConfig", '{"tolerance": 50}'),
    ]
    themes = []
    for i in range(0, 25):
        theme = Theme(name="theme_{}".format(i),
                      ordering=1,
                      icon="icon_{}".format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4], interfaces[(i + 2) % 4]]
        theme.metadatas = [
            Metadata(name=metadatas_protos[id][0],
                     value=metadatas_protos[id][1])
            for id in [i % 3, (i + 2) % 3]
        ]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [
            functionalities[i % 8], functionalities[(i + 3) % 8]
        ]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[i % 5],
                               ordering=len(groups[i % 5].children_relation)))
        dbsession.add(
            LayergroupTreeitem(group=theme,
                               item=groups[(i + 3) % 5],
                               ordering=len(groups[(i + 3) %
                                                   5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()

    yield {
        "themes": themes,
        "interfaces": interfaces,
        "groups": groups,
        "layers": layers,
        "functionalities": functionalities,
        "roles": roles,
    }
Esempio n. 3
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()
Esempio n. 4
0
def theme_test_data(dbsession):
    from c2cgeoportal_commons.models.main import \
        Theme, Role, Functionality, LayergroupTreeitem, \
        Interface, Metadata, LayerGroup, LayerWMS, OGCServer

    dbsession.begin_nested()

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

    groups = [LayerGroup(name='layer_group_{}'.format(i)) for i in range(0, 5)]

    layer = LayerWMS(name='layer_wms')
    layer.ogc_server = OGCServer(name='server')
    dbsession.add(layer)
    layers = [layer]

    functionalities = [Functionality(name=name, value='value_{}'.format(v))
                       for name in ('default_basemap', 'location') for v in range(0, 4)]

    roles = [Role('secretary_' + str(i)) for i in range(0, 4)]

    metadatas_protos = [('copyable', 'true'),
                        ('disclaimer', '© le momo'),
                        ('snappingConfig', '{"tolerance": 50}')]
    themes = []
    for i in range(0, 25):
        theme = Theme(name='theme_{}'.format(i),
                      ordering=1,
                      icon='icon_{}'.format(i))
        theme.public = 1 == i % 2
        theme.interfaces = [interfaces[i % 4],
                            interfaces[(i + 2) % 4]]
        theme.metadatas = [Metadata(name=metadatas_protos[id][0],
                                    value=metadatas_protos[id][1])
                           for id in [i % 3, (i + 2) % 3]]
        for metadata in theme.metadatas:
            metadata.item = theme
        theme.functionalities = [functionalities[i % 8], functionalities[(i + 3) % 8]]
        theme.restricted_roles = [roles[i % 4], roles[(i + 2) % 4]]

        dbsession.add(LayergroupTreeitem(group=theme,
                                         item=groups[i % 5],
                                         ordering=len(groups[i % 5].children_relation)))
        dbsession.add(LayergroupTreeitem(group=theme,
                                         item=groups[(i + 3) % 5],
                                         ordering=len(groups[(i + 3) % 5].children_relation)))

        dbsession.add(theme)
        themes.append(theme)

    dbsession.flush()
    yield {
        'themes': themes,
        'interfaces': interfaces,
        'groups': groups,
        'layers': layers,
        'functionalities': functionalities,
        'roles': roles,
    }

    dbsession.rollback()
Esempio n. 5
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()