def test_create_log(self): from datetime import datetime from geojson.feature import FeatureCollection from c2cgeoportal.views.layers import Layers from c2cgeoportal.models import Metadata from c2cgeoportal.models import DBSession, User self.assertEqual( DBSession.query(User.username).all(), [("__test_user", )]) metadatas = [ Metadata("lastUpdateDateColumn", "last_update_date"), Metadata("lastUpdateUserColumn", "last_update_user"), ] layer_id = self._create_layer(metadatas=metadatas) request = self._get_request(layer_id, username="******") request.method = "POST" request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"name": "foo", "child": "c1é"}, "geometry": {"type": "Point", "coordinates": [5, 45]}}]}' # noqa layers = Layers(request) collection = layers.create() self.assertEqual(request.response.status_int, 201) self.assertTrue(isinstance(collection, FeatureCollection)) self.assertEqual(len(collection.features), 1) properties = collection.features[0] self.assertEqual(request.user.username, "__test_user") self.assertEqual(properties.last_update_user, request.user.id) self.assertIsInstance(properties.last_update_date, datetime)
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 DBSession, \ Theme, LayerGroup, Interface, LayerWMS, Metadata main = Interface(name="desktop") ogc_server, _ = create_default_ogcserver() layer_noscale = LayerWMS(name="__test_layer_noscale", public=True) layer_noscale.layer = "test_noscale" layer_noscale.interfaces = [main] layer_noscale.ogc_server = ogc_server layer_minscale = LayerWMS(name="__test_layer_minscale", public=True) layer_minscale.layer = "test_minscale" layer_minscale.interfaces = [main] layer_minscale.ogc_server = ogc_server layer_maxscale = LayerWMS(name="__test_layer_maxscale", public=True) layer_maxscale.layer = "test_maxscale" layer_maxscale.interfaces = [main] layer_maxscale.ogc_server = ogc_server layer_boothscale = LayerWMS(name="__test_layer_boothscale", public=True) layer_boothscale.layer = "test_boothscale" layer_boothscale.interfaces = [main] layer_boothscale.ogc_server = ogc_server layer_metadatascale = LayerWMS(name="__test_layer_metadatascale", public=True) layer_metadatascale.layer = "test_boothscale" layer_metadatascale.interfaces = [main] layer_metadatascale.ogc_server = ogc_server layer_metadatascale.metadatas = [ Metadata("minResolution", "100"), Metadata("maxResolution", "1000"), ] layer_group = LayerGroup(name="__test_layer_group") layer_group.children = [layer_noscale, layer_minscale, layer_maxscale, layer_boothscale, layer_metadatascale] theme = Theme(name="__test_theme") theme.interfaces = [main] theme.children = [layer_group] DBSession.add_all([theme]) transaction.commit()
def test_metadata_log(self): from c2cgeoportal.views.layers import Layers from c2cgeoportal.models import Metadata metadatas = [ Metadata("lastUpdateDateColumn", "last_update_date"), Metadata("lastUpdateUserColumn", "last_update_user"), ] layer_id = self._create_layer(metadatas=metadatas) request = self._get_request(layer_id, username=u"__test_user") layers = Layers(request) cls = layers.metadata() self.assertFalse(hasattr(cls, "last_update_date")) self.assertFalse(hasattr(cls, "last_update_user"))
def test_update_log(self): from datetime import datetime from c2cgeoportal.views.layers import Layers from c2cgeoportal.models import Metadata metadatas = [ Metadata("lastUpdateDateColumn", "last_update_date"), Metadata("lastUpdateUserColumn", "last_update_user"), ] layer_id = self._create_layer(metadatas=metadatas) request = self._get_request(layer_id, username=u"__test_user") request.matchdict["feature_id"] = 1 request.method = "PUT" request.body = '{"type": "Feature", "id": 1, "properties": {"name": "foobar", "child": "c2é"}, "geometry": {"type": "Point", "coordinates": [5, 45]}}' # noqa layers = Layers(request) feature = layers.update() self.assertEquals(feature.id, 1) self.assertEquals(feature.last_update_user, request.user.id) self.assertIsInstance(feature.last_update_date, datetime)
def test_update_no_validation(self): from c2cgeoportal.views.layers import Layers from c2cgeoportal.models import Metadata metadatas = [Metadata("geometryValidation", "False")] layer_id = self._create_layer(metadatas=metadatas, geom_type=False) request = self._get_request(layer_id, username="******") request.matchdict["feature_id"] = 1 request.method = "PUT" request.body = '{"type": "Feature", "id": 1, "properties": {"name": "foobar", "child": "c2é"}, "geometry": {"type": "LineString", "coordinates": [[5, 45], [5, 45]]}}' # noqa layers = Layers(request) feature = layers.update() self.assertEqual(feature.id, 1) self.assertEqual(feature.name, "foobar") self.assertEqual(feature.child, "c2é")
def test_create_no_validation(self): from geojson.feature import FeatureCollection from c2cgeoportal.views.layers import Layers from c2cgeoportal.models import Metadata metadatas = [Metadata("geometryValidation", "False")] layer_id = self._create_layer(metadatas=metadatas, geom_type=False) request = self._get_request(layer_id, username="******") request.method = "POST" request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"name": "foo", "child": "c1é"}, "geometry": {"type": "Point", "coordinates": [5, 45]}}, {"type": "Feature", "properties": {"text": "foo", "child": "c2é"}, "geometry": {"type": "LineString", "coordinates": [[5, 45], [5, 45]]}}]}' # noqa layers = Layers(request) collection = layers.create() self.assertEqual(request.response.status_int, 201) self.assertTrue(isinstance(collection, FeatureCollection)) self.assertEqual(len(collection.features), 2)
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 DBSession, \ Theme, LayerGroup, Functionality, Interface, \ LayerV1, OGCServer, LayerWMS, LayerWMTS, \ Metadata, Dimension, OGCSERVER_AUTH_NOAUTH main = Interface(name="desktop") mobile = Interface(name="mobile") min_levels = Interface(name="min_levels") layer_v1 = LayerV1(name="__test_layer_v1", public=True) layer_v1.interfaces = [main] layer_v1.metadatas = [Metadata("test", "v1")] 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_v1, 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 test_themes_edit_columns_extras(self): from c2cgeoportal.views.entry import Entry from c2cgeoportal.models import Metadata metadatas = [ Metadata("lastUpdateDateColumn", "last_update_date"), Metadata("lastUpdateUserColumn", "last_update_user"), ] layer_id = self._create_layer(geom_type=False, exclude_properties=True, metadatas=metadatas) entry = Entry(self._get_request(layer_id, username="******", params={ "version": "2", "interface": "main" })) themes = entry.themes() layers = themes["themes"][0]["children"][0]["children"] self.assertEqual( [layer["edit_columns"] for layer in layers], [[{ "nillable": True, "type": "xsd:integer", "name": "child_id" }, { "nillable": True, "type": "xsd:boolean", "name": "deleted" }, { "nillable": True, "type": "xsd:date", "name": "date" }, { "nillable": True, "type": "xsd:time", "name": "start_time" # }, { # "nillable": True, # "type": "xsd:duration", # "name": "interval" }, { "nillable": True, "type": "xsd:string", "name": "short_name1" }, { "nillable": True, "type": "xsd:string", "name": "short_name2", "maxLength": 50 }, { "nillable": True, "type": "xsd:integer", "name": "short_number" }, { "nillable": True, "type": "xsd:double", "name": "double_number" }, { "nillable": True, "type": "xsd:base64Binary", "name": "large_binary" }, { "enumeration": [ "one", "two", "three", ], "type": "xsd:string", "name": "value", "nillable": True, "restriction": "enumeration" }, { "fractionDigits": 2, "nillable": True, "type": "xsd:decimal", "name": "numeric", "totalDigits": 5, }, { "name": "numeric2", "type": "xsd:decimal", "nillable": True }, { "srid": 21781, "nillable": True, "type": "gml:GeometryPropertyType", "name": "geom" }, { "restriction": "enumeration", "nillable": True, "type": "xsd:string", "name": "child", "enumeration": [ "c1\xe9", "c2\xe9" ] }]] )
def new_metadata(name, value, item): from c2cgeoportal.models import Metadata metadata = Metadata(name, value) metadata.item = item return metadata
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 DBSession, \ Theme, LayerGroup, Interface, LayerWMS, Metadata desktop = Interface(name="desktop") ogc_server_internal, _ = create_default_ogcserver() layer_wms = LayerWMS(name="__test_layer_internal_wms", public=True) layer_wms.layer = "__test_layer_internal_wms" layer_wms.ogc_server = ogc_server_internal layer_wms.interfaces = [desktop] layer_wms.metadatas = [ Metadata("string", "string"), Metadata("list", "1, 2, a"), Metadata("boolean", "y"), Metadata("boolean2", "no"), Metadata("boolean3", "Hello"), Metadata("integer", "1"), Metadata("float", "5.5"), Metadata("json", '{"test": 123}'), Metadata("json_wrong", '{"test": 123'), Metadata("date", "Sep 25 2003"), Metadata("time", "10:36:28"), Metadata("datetime", "Sep 25 10:36:28 BRST 2003"), Metadata("date2", "Sep 25 10:36:28 BRST 2003"), Metadata("time2", "Sep 25 10:36:28 BRST 2003"), Metadata("datetime2", "Hello"), Metadata("url1", "http://example.com/hi?a=b#c"), Metadata("url2", "static:///path/icon.png"), Metadata("url3", "static://static/path/icon.png"), Metadata("url4", "static://cgxp/path/icon.png"), Metadata("url5", "static://project:static/path/icon.png"), Metadata("url6", "static://project:cgxp/path/icon.png"), Metadata("url7", "config://server"), Metadata("url8", "config://server/index.html"), Metadata("url9", "/dummy/static/icon.png"), Metadata("url10", "dummy/static/icon.png"), Metadata("url11", "https:///static/icon.png"), Metadata("url12", "static://test"), Metadata("url13", "static://test/"), Metadata("url14", "config:///static/icon.png"), Metadata("url15", "config://unknown_server"), Metadata("url16", "https://"), Metadata("url17", "https:///"), Metadata("url18", "https:///static"), Metadata("url19", ""), Metadata("url20", "/"), Metadata("unknown", "Hello"), ] layer_group = LayerGroup(name="__test_layer_group") layer_group.children = [layer_wms] theme = Theme(name="__test_theme") theme.interfaces = [desktop] theme.children = [layer_group] DBSession.add(theme) transaction.commit()