def setup_method(self, _):
        self.maxDiff = None

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import (
            Role,
            LayerWMS,
            RestrictionArea,
            Interface,
            OGCServer,
            OGCSERVER_TYPE_MAPSERVER,
            OGCSERVER_AUTH_STANDARD,
        )
        from c2cgeoportal_commons.models.static import User

        setup_db()
        create_default_ogcserver()

        ogcserver_jpeg = OGCServer(name="__test_ogc_server_jpeg")
        ogcserver_jpeg.url = mapserv_url
        ogcserver_jpeg.image_type = "image/jpeg"
        ogcserver_jpeg.type = OGCSERVER_TYPE_MAPSERVER
        ogcserver_jpeg.auth = OGCSERVER_AUTH_STANDARD

        ogcserver_png = OGCServer(name="__test_ogc_server_png")
        ogcserver_png.url = mapserv_url
        ogcserver_png.image_type = "image/png"
        ogcserver_png.type = OGCSERVER_TYPE_MAPSERVER
        ogcserver_png.auth = OGCSERVER_AUTH_STANDARD

        ogcserver_wfs1 = OGCServer(name="__test_ogc_server_wfs1")
        ogcserver_wfs1.url = mapserv_url
        ogcserver_wfs1.url_wfs = "config://srv"
        ogcserver_wfs1.image_type = "image/png"
        ogcserver_wfs1.type = OGCSERVER_TYPE_MAPSERVER
        ogcserver_wfs1.auth = OGCSERVER_AUTH_STANDARD

        ogcserver_wfs2 = OGCServer(name="__test_ogc_server_wfs2")
        ogcserver_wfs2.url = "config://srv"
        ogcserver_wfs2.url_wfs = mapserv_url
        ogcserver_wfs2.image_type = "image/png"
        ogcserver_wfs2.type = OGCSERVER_TYPE_MAPSERVER
        ogcserver_wfs2.auth = OGCSERVER_AUTH_STANDARD

        role = Role(name="__test_role", description="__test_role")
        user = User(username="******",
                    password="******",
                    settings_role=role,
                    roles=[role])

        main = Interface(name="main")

        layer1 = LayerWMS("__test_layer1", public=False)
        layer1.layer = "__test_private_layer1"
        layer1.ogc_server = ogcserver_jpeg
        layer1.interfaces = [main]

        layer2 = LayerWMS("__test_layer2", public=False)
        layer2.layer = "__test_private_layer2"
        layer2.ogc_server = ogcserver_png
        layer2.interfaces = [main]

        layer3 = LayerWMS("__test_layer3", public=False)
        layer3.layer = "__test_private_layer3"
        layer3.ogc_server = ogcserver_wfs1
        layer3.interfaces = [main]

        layer4 = LayerWMS("__test_layer4", public=False)
        layer4.layer = "__test_private_layer4"
        layer4.ogc_server = ogcserver_wfs2
        layer4.interfaces = [main]

        restricted_area = RestrictionArea("__test_ra", "",
                                          [layer1, layer2, layer3, layer4],
                                          [role])

        DBSession.add_all([user, restricted_area])
        transaction.commit()
Beispiel #2
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 geoalchemy2 import Geometry
        from sqlalchemy import Column, Table, func, types
        from sqlalchemy.ext.declarative import declarative_base

        from c2cgeoportal_commons.models import DBSession
        from c2cgeoportal_commons.models.main import (
            OGCSERVER_AUTH_GEOSERVER,
            OGCSERVER_TYPE_GEOSERVER,
            FullTextSearch,
            Functionality,
            Interface,
            LayerGroup,
            LayerWMS,
            OGCServer,
            RestrictionArea,
            Role,
            Theme,
        )
        from c2cgeoportal_commons.models.static import User

        setup_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="testpoint_unprotected",
                                          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()
    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 (
            OGCSERVER_AUTH_GEOSERVER,
            OGCSERVER_TYPE_GEOSERVER,
            Functionality,
            Interface,
            LayerWMS,
            OGCServer,
            RestrictionArea,
            Role,
        )
        from c2cgeoportal_commons.models.static import User

        setup_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

        DBSession.query(PointTest).delete()

        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()