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
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
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
def test_get_action_on_trip_add(mock_navitia_fixture):
    """
    Test the function _get_action_on_trip with different type of flux cots
    returns:
    1. Fist trip add(AJOUTEE)->  FIRST_TIME_ADDED
    2. Add followed by update (PERTURBEE) -> PREVIOUSLY_ADDED
    3. Delete followed by add -> 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

        # Test for add followed by update should be PREVIOUSLY_ADDED
        rt_update = model.RealTimeUpdate(input_trip_add,
                                         connector='cots',
                                         contributor='realtime.cots')
        trip_updates = KirinModelBuilder(dumb_nav_wrapper()).build(rt_update)
        _, log_dict = handle(rt_update,
                             trip_updates,
                             'realtime.cots',
                             is_new_complete=True)

        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

        # Clean database for further test
        tables = [str(table) for table in db.metadata.sorted_tables]
        db.session.execute('TRUNCATE {} CASCADE;'.format(', '.join(tables)))
        db.session.commit()

        # Delete the recently added trip followed by add: should be FIRST_TIME_ADDED
        rt_update = model.RealTimeUpdate(input_trip_add,
                                         connector='cots',
                                         contributor='realtime.cots')
        trip_updates = KirinModelBuilder(dumb_nav_wrapper()).build(rt_update)
        _, log_dict = handle(rt_update,
                             trip_updates,
                             'realtime.cots',
                             is_new_complete=True)
        input_trip_delete = get_fixture_data(
            'cots_train_151515_deleted_trip_with_delay_and_stop_time_added.json'
        )
        rt_update = model.RealTimeUpdate(input_trip_delete,
                                         connector='cots',
                                         contributor='realtime.cots')
        trip_updates = KirinModelBuilder(dumb_nav_wrapper()).build(rt_update)
        _, log_dict = handle(rt_update,
                             trip_updates,
                             'realtime.cots',
                             is_new_complete=True)

        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
Exemple #5
0
def test_retrieve_interesting_pdp():
    """
    In the example below:
    1st stop is probably just the garage (no time info) although it's a real station > NOT interesting
    2nd is a station and has a departure time > keeping it
    3rd is a station but has no departure nor arrival time > NOT interesting
    4th is a station (no typeArret is a station) and has departure/arrival times > keeping it
    5th is a station, doesn't have arrival time but we keep it as there is arrival time later in 7th
        (travelers are able to hop on, then hop off later) > keeping it
    6th is not a station > NOT interesting
    7th is a regular final traveler stop > keeping it
    8th is a station, doesn't have arrival time nor do the following stops > NOT interesting
    9th is in the same situation than 8th > NOT interesting
    """
    list_pdp = [{
        '@id': '1st',
        'typeArret': 'CD'
    }, {
        '@id': '2nd',
        'typeArret': 'CH',
        'horaireVoyageurDepart': {
            'dateHeure': '2018-09-01T12:02:00+0000'
        }
    }, {
        '@id': '3rd',
        'typeArret': 'FD'
    }, {
        '@id': '4th',
        'horaireVoyageurArrivee': {
            'dateHeure': '2018-09-01T12:04:00+0000'
        },
        'horaireVoyageurDepart': {
            'dateHeure': '2018-09-01T12:04:30+0000'
        }
    }, {
        '@id': '5th',
        'typeArret': 'FH',
        'horaireVoyageurDepart': {
            'dateHeure': '2018-09-01T12:05:00+0000'
        }
    }, {
        '@id': '6th',
        'typeArret': 'TOTO',
        'horaireVoyageurDepart': {
            'dateHeure': '2018-09-01T12:06:00+0000'
        }
    }, {
        '@id': '7th',
        'typeArret': 'CD',
        'horaireVoyageurArrivee': {
            'dateHeure': '2018-09-01T12:07:00+0000'
        }
    }, {
        '@id': '8th',
        'typeArret': None,
        'horaireVoyageurDepart': {
            'dateHeure': '2018-09-01T12:08:00+0000'
        }
    }, {
        '@id': '9th',
        'typeArret': ''
    }]
    assert _retrieve_interesting_pdp(list_pdp) == [
        list_pdp[1], list_pdp[3], list_pdp[4], list_pdp[6]
    ]
Exemple #6
0
def test_retrieve_interesting_pdp():
    """
    In the example below:
    1st stop is probably just the garage (no time info) although it's a real station > NOT interesting
    2nd is a station and has a departure time > keeping it
    3rd is a station but has no departure nor arrival time > NOT interesting
    4th is a station (no typeArret is a station) and has departure/arrival times > keeping it
    5th is a station, doesn't have arrival time but we keep it as there is arrival time later in 7th
        (travelers are able to hop on, then hop off later) > keeping it
    6th is not a station > NOT interesting
    7th is a regular final traveler stop > keeping it
    8th is a station, doesn't have arrival time nor do the following stops > NOT interesting
    9th is in the same situation than 8th > NOT interesting

    This also tests that they are sorted according to 'rang':
    [2nd, 4th, 5th, 7th] are indexed [1, 3, 8, 5] initially
    """
    list_pdp = [
        {
            "@id": "1st",
            "rang": 1,
            "typeArret": "CD"
        },
        {
            "@id": "2nd",
            "rang": 2,
            "typeArret": "CH",
            "horaireVoyageurDepart": {
                "dateHeure": "2018-09-01T12:02:00+0000"
            },
        },
        {
            "@id": "3rd",
            "rang": 3,
            "typeArret": "FD"
        },
        {
            "@id": "4th",
            "rang": 4,
            "horaireVoyageurArrivee": {
                "dateHeure": "2018-09-01T12:04:00+0000"
            },
            "horaireVoyageurDepart": {
                "dateHeure": "2018-09-01T12:04:30+0000"
            },
        },
        {
            "@id": "6th",
            "rang": 6,
            "typeArret": "TOTO",
            "horaireVoyageurDepart": {
                "dateHeure": "2018-09-01T12:06:00+0000"
            },
        },
        {
            "@id": "7th",
            "rang": 7,
            "typeArret": "CD",
            "horaireVoyageurArrivee": {
                "dateHeure": "2018-09-01T12:07:00+0000"
            },
        },
        {
            "@id": "8th",
            "rang": 8,
            "typeArret": None,
            "horaireVoyageurDepart": {
                "dateHeure": "2018-09-01T12:08:00+0000"
            },
        },
        {
            "@id": "9th",
            "rang": 9,
            "typeArret": ""
        },
        {
            "@id": "5th",
            "rang": 5,
            "typeArret": "FH",
            "horaireVoyageurDepart": {
                "dateHeure": "2018-09-01T12:05:00+0000"
            },
        },
    ]
    assert _retrieve_interesting_pdp(list_pdp) == [
        list_pdp[1], list_pdp[3], list_pdp[8], list_pdp[5]
    ]
Exemple #7
0
def test_get_action_on_trip_add(mock_navitia_fixture):
    """
    Test the function _get_action_on_trip with different type of flux cots
    returns:
    1. Fist trip add(AJOUTEE)->  FIRST_TIME_ADDED
    2. Add followed by update (PERTURBEE) -> PREVIOUSLY_ADDED
    3. Delete followed by add -> 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

        # Test for add followed by update should be PREVIOUSLY_ADDED
        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

        # Clean database for further test
        clean_db()

        # Delete the recently added trip followed by add: should be FIRST_TIME_ADDED
        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