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_find_by_id():
    with raises(LocationNotFoundException):
        location_id = 10000000
        try:
            dal = LocationDal()
            dal.find_by_id(location_id)
        except LocationNotFoundException as e:
            assert e.location_id == location_id
            assert str(e) == 'No location with id {} was found.'.format(location_id)
            raise
Exemplo n.º 6
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.º 7
0
def read():
    dal = LocationDal()

    page_number = request.args.get('page_number')
    page_size = request.args.get('page_size')

    if is_int(page_number):
        page_number = int(page_number)
    if is_int(page_size):
        page_size = int(page_size)

    locations = dal.find(page_number=page_number, page_size=page_size)

    return jsonify(locations)
Exemplo n.º 8
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.º 9
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
Exemplo n.º 10
0
def read_by_id(location_id):
    dal = LocationDal()

    return jsonify(dal.find_by_id(location_id))
Exemplo n.º 11
0
def delete(location_id):
    dal = LocationDal()

    dal.delete(dal.find_by_id(location_id))

    return jsonify({'result': True})