Example #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
Example #2
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
Example #3
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
Example #4
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
Example #5
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
Example #6
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