def setUp(self): from c2cgeoportal.models import DBSession, User, Role, Layer, \ RestrictionArea, Theme, LayerGroup role1 = Role(name=u'__test_role1') user1 = User(username=u'__test_user1', password=u'__test_user1', role=role1) role2 = Role(name=u'__test_role2', extent=WKTSpatialElement( "POLYGON((1 2, 1 4, 3 4, 3 2, 1 2))", srid=21781)) user2 = User(username=u'__test_user2', password=u'__test_user2', role=role2) public_layer = Layer(name=u'__test_public_layer', order=40, public=True) public_layer.isChecked = False private_layer = Layer(name=u'__test_private_layer', order=40, public=False) private_layer.geoTable = 'a_schema.a_geo_table' layer_in_group = Layer(name=u'__test_layer_in_group') layer_group = LayerGroup(name=u'__test_layer_group') layer_group.children = [layer_in_group] layer_wmsgroup = Layer(name=u'test_wmsfeaturesgroup') layer_wmsgroup.isChecked = False theme = Theme(name=u'__test_theme') theme.children = [ public_layer, private_layer, layer_group, layer_wmsgroup ] poly = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))" area = WKTSpatialElement(poly, srid=21781) RestrictionArea(name=u'__test_ra1', description=u'', layers=[private_layer], roles=[role1], area=area) area = WKTSpatialElement(poly, srid=21781) RestrictionArea(name=u'__test_ra2', description=u'', layers=[private_layer], roles=[role2], area=area, readwrite=True) DBSession.add_all([user1, user2, public_layer, private_layer]) transaction.commit()
def setUp(self): from c2cgeoportal.models import User, Role, Layer, RestrictionArea, \ Functionality, DBSession TestPoint.__table__.create(bind=DBSession.bind, checkfirst=True) geom = WKTSpatialElement("MULTIPOINT((-90 -45))", srid=21781) p1 = TestPoint(the_geom=geom, name=u'foo', city=u'Lausanne', country=u'Swiss') geom = WKTSpatialElement("MULTIPOINT((-90 45))", srid=21781) p2 = TestPoint(the_geom=geom, name=u'bar', city=u'Chambéry', country=u'France') geom = WKTSpatialElement("MULTIPOINT((90 45))", srid=21781) p3 = TestPoint(the_geom=geom, name=u'éàè', city="Paris", country=u'France') geom = WKTSpatialElement("MULTIPOINT((90 -45))", srid=21781) p4 = TestPoint(the_geom=geom, name=u'123', city='Londre', country=u'UK') pt1 = Functionality(name=u'print_template', value=u'1 Wohlen A4 portrait') pt2 = Functionality(name=u'print_template', value=u'2 Wohlen A3 landscape') user1 = User(username=u'__test_user1', password=u'__test_user1') role1 = Role(name=u'__test_role1', description=u'__test_role1', functionalities=[pt1, pt2]) user1.role = role1 user1.email = u'Tarenpion' user2 = User(username=u'__test_user2', password=u'__test_user2') role2 = Role(name=u'__test_role2', description=u'__test_role2', functionalities=[pt1, pt2]) user2.role = role2 user2.email = u'Tarenpion' user3 = User(username=u'__test_user3', password=u'__test_user3') role3 = Role(name=u'__test_role3', description=u'__test_role3', functionalities=[pt1, pt2]) user3.role = role3 user3.email = u'Tarenpion' layer2 = Layer(u'testpoint_protected', 400, public=False) layer3 = Layer(u'testpoint_protected_query_with_collect', public=False) area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))" area = WKTSpatialElement(area, srid=21781) restricted_area1 = RestrictionArea(u'__test_ra1', u'', [layer2, layer3], [role1], area) area = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))" area = WKTSpatialElement(area, srid=21781) restricted_area2 = RestrictionArea(u'__test_ra2', u'', [layer2, layer3], [role2, role3], area) area = "POLYGON((-95 43, -95 47, 95 47, 95 43, -95 43))" area = WKTSpatialElement(area, srid=21781) restricted_area3 = RestrictionArea(u'__test_ra3', u'', [layer3], [role3], area, readwrite=True) DBSession.add_all([ p1, p2, p3, p4, user1, user2, user3, restricted_area1, restricted_area2, restricted_area3 ]) DBSession.flush() self.id_lausanne = p1.id self.id_paris = p3.id transaction.commit()
def setup_method(self, _): from c2cgeoportal.models import User, Role, LayerWMS, RestrictionArea, \ Interface, DBSession ogc_server_internal, _ = create_default_ogcserver() user1 = User(username="******", password="******") role1 = Role(name="__test_role1", description="__test_role1") user1.role_name = role1.name user1.email = "Tarenpion" main = Interface(name="main") layer1 = LayerWMS("testpoint_group_name", public=False) layer1.layer = "testpoint_group" layer1.ogc_server = ogc_server_internal layer1.interfaces = [main] layer2 = LayerWMS("testpoint_protected_2_name", public=False) layer2.layer = "testpoint_protected_2" layer2.ogc_server = ogc_server_internal layer2.interfaces = [main] area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))" area = WKTElement(area, srid=21781) restricted_area1 = RestrictionArea("__test_ra1", "", [layer1, layer2], [role1], area) DBSession.add_all([user1, role1, layer1, layer2, restricted_area1]) DBSession.flush() transaction.commit()
def setUp(self): # noqa from c2cgeoportal.models import User, Role, LayerV1, RestrictionArea, \ Interface, DBSession create_default_ogcserver() user1 = User(username=u"__test_user1", password=u"__test_user1") role1 = Role(name=u"__test_role1", description=u"__test_role1") user1.role_name = role1.name user1.email = u"Tarenpion" main = Interface(name=u"main") layer1 = LayerV1(u"testpoint_group", public=False) layer1.interfaces = [main] layer2 = LayerV1(u"testpoint_protected_2", public=False) layer2.interfaces = [main] area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))" area = WKTElement(area, srid=21781) restricted_area1 = RestrictionArea(u"__test_ra1", u"", [layer1, layer2], [role1], area) DBSession.add_all([user1, role1, layer1, layer2, restricted_area1]) DBSession.flush() transaction.commit()
def setUp(self): # noqa from c2cgeoportal.models import User, Role, LayerV1, RestrictionArea, \ Interface, DBSession user1 = User(username=u"__test_user1", password=u"__test_user1") role1 = Role(name=u"__test_role1", description=u"__test_role1") user1.role_name = role1.name user1.email = u"Tarenpion" user2 = User(username=u"__test_user2", password=u"__test_user2") role2 = Role(name=u"__test_role2", description=u"__test_role2") user2.role_name = role2.name user2.email = u"Tarenpion" main = Interface(name=u"main") layer1 = LayerV1(u"layer_1", public=False) layer1.interfaces = [main] layer2 = LayerV1(u"layer_2", public=False) layer2.interfaces = [main] layer3 = LayerV1(u"layer_3", public=False) layer3.interfaces = [main] area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))" area = WKTElement(area, srid=21781) restricted_area1 = RestrictionArea(u"__test_ra1", u"", [layer1, layer2], [role1], area, readwrite=True) area = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))" area = WKTElement(area, srid=21781) restricted_area2 = RestrictionArea(u"__test_ra2", u"", [layer1, layer2, layer3], [role2], area) DBSession.add_all( [user1, user2, role1, role2, restricted_area1, restricted_area2]) DBSession.flush() transaction.commit()
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
def setUp(self): # noqa self.maxDiff = None from c2cgeoportal.models import User, Role, LayerV1, RestrictionArea, \ Functionality, Interface, DBSession, management, OGCServer, \ OGCSERVER_TYPE_GEOSERVER, OGCSERVER_AUTH_GEOSERVER if management: TestPoint.__table__.c.the_geom.type.management = True create_default_ogcserver() ogcserver_geoserver = OGCServer(name="__test_ogc_server_geoserver") ogcserver_geoserver.url = mapserv ogcserver_geoserver.type = OGCSERVER_TYPE_GEOSERVER ogcserver_geoserver.auth = OGCSERVER_AUTH_GEOSERVER TestPoint.__table__.create(bind=DBSession.bind, checkfirst=True) geom = WKTElement("MULTIPOINT((-90 -45))", srid=21781) p1 = TestPoint(the_geom=geom, name=u"foo", city=u"Lausanne", country=u"Swiss") geom = WKTElement("MULTIPOINT((-90 45))", srid=21781) p2 = TestPoint(the_geom=geom, name=u"bar", city=u"Chambéry", country=u"France") geom = WKTElement("MULTIPOINT((90 45))", srid=21781) p3 = TestPoint(the_geom=geom, name=u"éàè", city="Paris", country=u"France") geom = WKTElement("MULTIPOINT((90 -45))", srid=21781) p4 = TestPoint(the_geom=geom, name=u"123", city="Londre", country=u"UK") pt1 = Functionality(name=u"print_template", value=u"1 Wohlen A4 portrait") pt2 = Functionality(name=u"print_template", value=u"2 Wohlen A3 landscape") user1 = User(username=u"__test_user1", password=u"__test_user1") role1 = Role(name=u"__test_role1", description=u"__test_role1", functionalities=[pt1, pt2]) user1.role_name = role1.name user1.email = u"Tarenpion" user2 = User(username=u"__test_user2", password=u"__test_user2") role2 = Role(name=u"__test_role2", description=u"__test_role2", functionalities=[pt1, pt2]) user2.role_name = role2.name user2.email = u"Tarenpion" user3 = User(username=u"__test_user3", password=u"__test_user3") role3 = Role(name=u"__test_role3", description=u"__test_role3", functionalities=[pt1, pt2]) user3.role_name = role3.name user3.email = u"Tarenpion" main = Interface(name=u"main") layer2 = LayerV1(u"testpoint_protected", public=False) layer2.interfaces = [main] layer3 = LayerV1(u"testpoint_protected_query_with_collect", public=False) layer3.interfaces = [main] area = "POLYGON((-100 30, -100 50, 100 50, 100 30, -100 30))" area = WKTElement(area, srid=21781) restricted_area1 = RestrictionArea(u"__test_ra1", u"", [layer2, layer3], [role1], area) area = "POLYGON((-100 0, -100 20, 100 20, 100 0, -100 0))" area = WKTElement(area, srid=21781) restricted_area2 = RestrictionArea(u"__test_ra2", u"", [layer2, layer3], [role2, role3], area) area = "POLYGON((-95 43, -95 47, 95 47, 95 43, -95 43))" area = WKTElement(area, srid=21781) restricted_area3 = RestrictionArea(u"__test_ra3", u"", [layer3], [role3], area, readwrite=True) DBSession.add_all([ p1, p2, p3, p4, user1, user2, user3, role1, role2, role3, restricted_area1, restricted_area2, restricted_area3, ogcserver_geoserver ]) DBSession.flush() self.id_lausanne = p1.id self.id_paris = p3.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.models import User, Role, LayerWMS, RestrictionArea, \ Functionality, Interface, DBSession, OGCServer, \ OGCSERVER_TYPE_GEOSERVER, OGCSERVER_AUTH_GEOSERVER 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") user1 = User(username="******", password="******") role1 = Role(name="__test_role1", description="__test_role1", functionalities=[pt1, pt2]) user1.role_name = role1.name user1.email = "Tarenpion" user2 = User(username="******", password="******") role2 = Role(name="__test_role2", description="__test_role2", functionalities=[pt1, pt2]) user2.role_name = role2.name user2.email = "Tarenpion" user3 = User(username="******", password="******") role3 = Role(name="__test_role3", description="__test_role3", functionalities=[pt1, pt2]) user3.role_name = role3.name 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) DBSession.add_all([ p1, p2, p3, p4, user1, user2, user3, role1, role2, role3, restricted_area1, restricted_area2, restricted_area3, ogcserver_geoserver ]) DBSession.flush() self.id_lausanne = p1.id self.id_paris = p3.id self.ogc_server_id = ogc_server_internal.id self.role1_id = role1.id self.role2_id = role2.id self.role3_id = role3.id transaction.commit()
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 setup_method(self, _): self.maxDiff = None from c2cgeoportal.models import User, Role, LayerWMS, RestrictionArea, \ Interface, DBSession, OGCServer, \ OGCSERVER_TYPE_MAPSERVER, OGCSERVER_AUTH_STANDARD cleanup_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="******") user.role_name = "__test_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()
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
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
def setUp(self): # noqa # Always see the diff # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff self.maxDiff = None functionality.FUNCTIONALITIES_TYPES = None from c2cgeoportal.models import DBSession, User, Role, \ RestrictionArea, Theme, LayerGroup, Interface, LayerWMS ogcserver, ogcserver_external = create_default_ogcserver() role1 = Role(name=u"__test_role1") role1.id = 999 user1 = User(username=u"__test_user1", password=u"__test_user1", role=role1) user1.email = "*****@*****.**" role2 = Role(name=u"__test_role2", extent=WKTElement("POLYGON((1 2, 1 4, 3 4, 3 2, 1 2))", srid=21781)) user2 = User(username=u"__test_user2", password=u"__test_user2", role=role2) main = Interface(name=u"main") private_layer = LayerWMS(name=u"__test_private_layer", public=False) private_layer.layer = "__test_private_layer" private_layer.geo_table = "a_schema.a_geo_table" private_layer.interfaces = [main] private_layer.ogc_server = ogcserver group = LayerGroup(name=u"__test_layer_group") group.children = [private_layer] theme = Theme(name=u"__test_theme") theme.children = [group] theme.interfaces = [main] DBSession.add( RestrictionArea( name=u"__test_ra1", description=u"", layers=[private_layer], roles=[role1], )) DBSession.add( RestrictionArea( name=u"__test_ra2", description=u"", layers=[private_layer], roles=[role2], readwrite=True, )) DBSession.add_all([ user1, user2, role1, role2, theme, group, private_layer, ]) transaction.commit()
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
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
def setup_method(self, _): # Always see the diff # https://docs.python.org/2/library/unittest.html#unittest.TestCase.maxDiff self.maxDiff = None self._tables = [] functionality.FUNCTIONALITIES_TYPES = None from c2cgeoportal.models import DBSession, User, Role, \ RestrictionArea, TreeItem, Theme, LayerGroup, Interface, LayerWMS from sqlalchemy import Column, Table, types from sqlalchemy.ext.declarative import declarative_base from geoalchemy2 import Geometry for o in DBSession.query(RestrictionArea).all(): DBSession.delete(o) for o in DBSession.query(Role).all(): DBSession.delete(o) for o in DBSession.query(User).all(): DBSession.delete(o) for o in DBSession.query(TreeItem).all(): DBSession.delete(o) ogcserver, ogcserver_external = create_default_ogcserver() role1 = Role(name="__test_role1") role1.id = 999 user1 = User(username="******", password="******", role=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="******", role=role2) main = Interface(name="main") 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() private_layer = LayerWMS(name="__test_private_layer", public=False) private_layer.layer = "__test_private_layer" private_layer.geo_table = "geodata.a_geo_table" private_layer.interfaces = [main] private_layer.ogc_server = ogcserver group = LayerGroup(name="__test_layer_group") group.children = [private_layer] theme = Theme(name="__test_theme") theme.children = [group] theme.interfaces = [main] DBSession.add(RestrictionArea( name="__test_ra1", description="", layers=[private_layer], roles=[role1], )) DBSession.add(RestrictionArea( name="__test_ra2", description="", layers=[private_layer], roles=[role2], readwrite=True, )) DBSession.add_all([ user1, user2, role1, role2, theme, group, private_layer, ]) transaction.commit()