Esempio n. 1
0
    def test_enumerate_attribute_values(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True)
        tablename = "table_%d" % layer_id
        settings = {
            "layers": {
                "enum": {
                    "layer_test": {
                        "table": tablename,
                        "attributes": {
                            "label": {
                                "column_name": "name"
                            }
                        }
                    }
                }
            }
        }

        request = self._get_request(layer_id)
        request.registry.settings.update(settings)
        request.matchdict["layer_name"] = "layer_test"
        request.matchdict["field_name"] = "label"
        layers = Layers(request)
        response = layers.enumerate_attribute_values()
        self.assertEquals(response, {
            "items": [{
                "label": "bar",
                "value": "bar"
            }, {
                "label": "foo",
                "value": "foo"
            }]
        })
Esempio n. 2
0
    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)
Esempio n. 3
0
    def test_enumerate_attribute_values(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True)
        tablename = "table_%d" % layer_id
        settings = {
            "layers": {
                "enum": {
                    "layer_test": {
                        "table": tablename,
                        "attributes": {
                            "label": {
                                "column_name": "name"
                            }
                        }
                    }
                }
            }
        }

        request = self._get_request(layer_id)
        request.registry.settings.update(settings)
        request.matchdict['layer_name'] = 'layer_test'
        request.matchdict['field_name'] = 'label'
        layers = Layers(request)
        response = layers.enumerate_attribute_values()
        self.assertEquals(response, {
            'items': [{
                'label': 'bar',
                'value': 'bar'
            }, {
                'label': 'foo',
                'value': 'foo'
            }]
        })
Esempio n. 4
0
    def test_enumerate_attribute_values(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True)
        tablename = "table_%d" % layer_id
        settings = {
            'layers_enum': {
                'layer_test': {
                    'table': tablename,
                    'attributes': {
                        'label': {
                            'column_name': 'name'
                        }
                    }
                }
            }
        }

        request = self._get_request(layer_id)
        request.registry.settings.update(settings)
        request.matchdict['layer_name'] = 'layer_test'
        request.matchdict['field_name'] = 'label'
        layers = Layers(request)
        response = layers.enumerate_attribute_values()
        self.assertEquals(
            response, {
                'items': [{
                    'label': 'bar',
                    'value': 'bar'
                }, {
                    'label': 'foo',
                    'value': 'foo'
                }]
            })
Esempio n. 5
0
    def test_count_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        response = layers.count()
        self.assertEquals(response, 2)
Esempio n. 6
0
    def test_metadata_exclude_properties(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(exclude_properties=True)
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        cls = layers.metadata()
        self.assertFalse(hasattr(cls, "name"))
Esempio n. 7
0
    def test_count_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        response = layers.count()
        self.assertEquals(response, 2)
Esempio n. 8
0
    def test_metadata_exclude_properties(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(exclude_properties=True)
        request = self._get_request(layer_id, username=u'__test_user')

        layers = Layers(request)
        cls = layers.metadata()
        self.assertFalse(hasattr(cls, 'name'))
Esempio n. 9
0
    def test_delete_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u'__test_user')
        request.matchdict['feature_id'] = 1
        request.method = 'DELETE'
        layers = Layers(request)
        response = layers.delete()
        self.assertEquals(response.status_int, 204)
Esempio n. 10
0
    def test_delete_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")
        request.matchdict["feature_id"] = 1
        request.method = "DELETE"
        layers = Layers(request)
        response = layers.delete()
        self.assertEquals(response.status_int, 204)
Esempio n. 11
0
    def test_delete(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u'__test_user')
        request.matchdict['feature_id'] = 1
        request.method = 'DELETE'
        layers = Layers(request)
        response = layers.delete()
        self.assertEquals(response.status_int, 204)
Esempio n. 12
0
    def test_delete(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")
        request.matchdict["feature_id"] = 1
        request.method = "DELETE"
        layers = Layers(request)
        response = layers.delete()
        self.assertEquals(response.status_int, 204)
Esempio n. 13
0
    def test_metadata(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        cls = layers.metadata()
        self.assertEquals(cls.__table__.name, "table_%d" % layer_id)
        self.assertTrue(hasattr(cls, "name"))
        self.assertTrue("child" in cls.__dict__)
Esempio n. 14
0
    def test_read_one_public_notfound(self):
        from pyramid.httpexceptions import HTTPNotFound
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True)
        request = self._get_request(layer_id)
        request.matchdict["feature_id"] = 10000

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, HTTPNotFound))
Esempio n. 15
0
    def test_metadata(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u'__test_user')

        layers = Layers(request)
        cls = layers.metadata()
        self.assertEquals(cls.__table__.name, 'table_%d' % layer_id)
        self.assertTrue(hasattr(cls, 'name'))
        self.assertTrue('child' in cls.__dict__)
Esempio n. 16
0
    def test_metadata(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u'__test_user')

        layers = Layers(request)
        cls = layers.metadata()
        self.assertEquals(cls.__table__.name, 'table_%d' % layer_id)
        self.assertTrue(hasattr(cls, 'name'))
        self.assertTrue('child' in cls.__dict__)
Esempio n. 17
0
    def test_read_many(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals([f.properties["child"] for f in collection.features], [u"c1é"])
Esempio n. 18
0
    def test_read_one_public_notfound(self):
        from pyramid.httpexceptions import HTTPNotFound
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True)
        request = self._get_request(layer_id)
        request.matchdict['feature_id'] = 10000

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, HTTPNotFound))
Esempio n. 19
0
    def test_metadata(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        cls = layers.metadata()
        self.assertEquals(cls.__table__.name, "table_%d" % layer_id)
        self.assertTrue(hasattr(cls, "name"))
        self.assertTrue("child" in cls.__dict__)
Esempio n. 20
0
    def test_create_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u'__test_user')
        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": "Point", "coordinates": [5, 45]}}]}'  # NOQA
        layers = Layers(request)
        collection = layers.create()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
Esempio n. 21
0
    def test_read_many(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals([f.properties["child"] for f in collection.features],
                          [u"c1é"])
Esempio n. 22
0
    def test_read_many(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u'__test_user')

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 1)
        self.assertEquals(collection.features[0].properties['child'], u'c1é')
Esempio n. 23
0
    def test_create_validation_fails(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")
        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)
        response = layers.create()
        self.assertEquals(request.response.status_int, 400)
        self.assertTrue("validation_error" in response)
        self.assertEquals(response["validation_error"], "Too few points in geometry component[5 45]")
Esempio n. 24
0
    def test_read_many(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u'__test_user')

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 1)
        self.assertEquals(collection.features[0].properties['child'], u'c1é')
Esempio n. 25
0
    def test_create_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")
        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": "Point", "coordinates": [5, 45]}}]}'  # noqa
        layers = Layers(request)
        collection = layers.create()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
Esempio n. 26
0
    def test_update_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        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.name, 'foobar')
        self.assertEquals(feature.child, u'c2é')
Esempio n. 27
0
    def test_create_validation_fails(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id, username=u"__test_user")
        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)
        response = layers.create()
        self.assertEquals(request.response.status_int, 400)
        self.assertTrue("validation_error" in response)
        self.assertEquals(response["validation_error"],
                          "Too few points in geometry component[5 45]")
Esempio n. 28
0
    def test_read_public_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
        self.assertEquals(collection.features[0].properties['child'], u'c1é')
        self.assertEquals(collection.features[1].properties['child'], u'c2é')
Esempio n. 29
0
    def test_update(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        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.name, "foobar")
        self.assertEquals(feature.child, u"c2é")
Esempio n. 30
0
    def test_read_public_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
        self.assertEquals(collection.features[0].properties['child'], u'c1é')
        self.assertEquals(collection.features[1].properties['child'], u'c2é')
Esempio n. 31
0
    def test_read_many_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
        self.assertEquals(collection.features[0].properties["child"], u"c1é")
        self.assertEquals(collection.features[1].properties["child"], u"c2é")
Esempio n. 32
0
    def test_update_validation_fails_simple(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        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": "LineString", "coordinates": [[5, 45], [6, 45], [5, 45]]}}'  # noqa
        layers = Layers(request)
        response = layers.update()
        self.assertEquals(request.response.status_int, 400)
        self.assertTrue("validation_error" in response)
        self.assertEquals(response["validation_error"], "Not simple")
Esempio n. 33
0
    def test_read_many_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
        self.assertEquals(collection.features[0].properties["child"], u"c1é")
        self.assertEquals(collection.features[1].properties["child"], u"c2é")
Esempio n. 34
0
    def test_update_validation_fails(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        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": "LineString", "coordinates": [[5, 45], [5, 45]]}}'  # noqa
        layers = Layers(request)
        response = layers.update()
        self.assertEquals(request.response.status_int, 400)
        self.assertTrue('validation_error' in response)
        self.assertEquals(response['validation_error'], 'Too few points in geometry component[5 45]')
Esempio n. 35
0
    def test_update_none_area(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        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.name, "foobar")
        self.assertEquals(feature.child, u"c2é")
Esempio n. 36
0
    def test_update(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        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.name, 'foobar')
        self.assertEquals(feature.child, u'c2é')
Esempio n. 37
0
    def test_update_validation_fails_simple(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        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": "LineString", "coordinates": [[5, 45], [6, 45], [5, 45]]}}'  # noqa
        layers = Layers(request)
        response = layers.update()
        self.assertEquals(request.response.status_int, 400)
        self.assertTrue("validation_error" in response)
        self.assertEquals(response["validation_error"], "Not simple")
Esempio n. 38
0
    def test_read_one_none_area(self):
        from geojson.feature import Feature
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")
        request.matchdict["feature_id"] = 1

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, Feature))
        self.assertEquals(feature.id, 1)
        self.assertEquals(feature.properties["name"], "foo")
        self.assertEquals(feature.properties["child"], u"c1é")
Esempio n. 39
0
    def test_read_public_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(
            [f.properties["child"] for f in collection.features],
            [u"c1é", u"c2é"],
        )
Esempio n. 40
0
    def test_read_one_none_area(self):
        from geojson.feature import Feature
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u"__test_user")
        request.matchdict["feature_id"] = 1

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, Feature))
        self.assertEquals(feature.id, 1)
        self.assertEquals(feature.properties["name"], "foo")
        self.assertEquals(feature.properties["child"], u"c1é")
Esempio n. 41
0
    def test_read_public_none_area(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(
            [f.properties["child"] for f in collection.features],
            [u"c1é", u"c2é"],
        )
Esempio n. 42
0
    def test_read_one_none_area(self):
        from geojson.feature import Feature
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u'__test_user')
        request.matchdict['feature_id'] = 1

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, Feature))
        self.assertEquals(feature.id, 1)
        self.assertEquals(feature.properties['name'], 'foo')
        self.assertEquals(feature.properties['child'], u'c1é')
Esempio n. 43
0
    def test_read_one_none_area(self):
        from geojson.feature import Feature
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id, username=u'__test_user')
        request.matchdict['feature_id'] = 1

        layers = Layers(request)
        feature = layers.read_one()
        self.assertTrue(isinstance(feature, Feature))
        self.assertEquals(feature.id, 1)
        self.assertEquals(feature.properties['name'], 'foo')
        self.assertEquals(feature.properties['child'], u'c1é')
Esempio n. 44
0
    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"))
Esempio n. 45
0
    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"))
Esempio n. 46
0
    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)
Esempio n. 47
0
    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é")
Esempio n. 48
0
    def test_create_no_validation(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers
        from c2cgeoportal.models import Metadata

        metadatas = [
            Metadata("geometry_validation", "False")
        ]
        layer_id = self._create_layer(metadatas=metadatas, geom_type=False)
        request = self._get_request(layer_id, username=u"__test_user")
        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.assertEquals(request.response.status_int, 201)
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 2)
Esempio n. 49
0
    def test_update_no_validation(self):
        from c2cgeoportal.views.layers import Layers
        from c2cgeoportal.models import Metadata

        metadatas = [
            Metadata("geometry_validation", "False")
        ]
        layer_id = self._create_layer(metadatas=metadatas, geom_type=False)
        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": "LineString", "coordinates": [[5, 45], [5, 45]]}}'  # noqa
        layers = Layers(request)
        feature = layers.update()
        self.assertEquals(feature.id, 1)
        self.assertEquals(feature.name, "foobar")
        self.assertEquals(feature.child, u"c2é")
Esempio n. 50
0
    def test_read_many_layer_not_found(self):
        from pyramid.httpexceptions import HTTPNotFound
        from c2cgeoportal.views.layers import Layers

        self._create_layer()
        request = self._get_request(10000, username=u'__test_user')

        layers = Layers(request)
        self.assertRaises(HTTPNotFound, layers.read_many)
Esempio n. 51
0
    def test_read_many_multi(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id1 = self._create_layer()
        layer_id2 = self._create_layer()
        layer_id3 = self._create_layer()

        layer_ids = "%d,%d,%d" % (layer_id1, layer_id2, layer_id3)
        request = self._get_request(layer_ids, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(
            [f.properties["__layer_id__"] for f in collection.features],
            [layer_id1, layer_id2, layer_id3],
        )
Esempio n. 52
0
    def test_read_many_multi(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id1 = self._create_layer()
        layer_id2 = self._create_layer()
        layer_id3 = self._create_layer()

        layer_ids = "%d,%d,%d" % (layer_id1, layer_id2, layer_id3)
        request = self._get_request(layer_ids, username=u"__test_user")

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(
            [f.properties["__layer_id__"] for f in collection.features],
            [layer_id1, layer_id2, layer_id3],
        )
Esempio n. 53
0
    def test_read_many_no_auth_none_area(self):
        from pyramid.httpexceptions import HTTPForbidden
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id)

        layers = Layers(request)
        self.assertRaises(HTTPForbidden, layers.read_many)
Esempio n. 54
0
    def test_metadata_no_auth(self):
        from pyramid.httpexceptions import HTTPForbidden
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer()
        request = self._get_request(layer_id)

        layers = Layers(request)
        self.assertRaises(HTTPForbidden, layers.metadata)
Esempio n. 55
0
    def test_enumerate_attribute_values_list(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, attr_list=True)
        tablename = "table_%d" % layer_id
        settings = {
            "layers": {
                "enum": {
                    "layer_test": {
                        "table": tablename,
                        "attributes": {
                            "label": {
                                "column_name": "name",
                                "separator": ","
                            }
                        }
                    }
                }
            }
        }

        request = self._get_request(layer_id)
        request.registry.settings.update(settings)
        request.matchdict["layer_name"] = "layer_test"
        request.matchdict["field_name"] = "label"

        layers = Layers(request)
        response = layers.enumerate_attribute_values()
        self.assertEquals(
            response, {
                "items": [{
                    "label": u"aaa",
                    "value": u"aaa"
                }, {
                    "label": u"bar",
                    "value": u"bar"
                }, {
                    "label": u"bbb",
                    "value": u"bbb"
                }, {
                    "label": u"foo",
                    "value": u"foo"
                }]
            })
Esempio n. 56
0
    def test_delete_no_auth_none_area(self):
        from pyramid.httpexceptions import HTTPForbidden
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(none_area=True)
        request = self._get_request(layer_id)
        request.matchdict['feature_id'] = 2
        request.method = 'DELETE'
        layers = Layers(request)
        self.assertRaises(HTTPForbidden, layers.delete)
Esempio n. 57
0
    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)
Esempio n. 58
0
    def test_enumerate_attribute_values_list(self):
        from c2cgeoportal.views.layers import Layers

        layer_id = self._create_layer(public=True, attr_list=True)
        tablename = "table_%d" % layer_id
        settings = {
            'layers_enum': {
                'layer_test': {
                    'table': tablename,
                    'attributes': {
                        'label': {
                            'column_name': 'name',
                            'separator': ','
                        }
                    }
                }
            }
        }

        request = self._get_request(layer_id)
        request.registry.settings.update(settings)
        request.matchdict['layer_name'] = 'layer_test'
        request.matchdict['field_name'] = 'label'

        layers = Layers(request)
        response = layers.enumerate_attribute_values()
        self.assertEquals(response, {
            'items': [{
                'label': u'aaa',
                'value': u'aaa'
            }, {
                'label': u'bar',
                'value': u'bar'
            }, {
                'label': u'bbb',
                'value': u'bbb'
            }, {
                'label': u'foo',
                'value': u'foo'
            }]
        })
Esempio n. 59
0
    def test_read_many_multi(self):
        from geojson.feature import FeatureCollection
        from c2cgeoportal.views.layers import Layers

        layer_id1 = self._create_layer()
        layer_id2 = self._create_layer()
        layer_id3 = self._create_layer()

        layer_ids = '%d,%d,%d' % (layer_id1, layer_id2, layer_id3)
        request = self._get_request(layer_ids, username=u'__test_user')

        layers = Layers(request)
        collection = layers.read_many()
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 3)
        self.assertEquals(collection.features[0].properties['__layer_id__'],
                          layer_id1)
        self.assertEquals(collection.features[1].properties['__layer_id__'],
                          layer_id2)
        self.assertEquals(collection.features[2].properties['__layer_id__'],
                          layer_id3)
Esempio n. 60
0
    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

        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.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.assertEquals(request.response.status_int, 201)
        self.assertTrue(isinstance(collection, FeatureCollection))
        self.assertEquals(len(collection.features), 1)
        properties = collection.features[0]
        self.assertEquals(properties.last_update_user, request.user.id)
        self.assertIsInstance(properties.last_update_date, datetime)