def test_protocol_delete(self): """Delete an existing point""" proto = Protocol(session, Spot) id = 1 request = FakeRequest({}) response = FakeResponse() proto.delete(request, response, id) eq_(response.status, 204) spot = session.query(Spot).get(id) ok_(spot is None)
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)
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)
def test_protocol_delete_fails(self): """Try to delete a not-existing point""" proto = Protocol(session, Spot) proto.delete(FakeRequest({}), FakeResponse(), -1)