def test_process_timezones(self): mock_stops = PropertyMock(return_value=pd.DataFrame( {STOP_TIMEZONE: [MONTREAL_TIMEZONE, TORONTO_TIMEZONE]})) mock_agency = PropertyMock( return_value=pd.DataFrame({AGENCY_TIMEZONE: [MONTREAL_TIMEZONE]})) mock_dataset = MagicMock() mock_dataset.__class__ = Feed type(mock_dataset).agency = mock_agency type(mock_dataset).stops = mock_stops mock_metadata = MagicMock() mock_metadata.__class__ = GtfsMetadata mock_gtfs_representation = MagicMock() mock_gtfs_representation.__class__ = GtfsRepresentation type(mock_gtfs_representation).dataset = mock_dataset type(mock_gtfs_representation).metadata = mock_metadata under_test = process_timezones_for_gtfs_metadata( mock_gtfs_representation) self.assertIsInstance(under_test, GtfsRepresentation) mock_stops.assert_called() mock_agency.assert_called() self.assertEqual(mock_metadata.main_timezone, MONTREAL_TIMEZONE) self.assertEqual(mock_metadata.other_timezones, [TORONTO_TIMEZONE])
def call_usecases( dataset_representation, source_name, dataset_url, api_url, username, password ): dataset_representation = process_start_service_date_for_gtfs_metadata( dataset_representation ) dataset_representation = process_end_service_date_for_gtfs_metadata( dataset_representation ) # TODO: fix the actual issue. might be taken care of once validator is deployed. try: dataset_representation = process_start_timestamp_for_gtfs_metadata( dataset_representation ) except TypeError as te: print( f"process_start_timestamp_for_gtfs_metadata for source {source_name}," f"dataset {dataset_url} raised: \n {te}", file=sys.stderr, ) try: dataset_representation = process_end_timestamp_for_gtfs_metadata( dataset_representation ) except TypeError as te: print( f"process_end_timestamp_for_gtfs_metadata for source {source_name}, dataset {dataset_url} raised: \n {te}", file=sys.stderr, ) dataset_representation = process_main_language_code_for_gtfs_metadata( dataset_representation ) dataset_representation = process_timezones_for_gtfs_metadata(dataset_representation) dataset_representation = process_bounding_box_for_gtfs_metadata( dataset_representation ) dataset_representation = process_bounding_octagon_for_gtfs_metadata( dataset_representation ) dataset_representation = process_agencies_count_for_gtfs_metadata( dataset_representation ) dataset_representation = process_routes_count_by_type_for_gtfs_metadata( dataset_representation ) dataset_representation = process_stops_count_by_type_for_gtfs_metadata( dataset_representation ) dataset_representation = create_dataset_entity_for_gtfs_metadata( dataset_representation, api_url, username, password ) return dataset_representation
def test_process_timezones_with_missing_files(self): mock_dataset = MagicMock() mock_dataset.__class__ = Feed mock_metadata = MagicMock() mock_metadata.__class__ = GtfsMetadata mock_gtfs_representation = MagicMock() mock_gtfs_representation.__class__ = GtfsRepresentation type(mock_gtfs_representation).dataset = mock_dataset type(mock_gtfs_representation).metadata = mock_metadata under_test = process_timezones_for_gtfs_metadata( mock_gtfs_representation) self.assertIsInstance(under_test, GtfsRepresentation)
def test_process_timezones_with_missing_fields(self): mock_agency = PropertyMock(return_value=pd.DataFrame({})) mock_stops = PropertyMock(return_value=pd.DataFrame({})) mock_dataset = MagicMock() mock_dataset.__class__ = Feed type(mock_dataset).agency = mock_agency type(mock_dataset).stops = mock_stops mock_metadata = MagicMock() mock_metadata.__class__ = GtfsMetadata mock_gtfs_representation = MagicMock() mock_gtfs_representation.__class__ = GtfsRepresentation type(mock_gtfs_representation).dataset = mock_dataset type(mock_gtfs_representation).metadata = mock_metadata under_test = process_timezones_for_gtfs_metadata( mock_gtfs_representation) self.assertIsInstance(under_test, GtfsRepresentation) mock_metadata.main_timezone.assert_not_called() mock_metadata.other_timezones.assert_not_called()
dataset_key, dataset_representation, ) in data_repository.get_dataset_representations().items(): dataset_representation = process_country_codes_for_gtfs_metadata( dataset_representation) dataset_representation = process_start_service_date_for_gtfs_metadata( dataset_representation) dataset_representation = process_end_service_date_for_gtfs_metadata( dataset_representation) dataset_representation = process_start_timestamp_for_gtfs_metadata( dataset_representation) dataset_representation = process_end_timestamp_for_gtfs_metadata( dataset_representation) dataset_representation = process_main_language_code_for_gtfs_metadata( dataset_representation) dataset_representation = process_timezones_for_gtfs_metadata( dataset_representation) dataset_representation = process_bounding_box_for_gtfs_metadata( dataset_representation) dataset_representation = process_bounding_octagon_for_gtfs_metadata( dataset_representation) dataset_representation = process_agencies_count_for_gtfs_metadata( dataset_representation) dataset_representation = process_routes_count_by_type_for_gtfs_metadata( dataset_representation) dataset_representation = process_stops_count_by_type_for_gtfs_metadata( dataset_representation) dataset_representation = create_dataset_entity_for_gtfs_metadata( dataset_representation, api_url) # Print results data_repository.print_dataset_representation(dataset_key)