Ejemplo n.º 1
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)')
Ejemplo n.º 2
0
    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())
Ejemplo n.º 3
0
 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())
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo 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)')
Ejemplo n.º 7
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)')
Ejemplo n.º 8
0
    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)')
Ejemplo n.º 9
0
    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)')
Ejemplo n.º 10
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)')