def test_protocol_create_fails(self): """Try to create a feature without geometry""" proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}' proto.create(request, FakeResponse())
def test_protocol_create_fails(self): """Try to create a feature without geometry""" proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}' proto.create(request, FakeResponse())
def test_protocol_create(self): from mapfish.protocol import Protocol proto = Protocol(Session, MappedClass) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}' response = FakeResponse() proto.create(request, response, execute=False) assert response.status == 201 assert len(Session.new) == 2 for obj in Session.new: assert obj["text"] == "foo" assert obj._mf_shape.x == 45 assert obj._mf_shape.y == 5 Session.rollback()
def test_protocol_create(self): from mapfish.protocol import Protocol proto = Protocol(Session, MappedClass) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}' response = FakeResponse() proto.create(request, response, execute=False) assert response.status == 201 assert len(Session.new) == 2 for obj in Session.new: assert obj["text"] == "foo" assert obj._mf_shape.x == 45 assert obj._mf_shape.y == 5 Session.rollback()
def test_protocol_create_and_update(self): """Create a new point and also update an already existing point""" old_spot = session.query(Spot).filter(Spot.spot_height==102.34).one() proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [\ {"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\ {"type": "Feature", "id": ' + str(old_spot.spot_id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}' response = FakeResponse() collection = proto.create(request, response) eq_(response.status, 201) eq_(len(collection.features), 2) feature0 = collection.features[0] eq_(feature0.id, 10) eq_(feature0.geometry.coordinates, (45.0, 5.0)) eq_(feature0.properties["spot_height"], 12) feature1 = collection.features[1] eq_(feature1.id, old_spot.spot_id) eq_(feature1.geometry.coordinates, (1, 1)) new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one() ok_(new_spot is not None) eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)') updated_spot = session.query(Spot).filter(Spot.spot_height==102.34).one() ok_(updated_spot is not None) ok_(old_spot is updated_spot) eq_(updated_spot.spot_height, 102.34) eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')
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_create(self): """Create a new point""" proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}' response = FakeResponse() collection = proto.create(request, response) eq_(response.status, 201) eq_(len(collection.features), 1) feature0 = collection.features[0] eq_(feature0.id, 10) eq_(feature0.geometry.coordinates, (45.0, 5.0)) eq_(feature0.properties["spot_height"], 12) new_spot = session.query(Spot).filter(Spot.spot_height == 12.0).one() ok_(new_spot is not None) eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')
def test_protocol_create(self): """Create a new point""" proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}' response = FakeResponse() collection = proto.create(request, response) eq_(response.status, 201) eq_(len(collection.features), 1) feature0 = collection.features[0] eq_(feature0.id, 10) eq_(feature0.geometry.coordinates, (45.0, 5.0)) eq_(feature0.properties["spot_height"], 12) new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one() ok_(new_spot is not None) eq_(session.scalar(new_spot.spot_location.wkt), u'POINT (45.0 5.0)')
def test_protocol_create_and_update(self): """Create a new point and also update an already existing point""" old_spot = session.query(Spot).filter(Spot.spot_height == 102.34).one() proto = Protocol(session, Spot) request = FakeRequest({}) request.body = '{"type": "FeatureCollection", "features": [\ {"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\ {"type": "Feature", "id": ' + str( old_spot.spot_id ) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}' response = FakeResponse() collection = proto.create(request, response) eq_(response.status, 201) eq_(len(collection.features), 2) feature0 = collection.features[0] eq_(feature0.id, 10) eq_(feature0.geometry.coordinates, (45.0, 5.0)) eq_(feature0.properties["spot_height"], 12) feature1 = collection.features[1] eq_(feature1.id, old_spot.spot_id) eq_(feature1.geometry.coordinates, (1, 1)) new_spot = session.query(Spot).filter(Spot.spot_height == 12.0).one() ok_(new_spot is not None) eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)') updated_spot = session.query(Spot).filter( Spot.spot_height == 102.34).one() ok_(updated_spot is not None) ok_(old_spot is updated_spot) eq_(updated_spot.spot_height, 102.34) eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')