Esempio n. 1
0
 def test_protocol_update_fails(self):
     """Try to update a not-existing feature"""
     proto = Protocol(session, Spot)
     id = -1
     
     request = FakeRequest({})
     request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
     
     response = FakeResponse()
     proto.update(request, response, id)
Esempio n. 2
0
    def test_protocol_update_fails(self):
        """Try to update a not-existing feature"""
        proto = Protocol(session, Spot)
        id = -1

        request = FakeRequest({})
        request.body = '{"type": "Feature", "id": ' + str(
            id
        ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'

        response = FakeResponse()
        proto.update(request, response, id)
class ParkingMetersController(BaseController):
    readonly = True # if set to True, only GET is supported

    def __init__(self):
        self.protocol = Protocol(Session, ParkingMeter, self.readonly)

    @geojsonify
    def index(self, format='json'):
        """GET /: return all features."""
        # If no filter argument is passed to the protocol index method
        # then the default MapFish filter is used.
        #
        # If you need your own filter with application-specific params 
        # taken into acount, create your own filter and pass it to the
        # protocol read method.
        #
        # E.g.
        #
        # from sqlalchemy.sql import and_
        #
        # default_filter = create_default_filter(request, ParkingMeter)
        # filter = and_(default_filter, ParkingMeter.columname.ilike('%value%'))
        # return self.protocol.read(request, filter=filter)
        if format != 'json':
            abort(404)
        response.headers['Access-Control-Allow-Origin'] = 'http://localhost:8000';
        return self.protocol.read(request)

    @geojsonify
    def show(self, id, format='json'):
        """GET /id: Show a specific feature."""
        if format != 'json':
            abort(404)
        return self.protocol.read(request, response, id=id)

    @geojsonify
    def create(self):
        """POST /: Create a new feature."""
        return self.protocol.create(request, response)

    @geojsonify
    def update(self, id):
        """PUT /id: Update an existing feature."""
        return self.protocol.update(request, response, id)

    def delete(self, id):
        """DELETE /id: Delete an existing feature."""
        return self.protocol.delete(request, response, id)

    def count(self):
        """GET /count: Count all features."""
        return self.protocol.count(request)
Esempio n. 4
0
class BicycleRentalController(BaseController):
    readonly = False  # if set to True, only GET is supported

    def __init__(self):
        self.protocol = Protocol(Session, BicycleRental, self.readonly)

    @geojsonify
    def index(self, format='json'):
        """GET /: return all features."""
        # If no filter argument is passed to the protocol index method
        # then the default MapFish filter is used.
        #
        # If you need your own filter with application-specific params
        # taken into acount, create your own filter and pass it to the
        # protocol read method.
        #
        # E.g.
        #
        # from sqlalchemy.sql import and_
        #
        # default_filter = create_default_filter(request, BicycleRental)
        # filter = and_(default_filter, BicycleRental.columname.ilike('%value%'))
        # return self.protocol.read(request, filter=filter)
        if format != 'json':
            abort(404)
        return self.protocol.read(request)

    @geojsonify
    def show(self, id, format='json'):
        """GET /id: Show a specific feature."""
        if format != 'json':
            abort(404)
        return self.protocol.read(request, response, id=id)

    @geojsonify
    def create(self):
        """POST /: Create a new feature."""
        return self.protocol.create(request, response)

    @geojsonify
    def update(self, id):
        """PUT /id: Update an existing feature."""
        return self.protocol.update(request, response, id)

    def delete(self, id):
        """DELETE /id: Delete an existing feature."""
        return self.protocol.delete(request, response, id)

    def count(self):
        """GET /count: Count all features."""
        return self.protocol.count(request)
Esempio n. 5
0
 def test_protocol_update(self):
     """Update an existing point"""
     proto = Protocol(session, Spot)
     id = 1
     
     request = FakeRequest({})
     request.body = '{"type": "Feature", "id": ' + str(id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'
     
     response = FakeResponse()
     feature = proto.update(request, response, id)
     eq_(response.status, 201)
     eq_(feature.id, 1)
     eq_(feature.geometry.coordinates, (1.0, 1.0))
     
     spot = session.query(Spot).get(id)
     ok_(spot is not None)
     eq_(session.scalar(spot.spot_location.wkt), u'POINT(1 1)')
Esempio n. 6
0
    def test_protocol_update(self):
        """Update an existing point"""
        proto = Protocol(session, Spot)
        id = 1

        request = FakeRequest({})
        request.body = '{"type": "Feature", "id": ' + str(
            id
        ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}'

        response = FakeResponse()
        feature = proto.update(request, response, id)
        eq_(response.status, 201)
        eq_(feature.id, 1)
        eq_(feature.geometry.coordinates, (1.0, 1.0))

        spot = session.query(Spot).get(id)
        ok_(spot is not None)
        eq_(session.scalar(spot.spot_location.wkt), u'POINT(1 1)')