Esempio n. 1
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
Esempio n. 2
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
Esempio 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
Esempio n. 4
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"
Esempio n. 5
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
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'
Esempio n. 7
0
def test_ire_trip_delayed_then_removal(mock_rabbitmq):
    """
    post delayed stops then trip removal on the same trip
    """
    ire_96231_delayed = get_fixture_data('train_96231_delayed.xml')
    res = api_post('/ire', data=ire_96231_delayed)
    assert res == 'OK'
    ire_96231_trip_removal = get_fixture_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_96231_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 8
0
def test_cots_trip_delayed_then_partial_removal(mock_rabbitmq):
    """
    post delayed stops then trip removal on the same trip
    """
    cots_96231_delayed = get_fixture_data('cots_train_96231_delayed.json')
    res = api_post('/cots', data=cots_96231_delayed)
    assert res == 'OK'
    cots_96231_partial_removal = get_fixture_data('cots_train_96231_partial_removal.json')
    res = api_post('/cots', data=cots_96231_partial_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()) == 6
        assert RealTimeUpdate.query.first().status == 'OK'
    check_db_96231_partial_removal(contributor='realtime.cots')
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 9
0
def test_cots_delayed_and_trip_removal_post(mock_rabbitmq):
    """
    post delayed stops on one trip then trip removal on another
    """
    cots_96231 = get_fixture_data('cots_train_96231_delayed.json')
    res = api_post('/cots', data=cots_96231)
    assert res == 'OK'

    cots_6113 = get_fixture_data('cots_train_6113_trip_removal.json')
    res = api_post('/cots', data=cots_6113)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 2
        assert len(StopTimeUpdate.query.all()) == 6
    check_db_96231_delayed(contributor='realtime.cots')
    check_db_6113_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 10
0
def test_get_action_on_trip_previously_added(mock_navitia_fixture):
    with app.app_context():
        # Test for add followed by update should be PREVIOUSLY_ADDED
        input_trip_add = get_fixture_data("cots_train_151515_added_trip.json")
        contributor = model.Contributor(
            id=COTS_CONTRIBUTOR_ID,
            navitia_coverage=None,
            connector_type=ConnectorType.cots.value)
        builder = KirinModelBuilder(contributor)
        wrap_build(builder, input_trip_add)

        input_update_added_trip = get_fixture_data(
            "cots_train_151515_added_trip_with_delay.json")
        json_data = json.loads(input_update_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.PREVIOUSLY_ADDED.name
Esempio n. 11
0
def test_ire_delayed_simple_post(mock_rabbitmq):
    """
    simple delayed stops post
    """
    ire_96231 = get_fixture_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_96231_delayed(contributor='realtime.ire')
    assert mock_rabbitmq.call_count == 1
Esempio n. 12
0
def test_cots_trip_removal_simple_post(mock_rabbitmq):
    """
    simple trip removal post
    """
    cots_6113 = get_fixture_data('cots_train_6113_trip_removal.json')
    res = api_post('/cots', data=cots_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_6113_trip_removal()
    assert mock_rabbitmq.call_count == 1
Esempio n. 13
0
def test_save_bad_raw_ire():
    """
    send a bad formatted ire, the bad raw ire should be saved in db
    """
    bad_ire = get_fixture_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
Esempio n. 14
0
def test_save_bad_raw_cots():
    """
    send a bad formatted COTS, the bad raw COTS should be saved in db
    """
    bad_cots = get_fixture_data('bad_cots.json')
    res = api_post('/cots', data=bad_cots, 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 json, impossible to find "numeroCourse" in json dict {"bad":"one","cots":"toto"}'
        assert RealTimeUpdate.query.first().raw_data == bad_cots
Esempio n. 15
0
def test_cots_added_stop_time_earlier_than_previous():
    """
    A new stop time is added in the VJ 96231 whose arrival/departure is earlier
    than the previous one.

    This cots should be rejected
    """
    cots_add_file = get_fixture_data(
        'cots_train_96231_add_stop_time_earlier_than_previous.json')
    res, status = api_post('/cots', data=cots_add_file, check=False)
    assert status == 400
    assert res.get('message') == 'Invalid arguments'
    with app.app_context():
        assert RealTimeUpdate.query.first().error == \
               'invalid cots: stop_point\'s(0087-713065-BV) time is not consistent'
Esempio n. 16
0
def test_wrong_planned_stop_time_reference_post():
    """
    Rejected COTS feed, contains wrong planned-stoptime
    """
    cots_file = get_fixture_data('cots_train_96231_delaylist_at_stop_ko.json')
    res, status = api_post('/cots', check=False, data=cots_file)

    assert status == 400
    assert res.get('message') == 'Invalid arguments'
    assert 'error' in res
    assert u'invalid json, impossible to find source "ESCALE" in any json dict of list:' in res.get('error')

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 0
        assert len(StopTimeUpdate.query.all()) == 0
Esempio n. 17
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_fixture_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_john_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 1
Esempio n. 18
0
def test_cots_delayed_simple_post(mock_rabbitmq):
    """
    simple delayed stops post
    """
    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
        db_trip_delayed = TripUpdate.find_by_dated_vj('trip:OCETrainTER-87212027-85000109-3:11859',
                                                      datetime(2015, 9, 21, 15, 21, tzinfo=utc))
        assert db_trip_delayed.stop_time_updates[4].message is None
    check_db_96231_delayed(contributor='realtime.cots')
    assert mock_rabbitmq.call_count == 1
Esempio n. 19
0
def test_cots_delayed_post_twice(mock_rabbitmq):
    """
    double delayed stops post
    """
    cots_96231 = get_fixture_data('cots_train_96231_delayed.json')
    res = api_post('/cots', data=cots_96231)
    assert res == 'OK'
    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_delayed(contributor='realtime.cots')
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 20
0
def test_cots_trip_removal_post_twice(mock_rabbitmq):
    """
    double trip removal post
    """
    cots_6113 = get_fixture_data('cots_train_6113_trip_removal.json')
    res = api_post('/cots', data=cots_6113)
    assert res == 'OK'
    res = api_post('/cots', data=cots_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_6113_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 21
0
def test_cots_partial_removal(mock_rabbitmq):
    """
    the trip 840427 has been partialy deleted

    Normally there are 7 stops in this VJ, but 4 (Chaumont, Bar-sur-Aube, Vendeuvre and Troyes) have been removed
    """
    cots_080427 = get_fixture_data('cots_train_840427_partial_removal.json')
    res = api_post('/cots', data=cots_080427)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert len(StopTimeUpdate.query.all()) == 7
        assert RealTimeUpdate.query.first().status == 'OK'
    check_db_840427_partial_removal(contributor='realtime.cots')
    assert mock_rabbitmq.call_count == 1
Esempio n. 22
0
def test_cots_two_trip_removal_post_twice(mock_rabbitmq):
    """
    post twice COTS trip removal on two trips
    """
    cots_john_trip_removal = get_fixture_data('cots_train_JOHN_trip_removal.json')
    res = api_post('/cots', data=cots_john_trip_removal)
    assert res == 'OK'
    res = api_post('/cots', data=cots_john_trip_removal)
    assert res == 'OK'

    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 2
        assert len(TripUpdate.query.all()) == 2
        assert len(StopTimeUpdate.query.all()) == 0
    check_db_john_trip_removal()
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 2
Esempio n. 23
0
def test_cots_added_stop_time_last_position():
    """
    A new stop time is added in the VJ 96231 in last position
    """
    cots_add_file = get_fixture_data('cots_train_96231_add_last.json')
    res = api_post('/cots', data=cots_add_file)
    assert res == 'OK'
    with app.app_context():
        assert len(RealTimeUpdate.query.all()) == 1
        assert len(TripUpdate.query.all()) == 1
        assert TripUpdate.query.all()[0].status == 'update'
        assert TripUpdate.query.all()[0].effect == 'MODIFIED_SERVICE'
        assert TripUpdate.query.all()[0].company_id == 'company:OCE:SN'
        assert len(StopTimeUpdate.query.all()) == 7
        assert StopTimeUpdate.query.all()[6].departure_status == 'none'
        assert StopTimeUpdate.query.all()[6].arrival_status == 'add'
        assert StopTimeUpdate.query.all()[6].departure == datetime(
            2015, 9, 21, 16, 50)
Esempio n. 24
0
def test_cots_mixed_statuses_delay_removal_delay(mock_rabbitmq):
    """
    stops have mixed statuses
    on 2nd stop is delayed by 5 min
    on 3rd is removed
    on 4th stop is delayed by 2 min
    """
    cots_96231 = get_fixture_data('cots_train_96231_mixed_statuses_delay_removal_delay.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
    check_db_96231_mixed_statuses_delay_removal_delay(contributor='realtime.cots')
    # the rabbit mq has to have been called twice
    assert mock_rabbitmq.call_count == 1
Esempio n. 25
0
def test_cots_mixed_statuses_inside_stop_times(mock_rabbitmq):
    """
    stops have mixed statuses (between their departure and arrival especially)
    on 2nd stop departure is delayed by 30 s, arrival OK
    on 3rd stop arrival is delayed by 30 s, departure OK (catching up on lost time)
    on 4th stop arrival is delayed by 1 min, departure is removed
    """
    cots_96231 = get_fixture_data('cots_train_96231_mixed_statuses_inside_stops.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
    check_db_96231_mixed_statuses_inside_stops(contributor='realtime.cots')

    assert mock_rabbitmq.call_count == 1
Esempio n. 26
0
def test_get_action_on_trip_add(mock_navitia_fixture):
    """
    Test the function _get_action_on_trip:
    - Fist trip add(AJOUTEE)-> FIRST_TIME_ADDED
    """

    with app.app_context():
        # Test for the first add: should be FIRST_TIME_ADDED
        input_trip_add = get_fixture_data("cots_train_151515_added_trip.json")
        json_data = json.loads(input_trip_add)
        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
Esempio n. 27
0
def test_cots_trip_with_parity_one_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_13 = cots_6113.replace('"numeroCourse": "006113",',
                                     '"numeroCourse": "006112/3",')
    res = api_post('/cots', data=cots_6112_13)
    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_6113_trip_removal()

    assert mock_rabbitmq.call_count == 1
Esempio n. 28
0
def test_ire_trip_with_parity_one_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
    """
    ire_6113 = get_fixture_data('train_6113_trip_removal.xml')
    ire_6112_13 = ire_6113.replace('<NumeroTrain>006113</NumeroTrain>',
                                   '<NumeroTrain>006112/3</NumeroTrain>')
    res = api_post('/ire', data=ire_6112_13)
    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_6113_trip_removal()

    assert mock_rabbitmq.call_count == 1
Esempio n. 29
0
def test_cots_simple_post(mock_rabbitmq):
    """
    simple COTS post should be stored in db as a RealTimeUpdate
    """
    cots_file = get_fixture_data('cots_train_96231_delayed.json')
    res = api_post('/cots', data=cots_file)
    assert res == 'OK'

    with app.app_context():
        rtu_array = RealTimeUpdate.query.all()
        assert len(rtu_array) == 1
        rtu = rtu_array[0]
        assert '-' in rtu.id
        assert rtu.received_at
        assert rtu.status == 'OK'
        assert rtu.error is None
        assert rtu.contributor == 'realtime.cots'
        assert rtu.connector == 'cots'
        assert 'listePointDeParcours' in rtu.raw_data
    assert mock_rabbitmq.call_count == 1
Esempio n. 30
0
def test_ire_trip_without_any_motifexterne(mock_rabbitmq):
    """
    a trip with a parity has been impacted, but the Message is missing,
    the IRE should still be acceptable
    """
    ire_96231 = get_fixture_data('train_96231_delayed.xml')
    # Removing MotifExterne
    ire_96231_without_MotifExterne = ire_96231.replace(
        '<MotifExterne>Affluence exceptionnelle de voyageurs</MotifExterne>',
        '')
    res = api_post('/ire', data=ire_96231_without_MotifExterne)
    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.ire',
                           motif_externe_is_null=True)
    assert mock_rabbitmq.call_count == 1