Beispiel #1
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 LayerV1, Theme, Interface, LayerGroup

        create_default_ogcserver()
        main = Interface(name="main")
        mobile = Interface(name="mobile")

        layer = LayerV1(name="__test_layer")
        layer.interfaces = [main, mobile]

        mobile_only_layer = LayerV1(name="__test_mobile_only_layer")
        mobile_only_layer.interfaces = [mobile]

        desktop_only_layer = LayerV1(name="__test_desktop_only_layer")
        desktop_only_layer.interfaces = [main]

        group = LayerGroup(name="__test_layer_group")
        group.children = [layer, mobile_only_layer, desktop_only_layer]
        theme = Theme(name="__test_theme")
        theme.children = [group]
        theme.interfaces = [main, mobile]

        mobile_only_group = LayerGroup(name="__test_mobile_only_layer_group")
        mobile_only_group.children = [layer]
        mobile_only_theme = Theme(name="__test_mobile_only_theme")
        mobile_only_theme.children = [mobile_only_group]
        mobile_only_theme.interfaces = [mobile]

        desktop_only_group = LayerGroup(name="__test_desktop_only_layer_group")
        desktop_only_group.children = [layer]
        desktop_only_theme = Theme(name="__test_desktop_only_theme")
        desktop_only_theme.children = [desktop_only_group]
        desktop_only_theme.interfaces = [main]

        # the following theme should not appear in the list of themes on desktop
        # nor on mobile
        # It should be accessible by explicitly loading it in mobile though
        mobile_private_group = LayerGroup(
            name="__test_mobile_private_layer_group")
        mobile_private_group.children = [layer]
        mobile_private_theme = Theme(name="__test_mobile_private_theme")
        mobile_private_theme.children = [mobile_private_group]

        DBSession.add_all([
            layer, mobile_only_layer, desktop_only_layer, theme,
            mobile_only_theme, desktop_only_theme, mobile_private_theme
        ])
        transaction.commit()
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
    }
    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()
Beispiel #4
0
 def layer_builder(i):
     layer = LayerV1(name='layer_v1_{}'.format(i))
     layer.public = 1 == i % 2
     layer.image_type = 'image/jpeg'
     return layer
Beispiel #5
0
def edit_url_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import \
        LayerWMTS, RestrictionArea, Interface, Role, \
        LayerWMS, LayerV1, 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)

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

    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,
        'layers_v1': layers_v1,
        'themes': [theme],
        'group': group,
        'roles': roles
    }
Beispiel #6
0
    def _create_layer(self,
                      public=False,
                      none_area=False,
                      attr_list=False,
                      exclude_properties=False,
                      metadatas=None,
                      geom_type=False):
        """ This function is central for this test class. It creates
        a layer with two features, and associates a restriction area
        to it. """
        import transaction
        from sqlalchemy import Column, Table, types, ForeignKey, CheckConstraint
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry, WKTElement
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import LayerV1, RestrictionArea

        if self._tables is None:
            self._tables = []

        self.__class__._table_index += 1
        id = self.__class__._table_index

        engine = DBSession.c2c_rw_bind
        connection = engine.connect()

        if not self.metadata:
            self.metadata = declarative_base(bind=engine).metadata

        tablename = "table_{0:d}".format(id)

        table1 = Table("{0!s}_child".format(tablename),
                       self.metadata,
                       Column("id", types.Integer, primary_key=True),
                       Column("name", types.Unicode),
                       schema="public")
        if geom_type:
            table1.append_column(Column("geom", Geometry("POINT", srid=21781)))
        else:
            table1.append_column(Column("geom", Geometry(srid=21781)))
        self._tables.append(table1)

        table2 = Table(
            tablename,
            self.metadata,
            Column("id", types.Integer, primary_key=True),
            Column("child_id", types.Integer,
                   ForeignKey("public.{0!s}_child.id".format(tablename))),
            Column("name", types.Unicode),
            Column(
                "email", types.Unicode,
                CheckConstraint("""email ~* '^[A-Za-z0-9._%%-]
                                      +@[A-Za-z0-9.-]+[.][A-Za-z]+$'""",
                                name="proper_email")),
            Column("last_update_user", types.Unicode),
            Column("last_update_date", types.DateTime),
            schema="public")
        if geom_type:
            table2.append_column(Column("geom", Geometry("POINT", srid=21781)))
        else:
            table2.append_column(Column("geom", Geometry(srid=21781)))
        self._tables.append(table2)

        table1.drop(checkfirst=True)
        table2.drop(checkfirst=True)
        table1.create()
        table2.create()

        ins = table1.insert().values(name="c1é")
        c1_id = connection.execute(ins).inserted_primary_key[0]
        ins = table1.insert().values(name="c2é")
        c2_id = connection.execute(ins).inserted_primary_key[0]

        ins = table2.insert().values(child_id=c1_id,
                                     name="foo",
                                     geom=WKTElement("POINT(5 45)", 21781))
        connection.execute(ins)
        ins = table2.insert().values(child_id=c2_id,
                                     name="bar",
                                     geom=WKTElement("POINT(6 46)", 21781))
        connection.execute(ins)
        if attr_list:
            ins = table2.insert().values(child_id=c2_id,
                                         name="aaa,bbb,foo",
                                         geom=WKTElement("POINT(6 46)", 21781))
            connection.execute(ins)

        layer = LayerV1()
        layer.id = id
        layer.name = str(id)
        layer.geo_table = tablename
        layer.public = public
        layer.interface = [self.main]

        if exclude_properties:
            layer.exclude_properties = "name"

        if metadatas:
            layer.metadatas = metadatas

        DBSession.add(layer)

        if not public:
            ra = RestrictionArea()
            ra.name = "__test_ra"
            ra.layers = [layer]
            ra.roles = [self.role]
            ra.readwrite = True
            if not none_area:
                poly = "POLYGON((4 44, 4 46, 6 46, 6 44, 4 44))"
                ra.area = WKTElement(poly, srid=21781)
            DBSession.add(ra)

        transaction.commit()

        self.layer_ids.append(id)
        return id
Beispiel #7
0
def layertree_test_data(dbsession, transact):
    del transact

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

    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,
        'ogc_servers': [ogc_server]
    })