def restriction_area_test_data(dbsession, transact): del transact from c2cgeoportal_commons.models.main import LayerWMS, OGCServer, RestrictionArea, Role roles = [] for i in range(0, 4): roles.append(Role("secretary_" + str(i))) dbsession.add_all(roles) ogc_server = OGCServer(name="test_server") layers = [] for i in range(0, 4): layer = LayerWMS(name=f"layer_{i}", layer=f"layer_{i}", public=False) layer.ogc_server = ogc_server layers.append(layer) dbsession.add_all(layers) restrictionareas = [] for i in range(0, 4): restrictionarea = RestrictionArea(name=f"restrictionarea_{i}") restrictionarea.area = from_shape(box(485869.5728, 76443.1884, 837076.5648, 299941.7864), srid=21781) restrictionarea.description = f"description_{i}" restrictionarea.roles = [roles[i % 4], roles[(i + 2) % 4]] restrictionarea.layers = [layers[i % 4], layers[(i + 2) % 4]] dbsession.add(restrictionarea) restrictionareas.append(restrictionarea) dbsession.flush() yield { "layers": layers, "restriction_areas": restrictionareas, "roles": roles, }
def restriction_area_test_data(dbsession, transact): del transact from c2cgeoportal_commons.models.main import RestrictionArea, Role roles = [] for i in range(0, 4): roles.append(Role("secretary_" + str(i))) dbsession.add(roles[i]) restrictionareas = [] for i in range(0, 4): restrictionarea = RestrictionArea(name='restrictionarea_{}'.format(i)) restrictionarea.area = \ from_shape(box(485869.5728, 76443.1884, 837076.5648, 299941.7864), srid=21781) restrictionarea.description = 'description_{}'.format(i) restrictionarea.roles = [roles[i % 4], roles[(i + 2) % 4]] dbsession.add(restrictionarea) restrictionareas.append(restrictionarea) dbsession.flush() yield {'restriction_areas': restrictionareas, 'roles': roles}
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 geoalchemy2 import Geometry, WKTElement from sqlalchemy import CheckConstraint, Column, ForeignKey, Table, types from sqlalchemy.ext.declarative import declarative_base from c2cgeoportal_commons.models import DBSession from c2cgeoportal_commons.models.main import LayerWMS, OGCServer, 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) ogc_server = DBSession.query(OGCServer).filter( OGCServer.name == "__test_ogc_server").one() layer = LayerWMS() layer.id = id layer.name = str(id) layer.ogc_server = ogc_server 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
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_commons.models import DBSession from c2cgeoportal_commons.models.main import 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
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_commons.models import DBSession from c2cgeoportal_commons.models.main import 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