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
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