def setup_method(self, _):
        import transaction

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Functionality, Role
        from c2cgeoportal_commons.models.static import User

        create_default_ogcserver()
        role1 = Role(name="__test_role1")
        user1 = User(username="******", password="******", settings_role=role1, roles=[role1])
        role2 = Role(name="__test_role2")
        user2 = User(username="******", password="******", settings_role=role2, roles=[role2])
        role3 = Role(name="__test_role3")
        role4 = Role(name="__test_role4")
        user3 = User(
            username="******", password="******", roles=[role3, role4], settings_role=role3
        )

        functionality1 = Functionality("__test_s", "db")
        functionality2 = Functionality("__test_a", "db1")
        functionality3 = Functionality("__test_a", "db2")
        functionality4 = Functionality("__test_b", "db")
        role2.functionalities = [functionality1, functionality2, functionality3]
        role3.functionalities = [functionality1, functionality2]
        role4.functionalities = [functionality2, functionality3, functionality4]

        DBSession.add_all([user1, user2, user3, role1, role2])
        transaction.commit()
    def setup_method(self, _):
        import transaction
        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role, Functionality
        from c2cgeoportal_commons.models.static import User

        create_default_ogcserver()
        role1 = Role(name="__test_role1")
        user1 = User(username="******",
                     password="******",
                     role=role1)
        role2 = Role(name="__test_role2")
        user2 = User(username="******",
                     password="******",
                     role=role2)

        functionality1 = Functionality("__test_s", "db")
        functionality2 = Functionality("__test_a", "db1")
        functionality3 = Functionality("__test_a", "db2")
        role2.functionalities = [
            functionality1, functionality2, functionality3
        ]

        DBSession.add_all([user1, user2, role1, role2])
        transaction.commit()
def functionality_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Functionality

    functionalities = []
    for i in range(0, 4):
        functionality = Functionality(name="functionality_{}".format(i),
                                      value="value_{}".format(i))
        functionality.description = "description_{}".format(i)
        dbsession.add(functionality)
        functionalities.append(functionality)

    dbsession.flush()

    yield {"functionalities": functionalities}
Esempio n. 4
0
def roles_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Role, Functionality, RestrictionArea
    from c2cgeoportal_commons.models.static import User

    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)

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

    roles = []
    for i in range(0, 23):
        role = Role('secretary_' + str(i))
        role.functionalities = [
            functionalities['default_basemap'][0],
            functionalities['location'][0],
            functionalities['location'][1]]
        role.restrictionareas = [
            restrictionareas[0],
            restrictionareas[1]]
        role.extent = from_shape(box(485869.5728, 76443.1884, 837076.5648, 299941.7864),
                                 srid=21781)
        dbsession.add(role)
        roles.append(role)

    # Users roles must not be broken with role name changes
    users = []
    for i in range(0, 23):
        user = User("babar_" + str(i),
                    email='mail' + str(i),
                    settings_role=roles[i],
                    roles=[roles[i]])
        user.password = '******'
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {
        'functionalities': functionalities,
        'restrictionareas': restrictionareas,
        'users': users,
        'roles': roles
    }
Esempio n. 5
0
def fill_tech_user_functionality(name, functionalities):
    from c2cgeoportal_commons.models import DBSession
    from c2cgeoportal_commons.models.main import Functionality, Role

    role = DBSession.query(Role).filter_by(name=name).one()
    role.functionalities = [Functionality(name, value) for name, value in functionalities]
    DBSession.add(role)
    transaction.commit()
    caching.invalidate_region()
def functionality_test_data(dbsession, transact, settings):
    del transact

    from c2cgeoportal_commons.models.main import Functionality

    functionalities = []
    for i in range(0, 4):
        functionality = Functionality(
            settings["admin_interface"]["available_functionalities"][i]["name"],
            value=f"value_{i}",
        )
        functionality.description = f"description_{i}"
        dbsession.add(functionality)
        functionalities.append(functionality)

    dbsession.flush()

    yield {"functionalities": functionalities}
Esempio n. 7
0
def roles_test_data(dbsession, transact):
    del transact

    from c2cgeoportal_commons.models.main import Functionality, RestrictionArea, Role
    from c2cgeoportal_commons.models.static import User

    # Note that "default_basemap" is not relevant for roles
    functionalities = {}
    for name in ("default_basemap", "default_theme", "print_template"):
        functionalities[name] = []
        for v in range(0, 4):
            functionality = Functionality(name=name, value=f"value_{v}")
            dbsession.add(functionality)
            functionalities[name].append(functionality)

    restrictionareas = []
    for i in range(0, 5):
        restrictionarea = RestrictionArea(name=f"restrictionarea_{i}")
        dbsession.add(restrictionarea)
        restrictionareas.append(restrictionarea)

    roles = []
    for i in range(0, 23):
        role = Role("secretary_" + str(i))
        role.functionalities = [
            functionalities["default_theme"][0],
            functionalities["print_template"][0],
            functionalities["print_template"][1],
        ]
        role.restrictionareas = [restrictionareas[0], restrictionareas[1]]
        role.extent = from_shape(box(485869.5728, 76443.1884, 837076.5648,
                                     299941.7864),
                                 srid=21781)
        dbsession.add(role)
        roles.append(role)

    # Users roles must not be broken with role name changes
    users = []
    for i in range(0, 23):
        user = User("babar_" + str(i),
                    email="mail" + str(i),
                    settings_role=roles[i],
                    roles=[roles[i]])
        user.password = "******"
        user.is_password_changed = i % 2 == 1
        users.append(user)
        dbsession.add(user)

    dbsession.flush()

    yield {
        "functionalities": functionalities,
        "restrictionareas": restrictionareas,
        "users": users,
        "roles": roles,
    }
Esempio n. 8
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. 9
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. 10
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
    }
Esempio n. 11
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()
    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 Role, LayerWMS, RestrictionArea, \
            Functionality, Interface, OGCServer, OGCSERVER_TYPE_GEOSERVER, OGCSERVER_AUTH_GEOSERVER
        from c2cgeoportal_commons.models.static import User

        cleanup_db()

        ogc_server_internal, _ = create_default_ogcserver()
        ogcserver_geoserver = OGCServer(name="__test_ogc_server_geoserver")
        ogcserver_geoserver.url = mapserv_url
        ogcserver_geoserver.type = OGCSERVER_TYPE_GEOSERVER
        ogcserver_geoserver.auth = OGCSERVER_AUTH_GEOSERVER

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

        geom = WKTElement("POINT(599910 199955)", srid=21781)
        p1 = PointTest(geom=geom, name="foo", city="Lausanne", country="Swiss")
        geom = WKTElement("POINT(599910 200045)", srid=21781)
        p2 = PointTest(geom=geom,
                       name="bar",
                       city="Chambéry",
                       country="France")
        geom = WKTElement("POINT(600090 200045)", srid=21781)
        p3 = PointTest(geom=geom, name="éàè", city="Paris", country="France")
        geom = WKTElement("POINT(600090 199955)", srid=21781)
        p4 = PointTest(geom=geom, name="123", city="Londre", country="UK")

        pt1 = Functionality(name="print_template",
                            value="1 Wohlen A4 portrait")
        pt2 = Functionality(name="print_template",
                            value="2 Wohlen A3 landscape")
        role1 = Role(name="__test_role1",
                     description="__test_role1",
                     functionalities=[pt1, pt2])
        user1 = User(username="******",
                     password="******",
                     roles=[role1])
        user1.email = "Tarenpion"

        role2 = Role(name="__test_role2",
                     description="__test_role2",
                     functionalities=[pt1, pt2])
        user2 = User(username="******",
                     password="******",
                     settings_role=role2,
                     roles=[role2])
        user2.email = "Tarenpion"

        role3 = Role(name="__test_role3",
                     description="__test_role3",
                     functionalities=[pt1, pt2])
        user3 = User(username="******",
                     password="******",
                     settings_role=role3,
                     roles=[role3])

        role4 = Role(name="__test_role4",
                     description="__test_role4",
                     functionalities=[pt1, pt2])
        role5 = Role(name="__test_role5",
                     description="__test_role5",
                     functionalities=[pt1, pt2])
        user4 = User(username="******",
                     password="******",
                     settings_role=role3,
                     roles=[role4, role5])

        main = Interface(name="main")

        layer2 = LayerWMS("testpoint_protected", public=False)
        layer2.layer = "testpoint_protected"
        layer2.ogc_server = ogc_server_internal
        layer2.interfaces = [main]

        layer3 = LayerWMS("testpoint_protected_query_with_collect",
                          public=False)
        layer3.layer = "testpoint_protected_query_with_collect"
        layer3.ogc_server = ogc_server_internal
        layer3.interfaces = [main]

        area = "POLYGON((599900 200030, 599900 200050, 600100 200050, 600100 200030, 599900 200030))"
        area = WKTElement(area, srid=21781)
        restricted_area1 = RestrictionArea("__test_ra1", "", [layer2, layer3],
                                           [role1], area)

        area = "POLYGON((599900 200000, 599900 200020, 600100 200020, 600100 200000, 599900 200000))"
        area = WKTElement(area, srid=21781)
        restricted_area2 = RestrictionArea("__test_ra2", "", [layer2, layer3],
                                           [role2, role3], area)

        area = "POLYGON((599905 200043, 599905 200047, 600095 200047, 600095 200043, 599905 200043))"
        area = WKTElement(area, srid=21781)
        restricted_area3 = RestrictionArea("__test_ra3",
                                           "", [layer3], [role3],
                                           area,
                                           readwrite=True)

        area = "POLYGON((599909 199954, 599911 199954, 599911 199956, 599909 199956, 599909 199954))"
        area = WKTElement(area, srid=21781)
        restricted_area4 = RestrictionArea("__test_ra4",
                                           "", [layer2], [role4],
                                           area,
                                           readwrite=True)

        area = "POLYGON((599909 200044, 599911 200044, 599911 200046, 599909 200046, 599909 200044))"
        area = WKTElement(area, srid=21781)
        restricted_area5 = RestrictionArea("__test_ra5",
                                           "", [layer2], [role5],
                                           area,
                                           readwrite=True)

        DBSession.add_all([
            p1,
            p2,
            p3,
            p4,
            user1,
            user2,
            user3,
            user4,
            role1,
            role2,
            role3,
            ogcserver_geoserver,
            restricted_area1,
            restricted_area2,
            restricted_area3,
            restricted_area4,
            restricted_area5,
        ])
        DBSession.flush()

        self.id_lausanne = p1.id
        self.id_paris = p3.id
        self.ogc_server_id = ogc_server_internal.id
        self.user1_id = user1.id
        self.user2_id = user2.id
        self.user3_id = user3.id

        transaction.commit()
Esempio n. 13
0
    def setup_method(self, _):
        # Always see the diff
        # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff
        self.maxDiff = None  # pylint: disable=invalid-name
        self._tables = []

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import Role, \
            RestrictionArea, Theme, LayerGroup, Functionality, Interface, \
            LayerWMS, OGCServer, FullTextSearch, OGCSERVER_TYPE_GEOSERVER, OGCSERVER_AUTH_GEOSERVER
        from c2cgeoportal_commons.models.static import User
        from sqlalchemy import Column, Table, types, func
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry

        cleanup_db()

        role1 = Role(name="__test_role1")
        user1 = User(username="******",
                     password="******",
                     settings_role=role1,
                     roles=[role1])
        user1.email = "*****@*****.**"

        role2 = Role(name="__test_role2",
                     extent=WKTElement("POLYGON((1 2, 1 4, 3 4, 3 2, 1 2))",
                                       srid=21781))
        user2 = User(username="******",
                     password="******",
                     settings_role=role2,
                     roles=[role2])

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

        engine = DBSession.c2c_rw_bind
        engine.connect()

        a_geo_table = Table("a_geo_table",
                            declarative_base(bind=engine).metadata,
                            Column("id", types.Integer, primary_key=True),
                            Column("geom", Geometry("POINT", srid=21781)),
                            schema="geodata")

        self._tables = [a_geo_table]
        a_geo_table.drop(checkfirst=True)
        a_geo_table.create()

        ogcserver = create_default_ogcserver()

        private_layer_edit = LayerWMS(name="__test_private_layer_edit",
                                      public=False)
        private_layer_edit.layer = "__test_private_layer"
        private_layer_edit.geo_table = "a_schema.a_geo_table"
        private_layer_edit.interfaces = [main, mobile]
        private_layer_edit.ogc_server = ogcserver

        public_layer2 = LayerWMS(name="__test_public_layer",
                                 layer="__test_public_layer_bis",
                                 public=True)
        public_layer2.interfaces = [main, mobile]
        public_layer2.ogc_server = ogcserver

        private_layer = LayerWMS(name="__test_private_layer",
                                 layer="__test_private_layer_bis",
                                 public=False)
        private_layer.interfaces = [main, mobile]
        private_layer.ogc_server = ogcserver

        interface_not_in_mapfile = Interface(name="interface_not_in_mapfile")
        public_layer_not_in_mapfile = LayerWMS(
            name="__test_public_layer_not_in_mapfile",
            layer="__test_public_layer_not_in_mapfile",
            public=True)
        public_layer_not_in_mapfile.interfaces = [interface_not_in_mapfile]
        public_layer_not_in_mapfile.ogc_server = ogcserver

        interface_notmapfile = Interface(name="interface_notmapfile")
        ogcserver_notmapfile = OGCServer(name="__test_ogc_server_notmapfile")
        ogcserver_notmapfile.url = mapserv_url + "?map=not_a_mapfile"
        public_layer_not_mapfile = LayerWMS(
            name="__test_public_layer_notmapfile",
            layer="__test_public_layer_notmapfile",
            public=True)
        public_layer_not_mapfile.interfaces = [interface_notmapfile]
        public_layer_not_mapfile.ogc_server = ogcserver_notmapfile

        interface_geoserver = Interface(name="interface_geoserver")
        ogcserver_geoserver = OGCServer(name="__test_ogc_server_geoserver")
        ogcserver_geoserver.url = mapserv_url
        ogcserver_geoserver.type = OGCSERVER_TYPE_GEOSERVER
        ogcserver_geoserver.auth = OGCSERVER_AUTH_GEOSERVER
        public_layer_geoserver = LayerWMS(
            name="__test_public_layer_geoserver",
            layer="__test_public_layer_geoserver",
            public=True)
        public_layer_geoserver.interfaces = [interface_geoserver]
        public_layer_geoserver.ogc_server = ogcserver_geoserver

        interface_no_layers = Interface(name="interface_no_layers")
        public_layer_no_layers = LayerWMS(name="__test_public_layer_no_layers",
                                          public=True)
        public_layer_no_layers.interfaces = [interface_no_layers]
        public_layer_no_layers.ogc_server = ogcserver

        group = LayerGroup(name="__test_layer_group")
        group.children = [
            private_layer_edit, public_layer2, public_layer_not_in_mapfile,
            public_layer_not_mapfile, public_layer_geoserver,
            public_layer_no_layers, private_layer
        ]
        theme = Theme(name="__test_theme")
        theme.children = [group]
        theme.interfaces = [
            main, interface_not_in_mapfile, interface_notmapfile,
            interface_geoserver, interface_no_layers
        ]

        functionality1 = Functionality(name="test_name", value="test_value_1")
        functionality2 = Functionality(name="test_name", value="test_value_2")
        theme.functionalities = [functionality1, functionality2]

        poly = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))"

        area = WKTElement(poly, srid=21781)
        RestrictionArea(name="__test_ra1",
                        description="",
                        layers=[private_layer_edit, private_layer],
                        roles=[role1],
                        area=area)

        area = WKTElement(poly, srid=21781)
        RestrictionArea(name="__test_ra2",
                        description="",
                        layers=[private_layer_edit, private_layer],
                        roles=[role2],
                        area=area,
                        readwrite=True)

        entry1 = FullTextSearch()
        entry1.label = "label1"
        entry1.layer_name = "layer1"
        entry1.ts = func.to_tsvector("french", "soleil travail")
        entry1.the_geom = WKTElement("POINT(-90 -45)", 21781)
        entry1.public = True

        entry2 = FullTextSearch()
        entry2.label = "label1"
        entry2.layer_name = "layer1"
        entry2.ts = func.to_tsvector("french", "soleil travail")
        entry2.the_geom = WKTElement("POINT(-90 -45)", 21781)
        entry2.public = True

        entry3 = FullTextSearch()
        entry3.label = "label1"
        entry3.layer_name = None
        entry3.ts = func.to_tsvector("french", "soleil travail")
        entry3.the_geom = WKTElement("POINT(-90 -45)", 21781)
        entry3.public = True

        DBSession.add_all([user1, user2, theme, entry1, entry2, entry3])
        DBSession.flush()

        self.role1_id = role1.id

        transaction.commit()
Esempio n. 14
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,
    }