Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
0
def test_populate_pb_with_full_dataset():
    """
    VJ cancelation
    """
    navitia_vj = {
        'trip': {
            'id': 'vehicle_journey:1'
        },
        'stop_times': [{
            'arrival_time': datetime.time(8, 10),
            'stop_point': {
                'stop_area': {
                    'timezone': 'UTC'
                }
            }
        }]
    }

    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',
                                          contributor='realtime.ire')
        trip_update.contributor = 'kisio-digital'
        trip_update.company_id = 'keolis'
        trip_update.effect = 'DETOUR'
        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 pb_trip_update.trip.Extensions[kirin_pb2.company_id] == 'keolis'
        assert pb_trip_update.Extensions[
            kirin_pb2.effect] == gtfs_realtime_pb2.Alert.DETOUR

        assert len(feed_entity.entity[0].trip_update.stop_time_update) == 0
Exemplo n.º 4
0
def test_populate_pb_with_cancelation():
    """
    VJ cancelation
    """
    navitia_vj = {
        "trip": {
            "id": "vehicle_journey:1"
        },
        "stop_times": [{
            "utc_arrival_time": datetime.time(8, 10),
            "stop_point": {
                "stop_area": {
                    "timezone": "UTC"
                }
            }
        }],
    }

    with app.app_context():
        vj = VehicleJourney(navitia_vj,
                            datetime.datetime(2015, 9, 8, 7, 10, 0),
                            datetime.datetime(2015, 9, 8, 11, 5, 0))
        trip_update = TripUpdate(vj=vj, contributor_id=COTS_CONTRIBUTOR_ID)
        trip_update.vj = vj
        trip_update.status = "delete"
        trip_update.message = "Message Test"
        real_time_update = make_rt_update(
            raw_data=None,
            connector_type=ConnectorType.cots.value,
            contributor_id=COTS_CONTRIBUTOR_ID)
        trip_update.company_id = "sncf"
        trip_update.effect = "REDUCED_SERVICE"
        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)

        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.HasExtension(kirin_pb2.trip_message) is 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) is True
        assert pb_trip_update.trip.Extensions[
            kirin_pb2.contributor] == COTS_CONTRIBUTOR_ID
        assert pb_trip_update.trip.Extensions[kirin_pb2.company_id] == "sncf"
        assert pb_trip_update.Extensions[
            kirin_pb2.effect] == gtfs_realtime_pb2.Alert.REDUCED_SERVICE

        assert len(feed_entity.entity[0].trip_update.stop_time_update) == 0
Exemplo n.º 5
0
def test_populate_pb_with_cancelation():
    """
    VJ cancelation
    """
    navitia_vj = {
        'trip': {
            'id': 'vehicle_journey:1'
        },
        'stop_times': [{
            'utc_arrival_time': datetime.time(8, 10),
            'stop_point': {
                'stop_area': {
                    'timezone': 'UTC'
                }
            }
        }]
    }

    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(
            navitia_vj, utc.localize(datetime.datetime(2015, 9, 8, 7, 10, 0)),
            utc.localize(datetime.datetime(2015, 9, 8, 11, 5, 0)))
        trip_update.vj = vj
        trip_update.status = 'delete'
        trip_update.message = 'Message Test'
        real_time_update = RealTimeUpdate(raw_data=None,
                                          connector='cots',
                                          contributor='realtime.cots')
        trip_update.contributor = 'kisio-digital'
        trip_update.company_id = 'sncf'
        trip_update.effect = 'REDUCED_SERVICE'
        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)

        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.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 pb_trip_update.trip.Extensions[kirin_pb2.company_id] == 'sncf'
        assert pb_trip_update.Extensions[
            kirin_pb2.effect] == gtfs_realtime_pb2.Alert.REDUCED_SERVICE

        assert len(feed_entity.entity[0].trip_update.stop_time_update) == 0
Exemplo n.º 6
0
def test_handle_new_vj():
    """an easy one: we have one vj with only one stop time updated"""
    navitia_vj = {'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
        trip_update.status = 'update'
        st = StopTimeUpdate({'id': 'sa:1'}, departure=_dt("8:15"), arrival=None)
        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 trip_update.status == 'update'
        assert len(trip_update.stop_time_updates) == 2
        assert trip_update.stop_time_updates[0].stop_id == 'sa:1'
        assert trip_update.stop_time_updates[0].departure == _dt("8:15")
        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 == None
        assert trip_update.stop_time_updates[1].arrival == _dt("9:10")


        # 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) == 2
        assert db_st_updates[0].stop_id == 'sa:1'
        assert db_st_updates[0].departure == _dt("8:15")
        assert db_st_updates[0].arrival == None
        assert db_st_updates[0].trip_update_id == db_trip_updates[0].vj_id

        assert db_st_updates[1].stop_id == 'sa:2'
        assert db_st_updates[1].departure == None
        assert db_st_updates[1].arrival == _dt("9:10")
        assert db_st_updates[1].trip_update_id == db_trip_updates[0].vj_id
Exemplo n.º 7
0
def test_populate_pb_with_cancelation():
    """
    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)

        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.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
Exemplo n.º 8
0
def test_populate_pb_for_added_trip():
    """
    For an added trip we don't call navitia to get a vj instead we create and initialize one vj only with 'id'
    Fill protobuf from trip_update
    Verify protobuf
    """
    navitia_vj = make_navitia_empty_vj("vehicle_journey:1")

    with app.app_context():
        vj = VehicleJourney(
            navitia_vj,
            since_dt=datetime.datetime(2015, 9, 8, 5, 10, 0),
            until_dt=datetime.datetime(2015, 9, 8, 8, 10, 0),
            vj_start_dt=datetime.datetime(2015, 9, 8, 5, 10, 0),
        )
        trip_update = TripUpdate(vj=vj, contributor_id=COTS_CONTRIBUTOR_ID)
        trip_update.vj = vj
        trip_update.status = "add"
        trip_update.effect = "ADDITIONAL_SERVICE"
        trip_update.physical_mode_id = "physical_mode:LongDistanceTrain"
        real_time_update = make_rt_update(
            raw_data=None,
            connector_type=ConnectorType.cots.value,
            contributor_id=COTS_CONTRIBUTOR_ID)
        real_time_update.trip_updates.append(trip_update)
        st = StopTimeUpdate(
            {"id": "sa:1"},
            departure=_dt("8:15"),
            departure_delay=timedelta(minutes=5),
            arrival=None,
            arr_status="none",
            dep_status="add",
        )
        trip_update.stop_time_updates.append(st)

        st = StopTimeUpdate(
            {"id": "sa:2"},
            departure=_dt("8:21"),
            departure_delay=timedelta(minutes=-40),
            arrival=_dt("8:20"),
            arrival_delay=timedelta(minutes=-40),
            message="bob's on the track",
            arr_status="add",
            dep_status="none",
        )
        trip_update.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 == "OCE:SN:vehicle_journey:1"
        assert pb_trip_update.trip.start_date == "20150908"
        assert pb_trip_update.HasExtension(kirin_pb2.trip_message) is False
        assert pb_trip_update.trip.HasExtension(kirin_pb2.contributor) is True
        assert pb_trip_update.trip.HasExtension(kirin_pb2.company_id) is False
        assert pb_trip_update.HasExtension(kirin_pb2.effect) is True
        assert pb_trip_update.Extensions[
            kirin_pb2.effect] == gtfs_realtime_pb2.Alert.ADDITIONAL_SERVICE
        assert pb_trip_update.vehicle.Extensions[
            kirin_pb2.physical_mode_id] == "physical_mode:LongDistanceTrain"

        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.arrival.delay == 0
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:15"))
        assert pb_stop_time.departure.delay == 5 * 60
        assert pb_stop_time.Extensions[kirin_pb2.stoptime_message] == ""
        assert pb_stop_time.arrival.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.SCHEDULED
        assert pb_stop_time.departure.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.ADDED

        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.arrival.delay == -40 * 60
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:21"))
        assert pb_stop_time.departure.delay == -40 * 60
        assert pb_stop_time.Extensions[
            kirin_pb2.stoptime_message] == "bob's on the track"
        assert pb_stop_time.arrival.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.ADDED
        assert pb_stop_time.departure.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.SCHEDULED
Exemplo n.º 9
0
def test_populate_pb_for_added_trip():
    """
    For an added trip we don't call navitia to get a vj instead we create and initialize one vj only with 'id'
    Fill protobuf from trip_update
    Verify protobuf
    """
    navitia_vj = make_navitia_empty_vj('vehicle_journey:1')

    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(
            navitia_vj,
            utc_since_dt=utc.localize(datetime.datetime(2015, 9, 8, 5, 10, 0)),
            utc_until_dt=utc.localize(datetime.datetime(2015, 9, 8, 8, 10, 0)),
            vj_start_dt=utc.localize(datetime.datetime(2015, 9, 8, 5, 10, 0)))
        trip_update.vj = vj
        trip_update.status = 'add'
        trip_update.effect = 'ADDITIONAL_SERVICE'
        trip_update.physical_mode_id = 'physical_mode:LongDistanceTrain'
        real_time_update = RealTimeUpdate(raw_data=None,
                                          connector='cots',
                                          contributor='realtime.cots')
        real_time_update.trip_updates.append(trip_update)
        st = StopTimeUpdate({'id': 'sa:1'},
                            departure=_dt("8:15"),
                            departure_delay=timedelta(minutes=5),
                            arrival=None,
                            arr_status='none',
                            dep_status='add')
        trip_update.stop_time_updates.append(st)

        st = StopTimeUpdate({'id': 'sa:2'},
                            departure=_dt("8:21"),
                            departure_delay=timedelta(minutes=-40),
                            arrival=_dt("8:20"),
                            arrival_delay=timedelta(minutes=-40),
                            message="bob's on the track",
                            arr_status='add',
                            dep_status='none')
        trip_update.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 == 'OCE:SN:vehicle_journey:1'
        assert pb_trip_update.trip.start_date == '20150908'
        assert pb_trip_update.HasExtension(kirin_pb2.trip_message) is False
        assert pb_trip_update.trip.HasExtension(kirin_pb2.contributor) is False
        assert pb_trip_update.trip.HasExtension(kirin_pb2.company_id) is False
        assert pb_trip_update.HasExtension(kirin_pb2.effect) is True
        assert pb_trip_update.Extensions[
            kirin_pb2.effect] == gtfs_realtime_pb2.Alert.ADDITIONAL_SERVICE
        assert pb_trip_update.vehicle.Extensions[
            kirin_pb2.physical_mode_id] == 'physical_mode:LongDistanceTrain'

        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.arrival.delay == 0
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:15"))
        assert pb_stop_time.departure.delay == 5 * 60
        assert pb_stop_time.Extensions[kirin_pb2.stoptime_message] == ""
        assert pb_stop_time.arrival.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.SCHEDULED
        assert pb_stop_time.departure.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.ADDED

        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.arrival.delay == -40 * 60
        assert pb_stop_time.departure.time == to_posix_time(_dt("8:21"))
        assert pb_stop_time.departure.delay == -40 * 60
        assert pb_stop_time.Extensions[
            kirin_pb2.stoptime_message] == "bob's on the track"
        assert pb_stop_time.arrival.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.ADDED
        assert pb_stop_time.departure.Extensions[
            kirin_pb2.stop_time_event_status] == kirin_pb2.SCHEDULED
Exemplo n.º 10
0
def test_handle_update_vj(setup_database, navitia_vj):
    """
    this time we receive an update for a vj already in the database
    """
    with app.app_context():
        trip_update = TripUpdate()
        vj = VehicleJourney(navitia_vj, datetime.date(2015, 9, 8))
        trip_update.status = 'update'
        trip_update.vj = vj
        st = StopTimeUpdate({'id': 'sa:2'}, departure=_dt("9:20"), arrival=_dt("9:15"))
        st.arrival_status = st.departure_status = 'update'
        real_time_update = RealTimeUpdate(raw_data=None, connector='ire')
        real_time_update.id = '30866ce8-0638-4fa1-8556-1ddfa22d09d3'
        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 trip_update.status == 'update'
        assert len(trip_update.real_time_updates) == 2
        assert len(trip_update.stop_time_updates) == 3

        stu_map = {stu.stop_id: stu for stu in trip_update.stop_time_updates}

        assert 'sa:1' in stu_map
        assert stu_map['sa:1'].arrival == None
        assert stu_map['sa:1'].departure == _dt("8:15")

        assert 'sa:2' in stu_map
        assert stu_map['sa:2'].arrival == _dt("9:15")
        assert stu_map['sa:2'].departure == _dt("9:20")

        assert 'sa:3' in stu_map
        assert stu_map['sa:3'].arrival == _dt("10:05")
        assert stu_map['sa:3'].departure ==  None


        # testing that RealTimeUpdate is persisted in db
        db_trip_updates = TripUpdate.query.join(VehicleJourney).order_by('circulation_date').all()
        assert len(db_trip_updates) == 2
        assert real_time_update.query.from_self(TripUpdate).all()[0].status == 'update'
        st_updates = real_time_update.query.from_self(StopTimeUpdate).order_by('stop_id').all()
        assert len(st_updates) == 6

        # testing that trip update on 2015/09/07 is remaining correctly stored in db
        assert len(db_trip_updates[0].stop_time_updates) == 3
        db_stu_map = {stu.stop_id: stu for stu in db_trip_updates[0].stop_time_updates}

        assert 'sa:1' in db_stu_map
        assert db_stu_map['sa:1'].arrival == None
        assert db_stu_map['sa:1'].departure == _dt("8:35", day=7)

        assert 'sa:2' in db_stu_map
        assert db_stu_map['sa:2'].arrival == _dt("9:35", day=7)
        assert db_stu_map['sa:2'].departure == _dt("9:40", day=7)

        assert 'sa:3' in db_stu_map
        assert db_stu_map['sa:3'].arrival == _dt("10:35", day=7)
        assert db_stu_map['sa:3'].departure ==  None

        # testing that trip update on 2015/09/08 is correctly merged and stored in db
        assert len(db_trip_updates[1].stop_time_updates) == 3
        db_stu_map = {stu.stop_id: stu for stu in db_trip_updates[1].stop_time_updates}

        assert 'sa:1' in db_stu_map
        assert db_stu_map['sa:1'].arrival == None
        assert db_stu_map['sa:1'].departure == _dt("8:15")

        assert 'sa:2' in db_stu_map
        assert db_stu_map['sa:2'].arrival == _dt("9:15")
        assert db_stu_map['sa:2'].departure == _dt("9:20")

        assert 'sa:3' in db_stu_map
        assert db_stu_map['sa:3'].arrival == _dt("10:05")
        assert db_stu_map['sa:3'].departure ==  None