Esempio n. 1
0
def api_get(url, display=False, *args, **kwargs):
    """
    call api, check response status code, and return json as dict
    """
    tester = app.test_client()
    resp = tester.get(url, *args, **kwargs)

    assert resp.status_code == 200
    return _to_json(resp.data, display)
Esempio n. 2
0
def test_ire_post_no_data():
    """
    when no data is given, we got a 400 error
    """
    tester = app.test_client()
    resp = tester.post('/ire')
    assert resp.status_code == 400

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 0
        assert len(TripUpdate.query.all()) == 0
        assert len(StopTimeUpdate.query.all()) == 0
Esempio n. 3
0
def test_ire_post_no_data():
    """
    when no data is given, we got a 400 error
    """
    tester = app.test_client()
    resp = tester.post('/ire')
    assert resp.status_code == 400

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 0
        assert len(TripUpdate.query.all()) == 0
        assert len(StopTimeUpdate.query.all()) == 0
Esempio n. 4
0
def api_post(url, check=True, *args, **kwargs):
    """
    call api, check response status code, and return json as dict
    """
    tester = app.test_client()
    resp = tester.post(url, *args, **kwargs)

    if check:
        assert resp.status_code == 200
        return _to_json(resp.data)
    else:
        return _to_json(resp.data), resp.status_code
Esempio n. 5
0
def test_gtfs_rt_simple_delay(basic_gtfs_rt_data, mock_rabbitmq):
    """
    test the gtfs-rt post with a simple gtfs-rt

    we have realtime data on only 2 stops, so the model builder should only have 2 stops (even if the VJ
    have 4 stops)

    after the merge, we should have 4 stops (and only 2 delayed)
    """
    tester = app.test_client()
    resp = tester.post('/gtfs_rt', data=basic_gtfs_rt_data.SerializeToString())
    assert resp.status_code == 200

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 4

        trip_update = TripUpdate.find_by_dated_vj('R:vj1', datetime.date(2012, 6, 15))

        assert trip_update

        # navitia's time are in local, but we return UTC time, and the stop is in sherbrooke, so UTC-4h
        first_stop = trip_update.stop_time_updates[0]
        assert first_stop.stop_id == 'StopR1'
        assert first_stop.arrival_status == 'none'
        assert first_stop.arrival_delay == timedelta(0)
        assert first_stop.arrival == datetime.datetime(2012, 6, 15, 14, 00)
        assert first_stop.departure_delay == timedelta(0)
        assert first_stop.departure_status == 'none'
        assert first_stop.departure == datetime.datetime(2012, 6, 15, 14, 00)
        assert first_stop.message is None

        second_stop = trip_update.stop_time_updates[1]
        assert second_stop.stop_id == 'StopR2'
        assert second_stop.arrival_status == 'update'
        # 10:30 in local + 4h to get it in UTC + 1minute of delay
        assert second_stop.arrival == datetime.datetime(2012, 6, 15, 14, 31)
        assert second_stop.arrival_delay == timedelta(minutes=1)
        # even if the GTFS-RT has no information of the departure, it have been also delayed by 1mn
        # for coherence
        assert second_stop.departure == datetime.datetime(2012, 6, 15, 14, 31)
        assert second_stop.departure_delay == timedelta(minutes=1)
        assert second_stop.departure_status == 'none'
        assert second_stop.message is None

        third_stop = trip_update.stop_time_updates[2]
        assert third_stop.stop_id == 'StopR3'
        assert third_stop.arrival_status == 'none'
        assert third_stop.arrival_delay == timedelta(0)
        assert third_stop.arrival == datetime.datetime(2012, 6, 15, 15, 00)
        assert third_stop.departure_delay == timedelta(0)
        assert third_stop.departure_status == 'none'
        assert third_stop.departure == datetime.datetime(2012, 6, 15, 15, 00)
        assert third_stop.message is None

        fourth_stop = trip_update.stop_time_updates[3]
        assert fourth_stop.stop_id == 'StopR4'
        assert fourth_stop.arrival_status == 'update'
        assert fourth_stop.arrival_delay == timedelta(minutes=3)
        assert fourth_stop.arrival == datetime.datetime(2012, 6, 15, 15, 33)
        # even if the GTFS-RT has no information of the departure, it have been also delayed by 3mn
        # for coherence
        assert fourth_stop.departure_delay == timedelta(minutes=3)
        assert fourth_stop.departure_status == 'none'
        assert fourth_stop.departure == datetime.datetime(2012, 6, 15, 15, 33)
        assert fourth_stop.message is None
Esempio n. 6
0
def test_client():
    app.testing = True
    with app.app_context(), app.test_client() as tester:
        yield tester