Ejemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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(_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:1"},
                           departure_delay=timedelta(minutes=5),
                           dep_status="update")
        ]
        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: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],
                        contributor_id=COTS_CONTRIBUTOR_ID,
                        is_new_complete=False)

        _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.º 13
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')
        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: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.º 14
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',
                                          contributor='realtime.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',
                                          contributor='realtime.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.º 15
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 = make_rt_update(None,
                             ConnectorType.cots.value,
                             contributor_id=COTS_CONTRIBUTOR_ID)
        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(_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.º 16
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 = make_rt_update(None, contributor_id=GTFS_CONTRIBUTOR_ID)
        rtu.id = "10866ce8-0638-4fa1-8556-1ddfa22d09d3"
        rtu.trip_updates.append(vju)
        db_commit(rtu)

    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",
            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: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.º 17
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.º 18
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',
                                          contributor='realtime.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.º 19
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(_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:1"},
                           departure_delay=timedelta(minutes=5),
                           dep_status="update")
        ]
        handle(real_time_update, [trip_update],
               contributor_id=COTS_CONTRIBUTOR_ID,
               is_new_complete=False)

        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