Exemplo n.º 1
0
def create():
    location = _populate_from_request(Location())

    dal = LocationDal()
    dal.create(location)

    return make_response(jsonify(location), 201)
Exemplo n.º 2
0
def update(location_id):
    dal = LocationDal()

    location = _populate_from_request(Location())
    location.id = location_id

    dal.update(location)

    return jsonify(location)
Exemplo n.º 3
0
def test_create_visit_date_required():
    location = Location(product_id=1, latitude=-85, longitude=94, elevation=600)
    with raises(LocationFieldRequiredException):
        try:
            dal = LocationDal()
            dal.create(location)
        except LocationFieldRequiredException as e:
            assert e.field_name == 'visit_date'
            assert str(e) == 'The visit_date field is required.'
            raise
Exemplo n.º 4
0
def test_create_elevation_required():
    location = Location(product_id=1, latitude=-85, longitude=94, visit_date=datetime.datetime.utcnow())
    with raises(LocationFieldRequiredException):
        try:
            dal = LocationDal()
            dal.create(location)
        except LocationFieldRequiredException as e:
            assert e.field_name == 'elevation'
            assert str(e) == 'The elevation field is required.'
            raise
Exemplo n.º 5
0
def test_update_longitude_required():
    location = Location(location_id=1, product_id=1, latitude=-85, elevation=600, visit_date=datetime.datetime.utcnow())
    with raises(LocationFieldRequiredException):
        try:
            dal = LocationDal()
            dal.update(location)
        except LocationFieldRequiredException as e:
            assert e.field_name == 'longitude'
            assert str(e) == 'The longitude field is required.'
            raise
Exemplo n.º 6
0
def test_create():
        dal = LocationDal()
        expected = Location(product_id=1, latitude=-85, longitude=94, elevation=600, visit_date=datetime.datetime.utcnow())
        assert expected.id is None
        
        dal.create(expected)
        
        assert expected.id is not None
        
        actual = dal.find_by_id(expected.id)
        
        assert expected.id == actual.id
        assert expected.product_id == actual.product_id
        assert expected.latitude == actual.latitude
        assert expected.longitude == actual.longitude
        assert expected.elevation == actual.elevation
Exemplo n.º 7
0
def test_update():
        dal = LocationDal()
        
        location_id = 1
         
        expected = Location(location_id=location_id, product_id=1, latitude=-85, longitude=94, elevation=600, visit_date=datetime.datetime.utcnow())
       
        dal.update(expected)
        
        actual = dal.find_by_id(location_id)
        
        assert expected.id == actual.id
        assert expected.product_id == actual.product_id
        assert expected.latitude == actual.latitude
        assert expected.longitude == actual.longitude
        assert expected.elevation == actual.elevation