示例#1
0
def get_property(request):

    if 'id' not in request.params:
        return HTTPBadRequest(detail='Please add a valid id in your request')

    id_ = request.params['id']

    proto = Protocol(DBSession, Property, 'geom')

    filter = "id IN ('" + id_ + "')"

    return proto.read(request, filter=filter)
示例#2
0
    def test_read_notfound(self):
        from papyrus.protocol import Protocol
        from pyramid.httpexceptions import HTTPNotFound

        class Session(object):
            def query(self, mapped_class):
                return {'a': None}

        proto = Protocol(Session, self._get_mapped_class(), 'geom')
        request = testing.DummyRequest()

        resp = proto.read(request, id='a')
        self.assertTrue(isinstance(resp, HTTPNotFound))
示例#3
0
    def test_read_notfound(self):
        from papyrus.protocol import Protocol
        from pyramid.httpexceptions import HTTPNotFound

        class Session(object):
            def query(self, mapped_class):
                return {'a': None}

        proto = Protocol(Session, self._get_mapped_class(), 'geom')
        request = testing.DummyRequest()

        resp = proto.read(request, id='a')
        self.assertTrue(isinstance(resp, HTTPNotFound))
示例#4
0
    def test_read_id(self):
        from papyrus.protocol import Protocol
        from shapely.geometry import Point
        from geojson import Feature

        class Session(object):
            def query(self, mapped_class):
                feature = Feature(id='a', geometry=Point(1, 2),
                                  properties=dict(text='foo'))
                return {'a': mapped_class(feature)}

        proto = Protocol(Session, self._get_mapped_class(), 'geom')
        request = testing.DummyRequest()

        feature = proto.read(request, id='a')
        self.assertEqual(feature.id, 'a')
        self.assertEqual(feature.properties['text'], 'foo')
示例#5
0
    def test_read_id(self):
        from papyrus.protocol import Protocol
        from shapely.geometry import Point
        from geojson import Feature

        class Session(object):
            def query(self, mapped_class):
                feature = Feature(id='a', geometry=Point(1, 2),
                                  properties=dict(text='foo'))
                return {'a': mapped_class(feature)}

        proto = Protocol(Session, self._get_mapped_class(), 'geom')
        request = testing.DummyRequest()

        feature = proto.read(request, id='a')
        self.assertEqual(feature.id, 'a')
        self.assertEqual(feature.properties['text'], 'foo')
示例#6
0
    def test_read_many(self):
        from papyrus.protocol import Protocol
        from shapely.geometry import Point
        from geojson import Feature, FeatureCollection

        engine = self._get_engine()
        Session = self._get_session(engine)
        MappedClass = self._get_mapped_class()

        proto = Protocol(Session, MappedClass, 'geom')

        def _query(request, filter):
            f1 = Feature(geometry=Point(1, 2))
            f2 = Feature(geometry=Point(2, 3))
            return [MappedClass(f1), MappedClass(f2)]
        proto._query = _query

        features = proto.read(testing.DummyRequest())
        self.assertTrue(isinstance(features, FeatureCollection))
        self.assertEqual(len(features.features), 2)
示例#7
0
    def test_read_many(self):
        from papyrus.protocol import Protocol
        from shapely.geometry import Point
        from geojson import Feature, FeatureCollection

        engine = self._get_engine()
        Session = self._get_session(engine)
        MappedClass = self._get_mapped_class()

        proto = Protocol(Session, MappedClass, 'geom')

        def _query(request, filter):
            f1 = Feature(geometry=Point(1, 2))
            f2 = Feature(geometry=Point(2, 3))
            return [MappedClass(f1), MappedClass(f2)]
        proto._query = _query

        features = proto.read(testing.DummyRequest())
        self.assertTrue(isinstance(features, FeatureCollection))
        self.assertEqual(len(features.features), 2)