Ejemplo n.º 1
0
def test_cots_delayed_then_ok(mock_rabbitmq):
    """
    We delay a stop, then the vj is back on time
    """
    cots_96231 = get_fixture_data('cots_train_96231_delayed.json')
    res = api_post('/cots', data=cots_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
        assert RealTimeUpdate.query.first().status == 'OK'
    check_db_96231_delayed(contributor='realtime.cots')
    assert mock_rabbitmq.call_count == 1

    cots_96231 = get_fixture_data('cots_train_96231_normal.json')
    res = api_post('/cots', data=cots_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_96231_normal(contributor='realtime.cots')
    assert mock_rabbitmq.call_count == 2
Ejemplo n.º 2
0
def test_cancellation_then_delay(navitia_vj):
    """
    we have a cancelled vj in the db, and we receive an update on the 3rd stoptime,
    at the end we have a delayed vj

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db                       -
    update kirin      8:10     9:05-9:10     10:45*
    """
    with app.app_context():
        vju = create_trip_update('70866ce8-0638-4fa1-8556-1ddfa22d09d3',
                                 'vehicle_journey:1',
                                 datetime.date(2015, 9, 8), [],
                                 status='delete')
        rtu = RealTimeUpdate(None, 'ire')
        rtu.id = '10866ce8-0638-4fa1-8556-1ddfa22d09d3'
        rtu.trip_updates.append(vju)
        db.session.add(rtu)
        db.session.commit()

    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:3'},
                           arrival_delay=timedelta(minutes=40),
                           arr_status='update'),
        ]
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        _check_cancellation_then_delay(res)
Ejemplo n.º 3
0
def test_cots_partial_removal_delayed_then_partial_removal_ok(mock_rabbitmq):
    """

    Removing first 5 stops and delay the rest by 10 min,
    then only the first 4 stops are removed, the rest are back and on time
    (no information on 10th stop so it should stay delayed)
    """
    cots_870154 = get_fixture_data(
        'cots_train_870154_partial_removal_delay.json')
    res = api_post('/cots', data=cots_870154)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert RealTimeUpdate.query.first().status == 'OK'
    check_db_870154_partial_removal(contributor='realtime.cots')
    check_db_870154_delay()
    assert mock_rabbitmq.call_count == 1

    cots_870154 = get_fixture_data('cots_train_870154_partial_normal.json')
    res = api_post('/cots', data=cots_870154)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
    check_db_870154_partial_removal(contributor='realtime.cots')
    check_db_870154_normal()
    assert mock_rabbitmq.call_count == 2
Ejemplo n.º 4
0
def test_ire_delayed_then_OK(mock_rabbitmq):
    """
    We delay a stop, then the vj is back on time
    """
    ire_96231 = get_ire_data('train_96231_delayed.xml')
    res = api_post('/ire', data=ire_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_ire_96231_delayed()
    assert mock_rabbitmq.call_count == 1

    ire_96231 = get_ire_data('train_96231_normal.xml')
    res = api_post('/ire', data=ire_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_ire_96231_normal()
    assert mock_rabbitmq.call_count == 2
Ejemplo n.º 5
0
def test_cancellation_then_delay(navitia_vj):
    """
    we have a cancelled vj in the db, and we receive an update on the 3rd stoptime,
    at the end we have a delayed vj

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db                       -
    update kirin      8:10     9:05-9:10     10:45*
    """
    with app.app_context():
        vju = create_trip_update('70866ce8-0638-4fa1-8556-1ddfa22d09d3', 'vehicle_journey:1',
                                 datetime.date(2015, 9, 8), [], status='delete')
        rtu = RealTimeUpdate(None, 'ire')
        rtu.id = '10866ce8-0638-4fa1-8556-1ddfa22d09d3'
        rtu.trip_updates.append(vju)
        db.session.add(rtu)
        db.session.commit()

    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj, datetime.date(2015, 9, 8)), status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:3'}, arrival_delay=timedelta(minutes=40), arr_status='update'),
        ]
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        _check_cancellation_then_delay(res)
Ejemplo n.º 6
0
def test_handle_new_trip_out_of_order(navitia_vj):
    """
    We have one vj with only one stop time updated, but it's not the first
    so we have to reorder the stop times in the resulting trip_update
    """
    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(navitia_vj, datetime.date(2015, 9, 8))
        trip_update.vj = vj
        st = StopTimeUpdate({'id': 'sa:2'}, departure=_dt("9:50"), arrival=_dt("9:49"))
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates.append(st)
        res = handle(real_time_update, [trip_update])

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert len(trip_update.stop_time_updates) == 3
        assert trip_update.stop_time_updates[0].stop_id == 'sa:1'
        assert trip_update.stop_time_updates[0].departure == _dt("8:10")
        assert trip_update.stop_time_updates[0].arrival == None

        assert trip_update.stop_time_updates[1].stop_id == 'sa:2'
        assert trip_update.stop_time_updates[1].departure == _dt("9:50")
        assert trip_update.stop_time_updates[1].arrival == _dt("9:49")

        assert trip_update.stop_time_updates[2].stop_id == 'sa:3'
        assert trip_update.stop_time_updates[2].departure == None
        assert trip_update.stop_time_updates[2].arrival == _dt("10:05")
Ejemplo n.º 7
0
def test_no_purge_rtu(mock_rabbitmq):
    with app.app_context():
        create_rt_update_and_trip_update(
            RTU_ID,
            COTS_CONTRIBUTOR_ID,
            VJ_ID,
            TRIP_ID,
            date.today() - timedelta(days=DEFAULT_DAYS_TO_KEEP_RT_UPDATE + 1),
        )
        db.session.commit()

        # Check there's really something before purge
        assert TripUpdate.query.count() == 1
        assert VehicleJourney.query.count() == 1
        assert StopTimeUpdate.query.count() == 3
        assert db.session.execute(
            "select * from associate_realtimeupdate_tripupdate").rowcount == 1
        assert RealTimeUpdate.query.count() == 1

        contributor = Contributor.query.filter_by(
            id=COTS_CONTRIBUTOR_ID).first()
        # Should not purge RealTimeUpdate since linked TripUpdate is not removed
        contributor.nb_days_to_keep_trip_update = PG_MAX_INT
        contributor.nb_days_to_keep_rt_update = DEFAULT_DAYS_TO_KEEP_RT_UPDATE

        purge()

        assert TripUpdate.query.count() == 1
        assert VehicleJourney.query.count() == 1
        assert StopTimeUpdate.query.count() == 3
        assert db.session.execute(
            "select * from associate_realtimeupdate_tripupdate").rowcount == 1
        assert RealTimeUpdate.query.count() == 1
Ejemplo n.º 8
0
def test_multiple_delays_in_2_updates(navitia_vj):
    """
    same test as test_multiple_delays, but with nothing in the db and with 2 trip updates
    """
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj, datetime.date(2015, 9, 8)), status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:1'}, departure_delay=timedelta(minutes=5), dep_status='update'),
        ]
        handle(real_time_update, [trip_update], 'kisio-digital')

        trip_update = TripUpdate(VehicleJourney(navitia_vj, datetime.date(2015, 9, 8)), status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:1'}, departure_delay=timedelta(minutes=10), dep_status='update'),
            StopTimeUpdate({'id': 'sa:2'}, arrival_delay=timedelta(minutes=2), arr_status='update'),
        ]
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        _check_multiples_delay(res)
        # we also check that there is what we want in the db
        db_trip_updates = res.query.from_self(TripUpdate).all()
        assert len(db_trip_updates) == 1
        assert db_trip_updates[0].status == 'update'
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(StopTimeUpdate.query.all()) == 3
Ejemplo n.º 9
0
def setup_database():
    """
    we create two realtime_updates with the same vj but for different date
    and return a vj for navitia
    """
    with app.app_context():
        vju = create_trip_update('70866ce8-0638-4fa1-8556-1ddfa22d09d3', 'vehicle_journey:1', datetime.date(2015, 9, 8),
                [
                    {'id': 'sa:1', 'departure': _dt("8:15"), 'arrival': None, 'departure_status': 'update', 'arrival_status': 'none'},
                    {'id': 'sa:2', 'departure': _dt("9:10"), 'arrival': _dt("9:05"), 'departure_status': 'none', 'arrival_status': 'none'},
                    {'id': 'sa:3', 'departure': None, 'arrival': _dt("10:05"), 'departure_status': 'none', 'arrival_status': 'none'},
                    ])
        rtu = RealTimeUpdate(None, 'ire')
        rtu.id = '10866ce8-0638-4fa1-8556-1ddfa22d09d3'
        rtu.trip_updates.append(vju)
        db.session.add(rtu)
        vju = create_trip_update('70866ce8-0638-4fa1-8556-1ddfa22d09d4', 'vehicle_journey:1', datetime.date(2015, 9, 7),
                [
                    {'id': 'sa:1', 'departure': _dt("8:35", day=7), 'arrival': None, 'departure_status': 'update', 'arrival_status': 'none'},
                    {'id': 'sa:2', 'departure': _dt("9:40", day=7), 'arrival': _dt("9:35", day=7), 'departure_status': 'update', 'arrival_status': 'update'},
                    {'id': 'sa:3', 'departure': None, 'arrival': _dt("10:35", day=7), 'departure_status': 'none', 'arrival_status': 'update'},
                    ])
        rtu = RealTimeUpdate(None, 'ire')
        rtu.id = '20866ce8-0638-4fa1-8556-1ddfa22d09d3'
        rtu.trip_updates.append(vju)
        db.session.add(rtu)
        db.session.commit()
Ejemplo n.º 10
0
def test_multiple_delays(setup_database, navitia_vj):
    """
    We receive a delay on the first and second stoptimes of a vj, and there was already some delay on the
    first st of this vj

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db          8:15*    9:05-9:10     10:05
    update kirin      8:20*   *9:07-9:10     10:05
    """
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        trip_update = TripUpdate(_create_db_vj(navitia_vj), status="update", contributor_id=contributor.id)
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates = [
            # Note: the delay is based of the navitia's vj
            StopTimeUpdate({"id": "sa:1"}, departure_delay=timedelta(minutes=10), dep_status="update"),
            StopTimeUpdate({"id": "sa:2"}, arrival_delay=timedelta(minutes=2), arr_status="update"),
        ]
        res, _ = handle(builder, real_time_update, [trip_update])

        _check_multiples_delay(res)

        # we also check that there is what we want in the db
        db_trip_updates = res.query.from_self(TripUpdate).all()
        assert len(db_trip_updates) == 2
        for tu in db_trip_updates:
            assert tu.status == "update"
        assert len(RealTimeUpdate.query.all()) == 3  # 2 already in db, one new update
        assert len(StopTimeUpdate.query.all()) == 6  # 3 st * 2 vj in the db
Ejemplo n.º 11
0
def test_cots_train_trip_removal(mock_navitia_fixture):
    """
    test the import of cots_train_6113_trip_removal.json
    """

    input_train_trip_removed = get_fixture_data(
        'cots_train_6113_trip_removal.json')

    with app.app_context():
        rt_update = model.RealTimeUpdate(input_train_trip_removed,
                                         connector='cots',
                                         contributor='realtime.cots')
        trip_updates = KirinModelBuilder(dumb_nav_wrapper()).build(rt_update)
        rt_update.trip_updates = trip_updates
        db.session.add(rt_update)
        db.session.commit()

        assert len(trip_updates) == 1
        trip_up = trip_updates[0]
        assert trip_up.vj.navitia_trip_id == 'trip:OCETGV-87686006-87751008-2:25768'
        assert trip_up.vj_id == trip_up.vj.id
        assert trip_up.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(trip_up.stop_time_updates) == 0
        # verify trip_update effect:
        assert trip_up.effect == 'NO_SERVICE'
Ejemplo n.º 12
0
def setup_database():
    """
    we create two realtime_updates with the same vj but for different date
    and return a vj for navitia
    """
    with app.app_context():
        vj1 = model.VehicleJourney({'trip': {'id': 'vj:1'}}, date(2015, 11, 4))
        vj2 = model.VehicleJourney({'trip': {'id': 'vj:2'}}, date(2015, 11, 4))
        vj3 = model.VehicleJourney({'trip': {'id': 'vj:3'}}, date(2015, 11, 4))
        tu1 = model.TripUpdate(vj1, contributor='realtime.ire')
        tu2 = model.TripUpdate(vj2, contributor='realtime.ire')
        tu3 = model.TripUpdate(vj3, contributor='realtime.timeo')
        rtu1 = model.RealTimeUpdate(None, 'ire')
        rtu1.created_at = datetime(2015, 11, 4, 6, 32)
        rtu1.trip_updates.append(tu1)
        model.db.session.add(rtu1)
        rtu2 = model.RealTimeUpdate(None, 'ire')
        rtu2.created_at = datetime(2015, 11, 4, 7, 32)
        rtu2.trip_updates.append(tu2)
        model.db.session.add(rtu2)

        rtu3 = model.RealTimeUpdate(None, 'ire')
        rtu3.created_at = datetime(2015, 11, 4, 7, 42)
        rtu3.trip_updates.append(tu3)
        model.db.session.add(rtu3)

        model.db.session.commit()
Ejemplo n.º 13
0
def test_get_action_on_trip_delete(mock_navitia_fixture):
    with app.app_context():
        # Delete the recently added trip followed by add: should be FIRST_TIME_ADDED
        contributor = model.Contributor(
            id=COTS_CONTRIBUTOR_ID,
            navitia_coverage=None,
            connector_type=ConnectorType.cots.value)
        builder = KirinModelBuilder(contributor)
        input_trip_add = get_fixture_data("cots_train_151515_added_trip.json")
        wrap_build(builder, input_trip_add)
        input_trip_delete = get_fixture_data(
            "cots_train_151515_deleted_trip_with_delay_and_stop_time_added.json"
        )
        wrap_build(builder, input_trip_delete)

        input_added_trip = get_fixture_data(
            "cots_train_151515_added_trip.json")
        json_data = json.loads(input_added_trip)
        dict_version = model_maker.get_value(json_data, "nouvelleVersion")
        train_numbers = model_maker.get_value(dict_version, "numeroCourse")
        pdps = model_maker._retrieve_interesting_pdp(
            model_maker.get_value(dict_version, "listePointDeParcours"))

        action_on_trip = model_maker._get_action_on_trip(
            train_numbers, dict_version, pdps)
        assert action_on_trip == ActionOnTrip.FIRST_TIME_ADDED.name
Ejemplo n.º 14
0
def check_db_ire_JOHN_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 2
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip1_removal = TripUpdate.find_by_dated_vj('trip:OCETGV-87686006-87751008-2:25768',
                                                      datetime.date(2015, 9, 21))
        assert db_trip1_removal

        assert db_trip1_removal.vj.navitia_trip_id == 'trip:OCETGV-87686006-87751008-2:25768'
        assert db_trip1_removal.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip1_removal.vj_id == db_trip1_removal.vj.id
        assert db_trip1_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip1_removal.stop_time_updates) == 0


        db_trip2_removal = TripUpdate.find_by_dated_vj('trip:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime.date(2015, 9, 21))
        assert db_trip2_removal

        assert db_trip2_removal.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip2_removal.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip2_removal.vj_id == db_trip2_removal.vj.id
        assert db_trip2_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip2_removal.stop_time_updates) == 0
Ejemplo n.º 15
0
def test_cots_train_trip_removal(mock_navitia_fixture):
    """
    test the import of cots_train_6113_trip_removal.json
    """

    input_train_trip_removed = get_fixture_data(
        "cots_train_6113_trip_removal.json")

    with app.app_context():
        contributor = model.Contributor(
            id=COTS_CONTRIBUTOR_ID,
            navitia_coverage=None,
            connector_type=ConnectorType.cots.value)
        wrap_build(KirinModelBuilder(contributor), input_train_trip_removed)

        trip_updates = TripUpdate.query.all()
        assert len(trip_updates) == 1
        trip_up = trip_updates[0]
        assert trip_up.vj.navitia_trip_id == "trip:OCETGV-87686006-87751008-2:25768"
        assert trip_up.vj_id == trip_up.vj.id
        assert trip_up.status == "delete"
        # full trip removal : no stop_time to precise
        assert len(trip_up.stop_time_updates) == 0
        # verify trip_update effect:
        assert trip_up.effect == "NO_SERVICE"
Ejemplo n.º 16
0
def test_siri_et_xml_tn_trip_removal(mock_rabbitmq):
    """
    simple trip removal post
    """
    path = os.path.join(os.path.dirname(__file__), "..", "fixtures",
                        "siri_et_xml_tn", "trip_removal.xml")
    raw_feed = ""
    with open(path, "r") as f:
        raw_feed = f.read()
    assert raw_feed

    res = api_post(
        "/contributors/{}/feeds".format(SIRI_ET_XML_TN_CONTRIBUTOR_ID),
        data=raw_feed)
    assert "'siri-et-xml-tn' feed processed" in res.get("message")

    with app.app_context():
        assert RealTimeUpdate.query.count() == 1
        assert TripUpdate.query.count() == 1

        db_trip_removal = TripUpdate.query.first()
        assert db_trip_removal
        assert db_trip_removal.vj.navitia_trip_id == "IDFM:TN:SNCF:64b9c30c-85fe-4e06-892a-7a3382ac540c"
        assert db_trip_removal.vj.start_timestamp == datetime(
            2021, 11, 22, 14, 6, 10)
        assert db_trip_removal.status == ModificationType.delete.name
        assert db_trip_removal.effect == TripEffect.NO_SERVICE.name

    assert mock_rabbitmq.call_count == 1
Ejemplo n.º 17
0
def test_handle_new_trip_out_of_order(navitia_vj):
    """
    We have one vj with only one stop time updated, but it's not the first
    so we have to reorder the stop times in the resulting trip_update
    """
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='update')
        st = StopTimeUpdate({'id': 'sa:2'},
                            departure_delay=timedelta(minutes=40),
                            dep_status='update',
                            arrival_delay=timedelta(minutes=44),
                            arr_status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates.append(st)
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert len(trip_update.stop_time_updates) == 3

        assert trip_update.stop_time_updates[0].stop_id == 'sa:1'
        assert trip_update.stop_time_updates[0].departure == _dt("8:10")
        assert trip_update.stop_time_updates[0].arrival == _dt("8:10")

        assert trip_update.stop_time_updates[1].stop_id == 'sa:2'
        assert trip_update.stop_time_updates[1].departure == _dt("9:50")
        assert trip_update.stop_time_updates[1].arrival == _dt("9:49")

        assert trip_update.stop_time_updates[2].stop_id == 'sa:3'
        assert trip_update.stop_time_updates[2].departure == _dt("10:05")
        assert trip_update.stop_time_updates[2].arrival == _dt("10:05")
Ejemplo n.º 18
0
def test_populate_pb_with_full_dataset():
    """
    VJ cancelation
    """
    navitia_vj = {'trip': {'id': 'vehicle_journey:1'}}

    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(navitia_vj, datetime.date(2015, 9, 8))
        trip_update.vj = vj
        trip_update.status = 'delete'
        trip_update.message = 'Message Test'
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.contributor = 'kisio-digital'
        real_time_update.trip_updates.append(trip_update)

        db.session.add(real_time_update)
        db.session.commit()

        feed_entity = convert_to_gtfsrt(real_time_update.trip_updates, gtfs_realtime_pb2.FeedHeader.FULL_DATASET)

        assert feed_entity.header.incrementality == gtfs_realtime_pb2.FeedHeader.FULL_DATASET
        assert feed_entity.header.gtfs_realtime_version == '1'
        pb_trip_update = feed_entity.entity[0].trip_update
        assert pb_trip_update.trip.trip_id == 'vehicle_journey:1'
        assert pb_trip_update.trip.start_date == '20150908'
        assert pb_trip_update.HasExtension(kirin_pb2.trip_message) == True
        assert pb_trip_update.Extensions[kirin_pb2.trip_message] == 'Message Test'
        assert pb_trip_update.trip.schedule_relationship == gtfs_realtime_pb2.TripDescriptor.CANCELED

        assert pb_trip_update.trip.HasExtension(kirin_pb2.contributor) == True
        assert pb_trip_update.trip.Extensions[kirin_pb2.contributor] == 'kisio-digital'

        assert len(feed_entity.entity[0].trip_update.stop_time_update) == 0
Ejemplo n.º 19
0
def check_db_john_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 2
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip1_removal = TripUpdate.find_by_dated_vj(
            'trip:OCETGV-87686006-87751008-2:25768',
            datetime(2015, 9, 21, 10, 37, tzinfo=utc))
        assert db_trip1_removal

        assert db_trip1_removal.vj.navitia_trip_id == 'trip:OCETGV-87686006-87751008-2:25768'
        assert db_trip1_removal.vj.get_start_timestamp() == datetime(
            2015, 9, 21, 10, 37, tzinfo=utc)
        assert db_trip1_removal.vj_id == db_trip1_removal.vj.id
        assert db_trip1_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip1_removal.stop_time_updates) == 0

        db_trip2_removal = TripUpdate.find_by_dated_vj(
            'trip:OCETrainTER-87212027-85000109-3:11859',
            datetime(2015, 9, 21, 15, 21, tzinfo=utc))
        assert db_trip2_removal

        assert db_trip2_removal.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip2_removal.vj.get_start_timestamp() == datetime(
            2015, 9, 21, 15, 21, tzinfo=utc)
        assert db_trip2_removal.vj_id == db_trip2_removal.vj.id
        assert db_trip2_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip2_removal.stop_time_updates) == 0
Ejemplo n.º 20
0
def check_db_john_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 2
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip1_removal = TripUpdate.find_by_dated_vj(
            "trip:OCETGV-87686006-87751008-2:25768", datetime(2015, 9, 21, 13, 37)
        )
        assert db_trip1_removal

        assert db_trip1_removal.vj.navitia_trip_id == "trip:OCETGV-87686006-87751008-2:25768"
        assert db_trip1_removal.vj.start_timestamp == datetime(2015, 9, 21, 13, 37)
        assert db_trip1_removal.vj_id == db_trip1_removal.vj.id
        assert db_trip1_removal.status == "delete"
        assert db_trip1_removal.effect == "NO_SERVICE"
        # full trip removal : no stop_time to precise
        assert len(db_trip1_removal.stop_time_updates) == 0

        db_trip2_removal = TripUpdate.find_by_dated_vj(
            "trip:OCETrainTER-87212027-85000109-3:11859", datetime(2015, 9, 21, 15, 21)
        )
        assert db_trip2_removal

        assert db_trip2_removal.vj.navitia_trip_id == "trip:OCETrainTER-87212027-85000109-3:11859"
        assert db_trip2_removal.vj.start_timestamp == datetime(2015, 9, 21, 15, 21)
        assert db_trip2_removal.vj_id == db_trip2_removal.vj.id
        assert db_trip2_removal.status == "delete"
        assert db_trip2_removal.effect == "NO_SERVICE"
        # full trip removal : no stop_time to precise
        assert len(db_trip2_removal.stop_time_updates) == 0
Ejemplo n.º 21
0
def test_cancellation_then_delay_in_2_updates(navitia_vj):
    """
    same as test_cancellation_then_delay, but with a clear db and in 2 updates
    """
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='delete')
        trip_update.stop_time_updates = []
        real_time_update = RealTimeUpdate(raw_data=None,
                                          connector='ire',
                                          contributor='realtime.ire')
        handle(real_time_update, [trip_update], 'kisio-digital')

        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='update')
        real_time_update = RealTimeUpdate(raw_data=None,
                                          connector='ire',
                                          contributor='realtime.ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:3'},
                           arrival_delay=timedelta(minutes=40),
                           arr_status='update',
                           order=2),
        ]
        res, _ = handle(real_time_update, [trip_update], 'kisio-digital')

        _check_cancellation_then_delay(res)
Ejemplo n.º 22
0
def check_db_ire_96231_delayed(motif_externe_is_null=False):
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 6
        db_trip_delayed = TripUpdate.find_by_dated_vj(
            'trip:OCETrainTER-87212027-85000109-3:11859',
            datetime.datetime(2015, 9, 21, 15, 21, tzinfo=utc))
        assert db_trip_delayed

        assert db_trip_delayed.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip_delayed.vj.get_start_timestamp() == datetime.datetime(
            2015, 9, 21, 15, 21, tzinfo=utc)
        assert db_trip_delayed.vj_id == db_trip_delayed.vj.id
        assert db_trip_delayed.status == 'update'
        # 6 stop times must have been created
        assert len(db_trip_delayed.stop_time_updates) == 6

        # the first stop (in Strasbourg) is not in the IRE, only on navitia's base schedule
        # no delay then, only base schedule
        # Navitia's time are in local, so departure 17h21 in paris is 15h21 in UTC
        first_st = db_trip_delayed.stop_time_updates[0]
        assert first_st.stop_id == 'stop_point:OCE:SP:TrainTER-87212027'
        assert first_st.arrival == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.arrival_status == 'none'
        assert first_st.arrival_delay == timedelta(0)
        assert first_st.departure == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.departure_delay == timedelta(0)
        assert first_st.departure_status == 'none'
        assert first_st.message is None

        second_st = db_trip_delayed.stop_time_updates[1]
        assert second_st.stop_id == 'stop_point:OCE:SP:TrainTER-87214056'
        assert second_st.arrival == datetime.datetime(2015, 9, 21, 15, 38)
        assert second_st.arrival_status == 'none'
        assert second_st.arrival_delay == timedelta(0)
        assert second_st.departure == datetime.datetime(2015, 9, 21, 15, 55)
        assert second_st.departure_delay == timedelta(minutes=15)
        assert second_st.departure_status == 'update'
        if motif_externe_is_null:
            assert second_st.message is None
        else:
            assert second_st.message == 'Affluence exceptionnelle de voyageurs'

        # last stop is gare de Basel-SBB, delay's only at the arrival
        last_st = db_trip_delayed.stop_time_updates[-1]
        assert last_st.stop_id == 'stop_point:OCE:SP:TrainTER-85000109'
        assert last_st.arrival == datetime.datetime(2015, 9, 21, 16, 54)
        assert last_st.arrival_status == 'update'
        assert last_st.arrival_delay == timedelta(minutes=15)
        #The departure is consistent with arrival
        assert last_st.departure == datetime.datetime(2015, 9, 21, 16, 54)
        assert last_st.departure_delay == timedelta(minutes=15)
        assert last_st.departure_status == 'none'
        if motif_externe_is_null:
            assert second_st.message is None
        else:
            assert second_st.message == 'Affluence exceptionnelle de voyageurs'

        assert db_trip_delayed.contributor == 'realtime.ire'
Ejemplo n.º 23
0
def check_db_ire_96231_normal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 6
        db_trip_delayed = TripUpdate.find_by_dated_vj(
            'trip:OCETrainTER-87212027-85000109-3:11859',
            datetime.datetime(2015, 9, 21, 15, 21, tzinfo=utc))
        assert db_trip_delayed

        assert db_trip_delayed.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip_delayed.vj.get_start_timestamp() == datetime.datetime(
            2015, 9, 21, 15, 21, tzinfo=utc)
        assert db_trip_delayed.vj_id == db_trip_delayed.vj.id
        assert db_trip_delayed.status == 'update'
        # 6 stop times must have been created
        assert len(db_trip_delayed.stop_time_updates) == 6

        # the first stop (in Strasbourg) is not in the IRE, only on navitia's base schedule
        # no delay then, only base schedule
        # Navitia's time are in local, so departure 17h21 in paris is 15h21 in UTC
        first_st = db_trip_delayed.stop_time_updates[0]
        assert first_st.stop_id == 'stop_point:OCE:SP:TrainTER-87212027'
        assert first_st.arrival == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.arrival_status == 'none'
        assert first_st.arrival_delay == timedelta(0)
        assert first_st.departure == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.departure_delay == timedelta(0)
        assert first_st.departure_status == 'none'
        assert first_st.message is None

        #the departure time has been updated with a delay at 0
        second_st = db_trip_delayed.stop_time_updates[1]
        assert second_st.stop_id == 'stop_point:OCE:SP:TrainTER-87214056'
        assert second_st.arrival == datetime.datetime(2015, 9, 21, 15, 38)
        assert second_st.arrival_status == 'none'
        assert second_st.arrival_delay == timedelta(0)
        assert second_st.departure == datetime.datetime(2015, 9, 21, 15, 40)
        assert second_st.departure_delay == timedelta(minutes=0)
        assert second_st.departure_status == 'update'
        assert second_st.message == 'Affluence exceptionnelle de voyageurs'

        # last stop is gare de Basel-SBB, the arrival is also updated with a delay at 0
        last_st = db_trip_delayed.stop_time_updates[-1]
        assert last_st.stop_id == 'stop_point:OCE:SP:TrainTER-85000109'
        assert last_st.arrival == datetime.datetime(2015, 9, 21, 16, 39)
        assert last_st.arrival_status == 'update'
        assert last_st.arrival_delay == timedelta(minutes=0)
        #The departure should be the same has the theroric one
        #except that it's not the case, we have messed with it when the vj was delayed, but we didn't put it back
        #like it was when the train catch up is delay
        try:
            assert last_st.departure == datetime.datetime(2015, 9, 21, 16, 39)
            assert last_st.departure_delay == timedelta(minutes=0)
            assert last_st.departure_status == 'none'
            assert last_st.message == 'Affluence exceptionnelle de voyageurs'
        except AssertionError:
            pass  # xfail: we don't change back the departure :(

        assert db_trip_delayed.contributor == 'realtime.ire'
Ejemplo n.º 24
0
def test_past_midnight():
    """
    integration of a past midnight
    """
    navitia_vj = {
        "trip": {"id": "vehicle_journey:1"},
        "stop_times": [
            {
                "utc_arrival_time": datetime.time(22, 10),
                "utc_departure_time": datetime.time(22, 15),
                "stop_point": {"id": "sa:1"},
            },
            # arrive at sa:2 at 23:10 and leave the day after
            {
                "utc_arrival_time": datetime.time(23, 10),
                "utc_departure_time": datetime.time(2, 15),
                "stop_point": {"id": "sa:2", "stop_area": {"timezone": "UTC"}},
            },
            {
                "utc_arrival_time": datetime.time(3, 20),
                "utc_departure_time": datetime.time(3, 25),
                "stop_point": {"id": "sa:3", "stop_area": {"timezone": "UTC"}},
            },
        ],
    }
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        vj = VehicleJourney(
            navitia_vj, datetime.datetime(2015, 9, 8, 21, 15, 0), datetime.datetime(2015, 9, 9, 4, 20, 0)
        )
        trip_update = TripUpdate(vj, status="update", contributor_id=contributor.id)
        st = StopTimeUpdate({"id": "sa:2"}, departure_delay=timedelta(minutes=31), dep_status="update", order=1)
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates.append(st)
        res, _ = handle(builder, real_time_update, [trip_update])

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == "update"
        assert len(trip_update.stop_time_updates) == 3

        assert trip_update.stop_time_updates[0].stop_id == "sa:1"
        assert trip_update.stop_time_updates[0].arrival == _dt("22:10")
        assert trip_update.stop_time_updates[0].departure == _dt("22:15")

        assert trip_update.stop_time_updates[1].stop_id == "sa:2"
        assert trip_update.stop_time_updates[1].arrival == _dt("23:10")
        assert trip_update.stop_time_updates[1].arrival_delay == timedelta(0)
        assert trip_update.stop_time_updates[1].departure == _dt("2:46", day=9)
        assert trip_update.stop_time_updates[1].departure_delay == timedelta(minutes=31)

        assert trip_update.stop_time_updates[2].stop_id == "sa:3"
        assert trip_update.stop_time_updates[2].arrival == _dt("3:51", day=9)
        assert trip_update.stop_time_updates[2].arrival_delay == timedelta(minutes=31)
        assert trip_update.stop_time_updates[2].departure == _dt("3:56", day=9)
        assert trip_update.stop_time_updates[2].departure_delay == timedelta(minutes=31)
Ejemplo n.º 25
0
def test_gtfs_model_builder(basic_gtfs_rt_data):
    """
    test the model builder 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)
    """
    with app.app_context():
        data = ''
        rt_update = RealTimeUpdate(data, connector='gtfs-rt')
        trip_updates = gtfs_rt.KirinModelBuilder(dumb_nav_wrapper()).build(rt_update, basic_gtfs_rt_data)

        # we associate the trip_update manually for sqlalchemy to make the links
        rt_update.trip_updates = trip_updates
        db.session.add(rt_update)
        db.session.commit()

        assert len(trip_updates) == 1
        assert len(trip_updates[0].stop_time_updates) == 2

        second_stop = trip_updates[0].stop_time_updates[0]
        assert second_stop.stop_id == 'StopR2'
        assert second_stop.arrival_status == 'update'
        assert second_stop.arrival_delay == timedelta(minutes=1)
        assert second_stop.departure_delay is None
        assert second_stop.departure_status == 'none'
        assert second_stop.message is None

        fourth_stop = trip_updates[0].stop_time_updates[1]
        assert fourth_stop.stop_id == 'StopR4'
        assert fourth_stop.arrival_status == 'update'
        assert fourth_stop.arrival_delay == timedelta(minutes=3)
        assert fourth_stop.departure_delay is None
        assert fourth_stop.departure_status == 'none'
        assert fourth_stop.message is None
Ejemplo n.º 26
0
def test_delays_then_cancellation_in_2_updates(navitia_vj):
    """
    Same test as above, but with nothing in the db, and with 2 updates
    """
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            StopTimeUpdate({'id': 'sa:1'},
                           departure_delay=timedelta(minutes=5),
                           dep_status='update'),
        ]
        handle(real_time_update, [trip_update], 'kisio-digital')

        trip_update = TripUpdate(VehicleJourney(navitia_vj,
                                                datetime.date(2015, 9, 8)),
                                 status='delete')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == 'delete'
        assert len(trip_update.stop_time_updates) == 0
        assert len(trip_update.real_time_updates) == 2
Ejemplo n.º 27
0
def test_delays_then_cancellation(setup_database, navitia_vj):
    """
    We have a delay on the first st of a vj in the db and we receive a cancellation on this vj,
    we should have a cancelled vj in the end

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db          8:15*    9:05-9:10     10:05
    update kirin                   -
    """
    with app.app_context():
        trip_update = TripUpdate(_create_db_vj(navitia_vj),
                                 status="delete",
                                 contributor_id=COTS_CONTRIBUTOR_ID)
        real_time_update = make_rt_update(
            raw_data=None,
            connector_type=ConnectorType.cots.value,
            contributor_id=COTS_CONTRIBUTOR_ID)
        res, _ = handle(real_time_update, [trip_update],
                        contributor_id=COTS_CONTRIBUTOR_ID,
                        is_new_complete=False)

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == "delete"
        assert len(trip_update.stop_time_updates) == 0
        assert len(trip_update.real_time_updates) == 2
Ejemplo n.º 28
0
def test_cancellation_then_delay_in_2_updates(navitia_vj):
    """
    same as test_cancellation_then_delay, but with a clear db and in 2 updates
    """
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        trip_update = TripUpdate(
            _create_db_vj(navitia_vj),
            status="delete",
            effect=TripEffect.NO_SERVICE.name,
            contributor_id=contributor.id,
        )
        trip_update.stop_time_updates = []
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        handle(builder, real_time_update, [trip_update])

        trip_update = TripUpdate(
            _create_db_vj(navitia_vj),
            status="none",
            effect=TripEffect.UNKNOWN_EFFECT.name,
            contributor_id=contributor.id,
        )
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates = [
            StopTimeUpdate({"id": "sa:1"}, arr_status="none", dep_status="none", order=0),
            StopTimeUpdate({"id": "sa:2"}, arr_status="none", dep_status="none", order=1),
            StopTimeUpdate({"id": "sa:3"}, arrival_delay=timedelta(minutes=40), arr_status="update", order=2),
        ]
        res, _ = handle(builder, real_time_update, [trip_update])

        _check_cancellation_then_delay(res)
Ejemplo n.º 29
0
def check_db_ire_JOHN_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 2
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip1_removal = TripUpdate.find_by_dated_vj('trip:OCETGV-87686006-87751008-2:25768',
                                                      datetime.date(2015, 9, 21))
        assert db_trip1_removal

        assert db_trip1_removal.vj.navitia_trip_id == 'trip:OCETGV-87686006-87751008-2:25768'
        assert db_trip1_removal.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip1_removal.vj_id == db_trip1_removal.vj.id
        assert db_trip1_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip1_removal.stop_time_updates) == 0


        db_trip2_removal = TripUpdate.find_by_dated_vj('trip:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime.date(2015, 9, 21))
        assert db_trip2_removal

        assert db_trip2_removal.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip2_removal.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip2_removal.vj_id == db_trip2_removal.vj.id
        assert db_trip2_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip2_removal.stop_time_updates) == 0
Ejemplo n.º 30
0
def test_delays_then_cancellation(setup_database, navitia_vj):
    """
    We have a delay on the first st of a vj in the db and we receive a cancellation on this vj,
    we should have a cancelled vj in the end

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db          8:15*    9:05-9:10     10:05
    update kirin                   -
    """
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        trip_update = TripUpdate(
            _create_db_vj(navitia_vj),
            status="delete",
            effect=TripEffect.NO_SERVICE.name,
            contributor_id=contributor.id,
        )
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        res, _ = handle(builder, real_time_update, [trip_update])

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == "delete"
        assert len(trip_update.stop_time_updates) == 3
        for stu in trip_update.stop_time_updates:
            assert stu.arrival_status == "delete"
            assert stu.departure_status == "delete"
        assert len(trip_update.real_time_updates) == 2
Ejemplo n.º 31
0
def test_delays_then_cancellation_in_2_updates(navitia_vj):
    """
    Same test as above, but with nothing in the db, and with 2 updates
    """
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        trip_update = TripUpdate(_create_db_vj(navitia_vj), status="update", contributor_id=contributor.id)
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates = [
            StopTimeUpdate({"id": "sa:1"}, departure_delay=timedelta(minutes=5), dep_status="update")
        ]
        handle(builder, real_time_update, [trip_update])

        trip_update = TripUpdate(
            _create_db_vj(navitia_vj),
            status="delete",
            effect=TripEffect.NO_SERVICE.name,
            contributor_id=contributor.id,
        )
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        res, _ = handle(builder, real_time_update, [trip_update])

        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == "delete"
        assert len(trip_update.stop_time_updates) == 3
        for stu in trip_update.stop_time_updates:
            assert stu.arrival_status == "delete"
            assert stu.departure_status == "delete"
        assert len(trip_update.real_time_updates) == 2
Ejemplo n.º 32
0
def test_multiple_delays(setup_database, navitia_vj):
    """
    We receive a delay on the first and second stoptimes of a vj, and there was already some delay on the
    first st of this vj

                      sa:1        sa:2       sa:3
    VJ navitia        8:10     9:05-9:10     10:05
    VJ in db          8:15*    9:05-9:10     10:05
    update kirin      8:20*   *9:07-9:10     10:05
    """
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj, datetime.date(2015, 9, 8)), status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates = [
            # Note: the delay is based of the navitia's vj
            StopTimeUpdate({'id': 'sa:1'}, departure_delay=timedelta(minutes=10), dep_status='update'),
            StopTimeUpdate({'id': 'sa:2'}, arrival_delay=timedelta(minutes=2), arr_status='update'),
        ]
        res = handle(real_time_update, [trip_update], 'kisio-digital')

        _check_multiples_delay(res)

        # we also check that there is what we want in the db
        db_trip_updates = res.query.from_self(TripUpdate).all()
        assert len(db_trip_updates) == 2
        for tu in db_trip_updates:
            assert tu.status == 'update'
        assert len(RealTimeUpdate.query.all()) == 3  # 2 already in db, one new update
        assert len(StopTimeUpdate.query.all()) == 6  # 3 st * 2 vj in the db
Ejemplo n.º 33
0
def test_multiple_delays_in_2_updates(navitia_vj):
    """
    same test as test_multiple_delays, but with nothing in the db and with 2 trip updates
    """
    with app.app_context():
        contributor = model.Contributor(
            id=GTFS_CONTRIBUTOR_ID, navitia_coverage=None, connector_type=ConnectorType.gtfs_rt.value
        )
        builder = kirin.poller_workers.gtfs_rt.KirinModelBuilder(contributor)

        trip_update = TripUpdate(_create_db_vj(navitia_vj), status="update", contributor_id=contributor.id)
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates = [
            StopTimeUpdate({"id": "sa:1"}, departure_delay=timedelta(minutes=5), dep_status="update")
        ]
        handle(builder, real_time_update, [trip_update])

        trip_update = TripUpdate(_create_db_vj(navitia_vj), status="update", contributor_id=contributor.id)
        real_time_update = make_rt_update(raw_data=None, contributor_id=contributor.id)
        trip_update.stop_time_updates = [
            StopTimeUpdate({"id": "sa:1"}, departure_delay=timedelta(minutes=10), dep_status="update"),
            StopTimeUpdate({"id": "sa:2"}, arrival_delay=timedelta(minutes=2), arr_status="update"),
        ]
        res, _ = handle(builder, real_time_update, [trip_update])

        _check_multiples_delay(res)
        # we also check that there is what we want in the db
        db_trip_updates = res.query.from_self(TripUpdate).all()
        assert len(db_trip_updates) == 1
        assert db_trip_updates[0].status == "update"
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(StopTimeUpdate.query.all()) == 3
Ejemplo n.º 34
0
def test_cots_trip_unknown_vj(mock_rabbitmq):
    """
    a trip with a parity has been impacted, but the train 6112 is not known by navitia
    there should be only the train 6113 impacted
    """
    cots_6113 = get_fixture_data('cots_train_6113_trip_removal.json')
    cots_6112 = cots_6113.replace('"numeroCourse": "006113",',
                                  '"numeroCourse": "006112",')

    res = api_post('/cots', data=cots_6112, check=False)
    assert res[1] == 404
    assert res[0]['error'] == 'no train found for headsign(s) 006112'
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 0
        assert len(StopTimeUpdate.query.all()) == 0
        assert RealTimeUpdate.query.first().status == 'KO'
        assert RealTimeUpdate.query.first().error == \
            'no train found for headsign(s) 006112'
        assert RealTimeUpdate.query.first().raw_data == cots_6112

    status = api_get('/status')
    assert '-' in status['last_update'][
        'realtime.cots']  # only check it's a date
    assert status['last_valid_update'] == {}
    assert status['last_update_error'][
        'realtime.cots'] == 'no train found for headsign(s) 006112'

    assert mock_rabbitmq.call_count == 0
Ejemplo n.º 35
0
def test_populate_pb_with_cancelation():
    """
    VJ cancelation
    """
    navitia_vj = {'id': 'vehicle_journey:1'}

    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(navitia_vj, datetime.date(2015, 9, 8))
        trip_update.vj = vj
        trip_update.status = 'delete'
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        real_time_update.trip_updates.append(trip_update)

        db.session.add(real_time_update)
        db.session.commit()

        feed_entity = convert_to_gtfsrt(real_time_update)

        assert feed_entity.header.incrementality == gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
        assert feed_entity.header.gtfs_realtime_version == '1'
        pb_trip_update = feed_entity.entity[0].trip_update
        assert pb_trip_update.trip.trip_id == 'vehicle_journey:1'
        assert pb_trip_update.trip.start_date == '20150908'
        assert pb_trip_update.trip.schedule_relationship == gtfs_realtime_pb2.TripDescriptor.CANCELED

        assert len(feed_entity.entity[0].trip_update.stop_time_update) == 0
Ejemplo n.º 36
0
def test_cancellation_then_delay_in_2_updates(navitia_vj):
    """
    same as test_cancellation_then_delay, but with a clear db and in 2 updates
    """
    with app.app_context():
        trip_update = TripUpdate(_create_db_vj(navitia_vj),
                                 status="delete",
                                 contributor_id=COTS_CONTRIBUTOR_ID)
        trip_update.stop_time_updates = []
        real_time_update = make_rt_update(
            raw_data=None,
            connector_type=ConnectorType.cots.value,
            contributor_id=COTS_CONTRIBUTOR_ID)
        handle(real_time_update, [trip_update],
               contributor_id=COTS_CONTRIBUTOR_ID,
               is_new_complete=False)

        trip_update = TripUpdate(_create_db_vj(navitia_vj),
                                 status="update",
                                 contributor_id=COTS_CONTRIBUTOR_ID)
        real_time_update = make_rt_update(
            raw_data=None,
            connector_type=ConnectorType.cots.value,
            contributor_id=COTS_CONTRIBUTOR_ID)
        trip_update.stop_time_updates = [
            StopTimeUpdate({"id": "sa:3"},
                           arrival_delay=timedelta(minutes=40),
                           arr_status="update",
                           order=2)
        ]
        res, _ = handle(real_time_update, [trip_update],
                        COTS_CONTRIBUTOR_ID,
                        is_new_complete=False)

        _check_cancellation_then_delay(res)
Ejemplo n.º 37
0
def test_poller_with_error_response(input_gtfs_rt):
    responses_list = [
        {
            "content": input_gtfs_rt,
            "status_code": 200,
            "headers": {
                "ETag": "etag1"
            }
        },
        {
            "status_code": 400
        },
        {
            "content": basic_gtfs_rt_data_last_stop_without_delays(),
            "status_code": 200
        },
    ]
    config = {
        "contributor": GTFS_CONTRIBUTOR_ID,
        "navitia_url": app.config.get("NAVITIA_URL"),
        "token": "navitia_token",
        "coverage": "navitia_coverage",
        "feed_url": FEED_URL,
        # No retrieval interval to be able to poll successively in test
        "retrieval_interval": 0,
        "timeout": app.config.get("GTFS_RT_TIMEOUT", 1),
    }
    etag_key = build_redis_etag_key(config["contributor"])
    poller = Poller("test_gtfs_poller", ConnectorType.gtfs_rt.value, config)
    with requests_mock.Mocker() as m:
        m.get(FEED_URL, response_list=responses_list)
        with app.app_context():
            poller.poll(kirin.poller_workers.gtfs_rt.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 1
            assert len(TripUpdate.query.all()) == 1
            assert len(StopTimeUpdate.query.all()) == 4
            assert b"etag1" == kirin.redis_client.get(etag_key)
            assert RealTimeUpdate.query.order_by(
                desc(RealTimeUpdate.created_at)).first().status == "OK"

            poller.poll(kirin.poller_workers.gtfs_rt.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 2
            assert len(TripUpdate.query.all()) == 1
            assert len(StopTimeUpdate.query.all()) == 4
            assert kirin.redis_client.get(etag_key) is None
            assert RealTimeUpdate.query.order_by(
                desc(RealTimeUpdate.created_at)).first().raw_data == ""
            assert RealTimeUpdate.query.order_by(
                desc(RealTimeUpdate.created_at)).first().status == "KO"
            assert RealTimeUpdate.query.order_by(
                desc(RealTimeUpdate.created_at)).first().error == "Http Error"

            poller.poll(kirin.poller_workers.gtfs_rt.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 3
            assert len(TripUpdate.query.all()) == 1
            assert len(StopTimeUpdate.query.all()) == 4
            assert kirin.redis_client.get(etag_key) is None
            assert RealTimeUpdate.query.order_by(
                desc(RealTimeUpdate.created_at)).first().status == "OK"
Ejemplo n.º 38
0
def test_sirietliteidfm_poller():
    responses_list = [
        {
            "content": b"{}",
            "status_code": 200,
            "headers": {
                "ETag": "etag1"
            }
        },
        {
            "status_code": 304,
            "headers": {
                "ETag": "etag1"
            }
        },
        {
            "content": b"{}",
            "status_code": 200,
            "headers": {
                "ETag": "etag2"
            }
        },
    ]
    config = {
        "contributor": SIRI_ET_LITE_IDFM_CONTRIBUTOR_ID,
        "navitia_url": app.config.get("NAVITIA_URL"),
        "token": "navitia_token",
        "coverage": "navitia_coverage",
        "feed_url": FEED_URL,
        # No retrieval interval to be able to poll multiple times in testsuccessively
        "retrieval_interval": 0,
        "timeout": app.config.get("SIRI_ET_LITE_IDFM_RT_TIMEOUT", 1),
    }
    etag_key = build_redis_etag_key(config["contributor"])
    poller = Poller("test_siri_et_lite_idfm_poller",
                    ConnectorType.siri_et_lite_idfm.value, config)
    with requests_mock.Mocker() as m:
        m.get(FEED_URL, response_list=responses_list)
        with app.app_context():
            poller.poll(
                kirin.poller_workers.siri_et_lite_idfm.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 1
            assert len(TripUpdate.query.all()) == 0
            assert len(StopTimeUpdate.query.all()) == 0
            assert b"etag1" == kirin.redis_client.get(etag_key)

            poller.poll(
                kirin.poller_workers.siri_et_lite_idfm.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 1
            assert len(TripUpdate.query.all()) == 0
            assert len(StopTimeUpdate.query.all()) == 0
            assert b"etag1" == kirin.redis_client.get(etag_key)

            poller.poll(
                kirin.poller_workers.siri_et_lite_idfm.KirinModelBuilder)
            assert len(RealTimeUpdate.query.all()) == 2
            assert len(TripUpdate.query.all()) == 0
            assert len(StopTimeUpdate.query.all()) == 0
            assert b"etag2" == kirin.redis_client.get(etag_key)
Ejemplo n.º 39
0
def clean_db():
    """
    before all tests the database is cleared
    """
    with app.app_context():
        tables = [str(table) for table in db.metadata.sorted_tables]
        db.session.execute('TRUNCATE {} CASCADE;'.format(', '.join(tables)))
        db.session.commit()
Ejemplo n.º 40
0
def bdd(init_flask_db):
    """
    All tests under this module will have a database
     with an up to date scheme

    At the end of the module the database scheme will be downgraded and upgraded again
    in the next module to test the database migrations
    """
    with app.app_context():
        flask_migrate.Migrate(app, db)
        migration_dir = os.path.join(os.path.dirname(__file__), '..', '..', 'migrations')
        flask_migrate.upgrade(directory=migration_dir)

    yield

    with app.app_context():
        flask_migrate.downgrade(revision='base', directory=migration_dir)
Ejemplo n.º 41
0
def test_handle_basic():
    with pytest.raises(TypeError):
        handle(None)

    #a RealTimeUpdate without any TripUpdate doesn't do anything
    with app.app_context():
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        res = handle(real_time_update, [])
        assert res == real_time_update
Ejemplo n.º 42
0
def test_populate_pb_with_two_stop_time():
    """
    an easy one: we have one vj with only one stop time updated
    fill protobuf from trip_update
    Verify protobuf
    """

    #we add another impacted stop time to the Model
    navitia_vj = {'trip': {'id': 'vehicle_journey:1'}, 'stop_times': [
        {'arrival_time': None, 'departure_time': datetime.time(8, 10), 'stop_point': {'id': 'sa:1'}},
        {'arrival_time': datetime.time(9, 10), 'departure_time': None, 'stop_point': {'id': 'sa:2'}}
        ]}

    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(navitia_vj, datetime.date(2015, 9, 8))
        trip_update.vj = vj
        st = StopTimeUpdate({'id': 'sa:1'}, departure=_dt("8:15"), arrival=None)
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        real_time_update.trip_updates.append(trip_update)
        trip_update.stop_time_updates.append(st)

        st = StopTimeUpdate({'id': 'sa:2'},
                            departure=_dt("8:21"),
                            arrival=_dt("8:20"),
                            message="bob's on the track")
        real_time_update.trip_updates[0].stop_time_updates.append(st)

        db.session.add(real_time_update)
        db.session.commit()

        feed_entity = convert_to_gtfsrt(real_time_update.trip_updates)

        assert feed_entity.header.incrementality == gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
        assert feed_entity.header.gtfs_realtime_version, '1'
        assert len(feed_entity.entity) == 1
        pb_trip_update = feed_entity.entity[0].trip_update
        assert pb_trip_update.trip.trip_id == 'vehicle_journey:1'
        assert pb_trip_update.trip.start_date == '20150908'
        assert pb_trip_update.HasExtension(kirin_pb2.trip_message) == False
        assert pb_trip_update.trip.HasExtension(kirin_pb2.contributor) == False
        assert pb_trip_update.trip.schedule_relationship == gtfs_realtime_pb2.TripDescriptor.SCHEDULED

        assert len(pb_trip_update.stop_time_update) == 2

        pb_stop_time = pb_trip_update.stop_time_update[0]
        assert pb_stop_time.stop_id == 'sa:1'
        assert pb_stop_time.arrival.time == 0
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:15"))
        assert pb_stop_time.Extensions[kirin_pb2.stoptime_message] == ""

        pb_stop_time = pb_trip_update.stop_time_update[1]
        assert pb_stop_time.stop_id == 'sa:2'
        assert pb_stop_time.arrival.time == to_posix_time(_dt("8:20"))
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:21"))
        assert pb_stop_time.Extensions[kirin_pb2.stoptime_message] == "bob's on the track"
Ejemplo n.º 43
0
def test_find_by_vj(setup_database):
    with app.app_context():
        assert TripUpdate.find_by_dated_vj('vehicle_journey:1', datetime.date(2015, 9, 9)) is None
        row = TripUpdate.find_by_dated_vj('vehicle_journey:1', datetime.date(2015, 9, 8))
        assert row is not None
        assert row.vj_id == '70866ce8-0638-4fa1-8556-1ddfa22d09d3'

        row = TripUpdate.find_by_dated_vj('vehicle_journey:2', datetime.date(2015, 9, 8))
        assert row is not None
        assert row.vj_id == '70866ce8-0638-4fa1-8556-1ddfa22d09d4'
Ejemplo n.º 44
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
Ejemplo n.º 45
0
def check_db_ire_96231_delayed():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 6
        db_trip_delayed = TripUpdate.find_by_dated_vj('trip:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime.date(2015, 9, 21))
        assert db_trip_delayed

        assert db_trip_delayed.vj.navitia_trip_id == 'trip:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip_delayed.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip_delayed.vj_id == db_trip_delayed.vj.id
        assert db_trip_delayed.status == 'update'
        # 6 stop times must have been created
        assert len(db_trip_delayed.stop_time_updates) == 6

        # the first stop (in Strasbourg) is not in the IRE, only on navitia's base schedule
        # no delay then, only base schedule
        # Navitia's time are in local, so departure 17h21 in paris is 15h21 in UTC
        first_st = db_trip_delayed.stop_time_updates[0]
        assert first_st.stop_id == 'stop_point:OCE:SP:TrainTER-87212027'
        assert first_st.arrival == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.arrival_status == 'none'
        assert first_st.arrival_delay == timedelta(0)
        assert first_st.departure == datetime.datetime(2015, 9, 21, 15, 21)
        assert first_st.departure_delay == timedelta(0)
        assert first_st.departure_status == 'none'
        assert first_st.message is None

        second_st = db_trip_delayed.stop_time_updates[1]
        assert second_st.stop_id == 'stop_point:OCE:SP:TrainTER-87214056'
        assert second_st.arrival == datetime.datetime(2015, 9, 21, 15, 38)
        assert second_st.arrival_status == 'none'
        assert second_st.arrival_delay == timedelta(0)
        assert second_st.departure == datetime.datetime(2015, 9, 21, 15, 55)
        assert second_st.departure_delay == timedelta(minutes=15)
        assert second_st.departure_status == 'update'
        assert second_st.message == 'Affluence exceptionnelle de voyageurs'

        # last stop is gare de Basel-SBB, delay's only at the arrival
        last_st = db_trip_delayed.stop_time_updates[-1]
        assert last_st.stop_id == 'stop_point:OCE:SP:TrainTER-85000109'
        assert last_st.arrival == datetime.datetime(2015, 9, 21, 16, 54)
        assert last_st.arrival_status == 'update'
        assert last_st.arrival_delay == timedelta(minutes=15)
        #The departure is consistent with arrival
        assert last_st.departure == datetime.datetime(2015, 9, 21, 16, 54)
        assert last_st.departure_delay == timedelta(minutes=15)
        assert last_st.departure_status == 'none'
        assert last_st.message == 'Affluence exceptionnelle de voyageurs'

        assert db_trip_delayed.contributor == 'realtime.ire'
Ejemplo n.º 46
0
def test_simple_delay(navitia_vj):
    """Test on delay when there is nothing in the db"""
    with app.app_context():
        trip_update = TripUpdate(VehicleJourney(navitia_vj, datetime.date(2015, 9, 8)), status='update')
        st = StopTimeUpdate({'id': 'sa:1'},
                            departure_delay=timedelta(minutes=10), dep_status='update',
                            arrival_delay=timedelta(minutes=5), arr_status='update')
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        trip_update.stop_time_updates.append(st)
        res = handle(real_time_update, [trip_update], 'kisio-digital')
        assert len(res.trip_updates) == 1
        trip_update = res.trip_updates[0]
        assert trip_update.status == 'update'
        assert len(trip_update.stop_time_updates) == 3

        assert trip_update.stop_time_updates[0].stop_id == 'sa:1'
        assert trip_update.stop_time_updates[0].arrival == _dt('8:20')  # departure
        assert trip_update.stop_time_updates[0].arrival_delay == timedelta(minutes=5)
        assert trip_update.stop_time_updates[0].arrival_status == 'update'
        assert trip_update.stop_time_updates[0].departure == _dt('8:20')  # 8:10 + 10mn
        assert trip_update.stop_time_updates[0].departure_delay == timedelta(minutes=10)
        assert trip_update.stop_time_updates[0].departure_status == 'update'

        assert trip_update.stop_time_updates[1].stop_id == 'sa:2'
        assert trip_update.stop_time_updates[1].arrival == _dt('9:05')
        assert trip_update.stop_time_updates[1].arrival_delay == timedelta(0)
        assert trip_update.stop_time_updates[1].arrival_status == 'none'
        assert trip_update.stop_time_updates[1].departure == _dt('9:10')
        assert trip_update.stop_time_updates[1].departure_delay == timedelta(0)
        assert trip_update.stop_time_updates[1].departure_status == 'none'

        # testing that RealTimeUpdate is persisted in db
        db_trip_updates = real_time_update.query.from_self(TripUpdate).all()
        assert len(db_trip_updates) == 1
        assert db_trip_updates[0].status == 'update'

        db_st_updates = real_time_update.query.from_self(StopTimeUpdate).order_by('stop_id').all()
        assert len(db_st_updates) == 3
        assert db_st_updates[0].stop_id == 'sa:1'
        assert db_st_updates[0].arrival == _dt('8:20')  # departure
        assert db_st_updates[0].arrival_delay == timedelta(minutes=5)
        assert db_st_updates[0].arrival_status == 'update'
        assert db_st_updates[0].departure == _dt('8:20')  # 8:10 + 10mn
        assert db_st_updates[0].departure_delay == timedelta(minutes=10)
        assert db_st_updates[0].departure_status == 'update'

        assert db_st_updates[1].stop_id == 'sa:2'
        assert db_st_updates[1].arrival == _dt('9:05')
        assert db_st_updates[1].departure == _dt('9:10')
        assert db_st_updates[1].trip_update_id == db_trip_updates[0].vj_id

        assert db_st_updates[2].stop_id == 'sa:3'
Ejemplo n.º 47
0
def test_find_stop():
    with app.app_context():
        vj = create_trip_update('70866ce8-0638-4fa1-8556-1ddfa22d09d3', 'vj1', datetime.date(2015, 9, 8))
        st1 = StopTimeUpdate({'id': 'sa:1'}, None, None)
        vj.stop_time_updates.append(st1)
        st2 = StopTimeUpdate({'id': 'sa:2'}, None, None)
        vj.stop_time_updates.append(st2)
        st3 = StopTimeUpdate({'id': 'sa:3'}, None, None)
        vj.stop_time_updates.append(st3)

        assert vj.find_stop('sa:1') == st1
        assert vj.find_stop('sa:3') == st3
        assert vj.find_stop('sa:4') is None
Ejemplo n.º 48
0
def test_ire_delayed_simple_post(mock_rabbitmq):
    """
    simple delayed stops post
    """
    ire_96231 = get_ire_data('train_96231_delayed.xml')
    res = api_post('/ire', data=ire_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_ire_96231_delayed()
    assert mock_rabbitmq.call_count == 1
Ejemplo n.º 49
0
def test_ire_trip_removal_simple_post(mock_rabbitmq):
    """
    simple trip removal post
    """
    ire_6113 = get_ire_data('train_6113_trip_removal.xml')
    res = api_post('/ire', data=ire_6113)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_ire_6113_trip_removal()
    assert mock_rabbitmq.call_count == 1
Ejemplo n.º 50
0
def test_save_bad_raw_ire():
    """
    send a bad formatted ire, the bad raw ire should be saved in db
    """
    bad_ire = get_ire_data('bad_ire.xml')
    res = api_post('/ire', data=bad_ire, check=False)
    assert res[1] == 400
    assert res[0]['message'] == 'Invalid arguments'
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert RealTimeUpdate.query.first().status == 'KO'
        assert RealTimeUpdate.query.first().error == \
            'invalid xml, impossible to find "Train" in xml elt InfoRetard'
        assert RealTimeUpdate.query.first().raw_data == bad_ire
Ejemplo n.º 51
0
def check_db_ire_96231_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip_removal = TripUpdate.find_by_dated_vj('vehicle_journey:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime.date(2015, 9, 21))
        assert db_trip_removal

        assert db_trip_removal.vj.navitia_id == 'vehicle_journey:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip_removal.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip_removal.vj_id == db_trip_removal.vj.id
        assert db_trip_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip_removal.stop_time_updates) == 0
Ejemplo n.º 52
0
def check_db_ire_6113_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip_removal = TripUpdate.find_by_dated_vj('vehicle_journey:OCETGV-87686006-87751008-2:25768',
                                                      datetime.date(2015, 10, 6))
        assert db_trip_removal

        assert db_trip_removal.vj.navitia_id == 'vehicle_journey:OCETGV-87686006-87751008-2:25768'
        assert db_trip_removal.vj.circulation_date == datetime.date(2015, 10, 6)
        assert db_trip_removal.vj_id == db_trip_removal.vj.id
        assert db_trip_removal.status == 'delete'
        # full trip removal : no stop_time to precise
        assert len(db_trip_removal.stop_time_updates) == 0
Ejemplo n.º 53
0
def check_db_ire_96231_delayed():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 6
        db_trip_delayed = TripUpdate.find_by_dated_vj('vehicle_journey:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime.date(2015, 9, 21))
        assert db_trip_delayed

        assert db_trip_delayed.vj.navitia_id == 'vehicle_journey:OCETrainTER-87212027-85000109-3:11859'
        assert db_trip_delayed.vj.circulation_date == datetime.date(2015, 9, 21)
        assert db_trip_delayed.vj_id == db_trip_delayed.vj.id
        assert db_trip_delayed.status == 'update'
        # 6 stop times must have been created
        assert len(db_trip_delayed.stop_time_updates) == 6
Ejemplo n.º 54
0
def test_ire_two_trip_removal_one_post(mock_rabbitmq):
    """
    post one ire trip removal on two trips
    (navitia mock returns 2 vj for 'JOHN' headsign)
    """
    ire_JOHN_trip_removal = get_ire_data('train_JOHN_trip_removal.xml')
    res = api_post('/ire', data=ire_JOHN_trip_removal)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 2
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_ire_JOHN_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 1
Ejemplo n.º 55
0
def test_ire_trip_removal_parity(mock_rabbitmq):
    """
    simple parity trip removal post
    """
    ire_6113 = get_ire_data('train_6113_trip_removal.xml')
    ire_6113_14 = ire_6113.replace('<NumeroTrain>006113</NumeroTrain>',
                                   '<NumeroTrain>006113/14</NumeroTrain>')
    res = api_post('/ire', data=ire_6113_14)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_ire_6113_trip_removal()
    assert mock_rabbitmq.call_count == 1
Ejemplo n.º 56
0
def check_db_ire_6114_trip_removal():
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) >= 1
        assert len(TripUpdate.query.all()) >= 1
        assert len(StopTimeUpdate.query.all()) >= 0
        db_trip_removal = TripUpdate.find_by_dated_vj('trip:OCETGV-87686006-87751008-2:25768-2',
                                                      datetime.date(2015, 10, 6))
        assert db_trip_removal

        assert db_trip_removal.vj.navitia_trip_id == 'trip:OCETGV-87686006-87751008-2:25768-2'
        assert db_trip_removal.vj.circulation_date == datetime.date(2015, 10, 6)
        assert db_trip_removal.vj_id == db_trip_removal.vj.id
        assert db_trip_removal.status == 'delete'
        print db_trip_removal.message
        assert db_trip_removal.message == u'Accident à un Passage à Niveau'
        # full trip removal : no stop_time to precise
        assert len(db_trip_removal.stop_time_updates) == 0
Ejemplo n.º 57
0
def test_ire_trip_removal_post_twice(mock_rabbitmq):
    """
    double trip removal post
    """
    ire_6113 = get_ire_data('train_6113_trip_removal.xml')
    res = api_post('/ire', data=ire_6113)
    assert res == 'OK'
    res = api_post('/ire', data=ire_6113)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_ire_6113_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Ejemplo n.º 58
0
def test_ire_delayed_post_twice(mock_rabbitmq):
    """
    double delayed stops post
    """
    ire_96231 = get_ire_data('train_96231_delayed.xml')
    res = api_post('/ire', data=ire_96231)
    assert res == 'OK'
    res = api_post('/ire', data=ire_96231)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_ire_96231_delayed()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Ejemplo n.º 59
0
def test_ire_trip_delayed_then_removal(mock_rabbitmq):
    """
    post delayed stops then trip removal on the same trip
    """
    ire_96231_delayed = get_ire_data('train_96231_delayed.xml')
    res = api_post('/ire', data=ire_96231_delayed)
    assert res == 'OK'
    ire_96231_trip_removal = get_ire_data('train_96231_trip_removal.xml')
    res = api_post('/ire', data=ire_96231_trip_removal)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_ire_96231_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2