Пример #1
0
    def _create_layer(
            self, public=False, none_area=False, attr_list=False,
            exclude_properties=False, metadatas=None):
        """ This function is central for this test class. It creates
        a layer with two features, and associates a restriction area
        to it. """
        import transaction
        import sqlahelper
        from sqlalchemy import Column, Table, types, ForeignKey
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry, WKTElement
        from c2cgeoportal.models import DBSession, management, LayerV1, RestrictionArea

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

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

        engine = sqlahelper.get_engine()
        connection = engine.connect()

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

        tablename = "table_%d" % id

        table1 = Table(
            "%s_child" % tablename, self.metadata,
            Column("id", types.Integer, primary_key=True),
            Column("name", types.Unicode),
            schema="public"
        )
        self._tables.append(table1)
        table2 = Table(
            tablename, self.metadata,
            Column("id", types.Integer, primary_key=True),
            Column("child_id", types.Integer,
                   ForeignKey("public.%s_child.id" % tablename)),
            Column("name", types.Unicode),
            Column("geom", Geometry("POINT", srid=21781, management=management)),
            schema="public"
        )
        self._tables.append(table2)

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

        ins = table1.insert().values(name=u"c1é")
        c1_id = connection.execute(ins).inserted_primary_key[0]
        ins = table1.insert().values(name=u"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 = u"__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
Пример #2
0
    def _create_layer(
            self, public=False, none_area=False, attr_list=False,
            exclude_properties=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
        import sqlahelper
        from sqlalchemy import Column, Table, types, ForeignKey
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry, WKTElement
        from c2cgeoportal.models import DBSession, management, LayerV1, RestrictionArea

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

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

        engine = sqlahelper.get_engine()

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

        tablename = "table_%d" % id

        table = Table(
            '%s_child' % tablename, self.metadata,
            Column('id', types.Integer, primary_key=True),
            Column('name', types.Unicode),
            schema='public'
        )
        table.create()
        self._tables.append(table)

        ins = table.insert().values(name=u'c1é')
        c1_id = engine.connect().execute(ins).inserted_primary_key[0]
        ins = table.insert().values(name=u'c2é')
        c2_id = engine.connect().execute(ins).inserted_primary_key[0]

        table = Table(
            tablename, self.metadata,
            Column('id', types.Integer, primary_key=True),
            Column('child_id', types.Integer,
                   ForeignKey('public.%s_child.id' % tablename)),
            Column('name', types.Unicode),
            Column('geom', Geometry("POINT", srid=21781, management=management)),
            schema='public'
        )
        table.create()
        self._tables.append(table)

        ins = table.insert().values(
            child_id=c1_id,
            name='foo',
            geom=WKTElement('POINT(5 45)', 21781)
        )
        engine.connect().execute(ins).inserted_primary_key[0]
        ins = table.insert().values(
            child_id=c2_id,
            name='bar',
            geom=WKTElement('POINT(6 46)', 21781)
        )
        engine.connect().execute(ins).inserted_primary_key[0]
        if attr_list:
            ins = table.insert().values(
                child_id=c2_id,
                name='aaa,bbb,foo',
                geom=WKTElement('POINT(6 46)', 21781)
            )
            engine.connect().execute(ins).inserted_primary_key[0]

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

        if exclude_properties:
            layer.exclude_properties = 'name'

        DBSession.add(layer)

        if not public:
            ra = RestrictionArea()
            ra.name = u'__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
    def _create_layer(self, 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
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry
        from c2cgeoportal.models import DBSession, RestrictionArea, LayerWMS

        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 = "geo_table_{0:d}".format(id)
        schemaname = "geodata"

        table1 = Table(
            "{0!s}_child".format(tablename), self.metadata,
            Column("id", types.Integer, primary_key=True),
            Column("name", types.Unicode),
            schema=schemaname
        )

        self._tables.append(table1)

        table2 = Table(
            tablename, self.metadata,
            Column("id", types.Integer, primary_key=True),
            Column("child_id", types.Integer,
                   ForeignKey("{0!s}.{1!s}_child.id".format(schemaname, tablename))),
            Column("name", types.Unicode, nullable=False),
            Column("deleted", types.Boolean),
            Column("last_update_user", types.Unicode),
            Column("last_update_date", types.DateTime),
            Column("date", types.Date),
            Column("start_time", types.Time),
            # Column("interval", Interval()),
            Column("short_name1", types.String, nullable=True),
            Column("short_name2", types.String(50), nullable=True),
            Column("short_number", types.Integer, nullable=True),
            Column("double_number", types.Float(precision=4)),
            Column("large_binary", types.LargeBinary(length=60), nullable=True),
            Column("value", types.Enum("one", "two", "three", name="an_enum_value")),
            Column("numeric", types.Numeric(precision=5, scale=2), nullable=True),
            Column("numeric2", types.Numeric(), nullable=True),
            schema=schemaname
        )
        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)

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

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

        layer = LayerWMS(name="test_WMS_1", public=True)
        layer.layer = "test_wms"
        layer.id = id
        layer.geo_table = "{0!s}.{1!s}".format(schemaname, tablename)
        layer.interfaces = [self.main]
        layer.ogc_server = self.ogc_server

        if exclude_properties:
            layer.exclude_properties = "name"

        if metadatas:
            layer.metadatas = metadatas

        DBSession.add(self.layer_group_1)
        self.layer_group_1.children = self.layer_group_1.children + [layer]

        DBSession.add(self.layer_group_1)

        ra = RestrictionArea()
        ra.name = "__test_ra"
        ra.layers = [layer]
        ra.roles = [self.role]
        ra.readwrite = True
        DBSession.add(ra)

        transaction.commit()

        self.layer_ids.append(id)
        return id
Пример #4
0
    def _create_layer(self,
                      public=False,
                      none_area=False,
                      attr_list=False,
                      exclude_properties=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
        import sqlahelper
        from sqlalchemy import func
        from sqlalchemy import Column, Table, types, ForeignKey
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy import (GeometryDDL, GeometryExtensionColumn, Point,
                                WKTSpatialElement)
        from c2cgeoportal.models import DBSession, Layer, RestrictionArea

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

        engine = sqlahelper.get_engine()

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

        tablename = "table_%d" % id

        table = Table('%s_child' % tablename,
                      self.metadata,
                      Column('id', types.Integer, primary_key=True),
                      Column('name', types.Unicode),
                      schema='public')
        table.create()

        ins = table.insert().values(name=u'c1é')
        c1_id = engine.connect().execute(ins).inserted_primary_key[0]
        ins = table.insert().values(name=u'c2é')
        c2_id = engine.connect().execute(ins).inserted_primary_key[0]

        table = Table(tablename,
                      self.metadata,
                      Column('id', types.Integer, primary_key=True),
                      Column('child_id', types.Integer,
                             ForeignKey('public.%s_child.id' % tablename)),
                      Column('name', types.Unicode),
                      GeometryExtensionColumn('geom', Point(srid=21781)),
                      schema='public')
        GeometryDDL(table)
        table.create()

        ins = table.insert().values(child_id=c1_id,
                                    name='foo',
                                    geom=func.ST_GeomFromText(
                                        'POINT(5 45)', 21781))
        engine.connect().execute(ins).inserted_primary_key[0]
        ins = table.insert().values(child_id=c2_id,
                                    name='bar',
                                    geom=func.ST_GeomFromText(
                                        'POINT(6 46)', 21781))
        engine.connect().execute(ins).inserted_primary_key[0]
        if attr_list:
            ins = table.insert().values(child_id=c2_id,
                                        name='aaa,bbb,foo',
                                        geom=func.ST_GeomFromText(
                                            'POINT(6 46)', 21781))
            engine.connect().execute(ins).inserted_primary_key[0]

        layer = Layer()
        layer.id = id
        layer.geoTable = tablename
        layer.public = public

        if exclude_properties:
            layer.excludeProperties = 'name'

        DBSession.add(layer)

        if not public:
            ra = RestrictionArea()
            ra.name = u'__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 = WKTSpatialElement(poly, srid=21781)
            DBSession.add(ra)

        self.layer_ids.append(self.__class__._table_index)

        transaction.commit()

        return id
Пример #5
0
    def _create_layer(self, public=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
        import sqlahelper
        from sqlalchemy import func
        from sqlalchemy import Column, Table, types, ForeignKey
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy import (GeometryDDL, GeometryExtensionColumn,
                                Point, WKTSpatialElement)
        from c2cgeoportal.models import DBSession, Layer, RestrictionArea

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

        engine = sqlahelper.get_engine()

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

        tablename = "table_%d" % id

        table = Table('%s_child' % tablename, self.metadata,
                      Column('id', types.Integer, primary_key=True),
                      Column('name', types.Unicode),
                      schema='public'
                      )
        table.create()

        ins = table.insert().values(name=u'c1é')
        c1_id = engine.connect().execute(ins).inserted_primary_key[0]
        ins = table.insert().values(name=u'c2é')
        c2_id = engine.connect().execute(ins).inserted_primary_key[0]

        table = Table(tablename, self.metadata,
                Column('id', types.Integer, primary_key=True),
                Column('child_id', types.Integer,
                       ForeignKey('public.%s_child.id' % tablename)),
                Column('name', types.Unicode),
                GeometryExtensionColumn('geom', Point(srid=21781)),
                schema='public')
        GeometryDDL(table)
        table.create()

        ins = table.insert().values(
                child_id=c1_id,
                name='foo',
                geom=func.ST_GeomFromText('POINT(5 45)', 21781))
        f1_id = engine.connect().execute(ins).inserted_primary_key[0]  # NOQA
        ins = table.insert().values(
                child_id=c2_id,
                name='bar',
                geom=func.ST_GeomFromText('POINT(6 46)', 21781))
        f2_id = engine.connect().execute(ins).inserted_primary_key[0]  # NOQA

        layer = Layer()
        layer.id = id
        layer.geoTable = tablename
        layer.public = public
        DBSession.add(layer)

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

        self.layer_ids.append(self.__class__._table_index)

        transaction.commit()

        return id
Пример #6
0
    def _create_layer(self,
                      public=False,
                      none_area=False,
                      attr_list=False,
                      exclude_properties=False,
                      metadatas=None):
        """ This function is central for this test class. It creates
        a layer with two features, and associates a restriction area
        to it. """
        import transaction
        import sqlahelper
        from sqlalchemy import Column, Table, types, ForeignKey
        from sqlalchemy.ext.declarative import declarative_base
        from geoalchemy2 import Geometry, WKTElement
        from c2cgeoportal.models import DBSession, management, LayerV1, RestrictionArea

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

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

        engine = sqlahelper.get_engine()
        connection = engine.connect()

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

        tablename = "table_%d" % id

        table1 = Table("%s_child" % tablename,
                       self.metadata,
                       Column("id", types.Integer, primary_key=True),
                       Column("name", types.Unicode),
                       schema="public")
        self._tables.append(table1)
        table2 = Table(tablename,
                       self.metadata,
                       Column("id", types.Integer, primary_key=True),
                       Column("child_id", types.Integer,
                              ForeignKey("public.%s_child.id" % tablename)),
                       Column("name", types.Unicode),
                       Column(
                           "geom",
                           Geometry("POINT", srid=21781,
                                    management=management)),
                       schema="public")
        self._tables.append(table2)

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

        ins = table1.insert().values(name=u"c1é")
        c1_id = connection.execute(ins).inserted_primary_key[0]
        ins = table1.insert().values(name=u"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 = u"__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