From 68f19aa56f25adcfd651ffbf7d42a080635c8524 Mon Sep 17 00:00:00 2001 From: Francia Csaba Date: Fri, 9 Feb 2024 14:30:02 +0100 Subject: [PATCH] test_gtfs.py --- .../plugins/gtfs_export/tests/__init__.py | 0 .../plugins/gtfs_export/tests/test_gtfs.py | 142 ++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 amarillo/plugins/gtfs_export/tests/__init__.py create mode 100644 amarillo/plugins/gtfs_export/tests/test_gtfs.py diff --git a/amarillo/plugins/gtfs_export/tests/__init__.py b/amarillo/plugins/gtfs_export/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/amarillo/plugins/gtfs_export/tests/test_gtfs.py b/amarillo/plugins/gtfs_export/tests/test_gtfs.py new file mode 100644 index 0000000..3fbe97c --- /dev/null +++ b/amarillo/plugins/gtfs_export/tests/test_gtfs.py @@ -0,0 +1,142 @@ +from amarillo.tests.sampledata import carpool_1234, data1, carpool_repeating_json, stop_issue +from amarillo.plugins.enhancer.services.gtfs_export import GtfsExport +from amarillo.plugins.enhancer.services.gtfs import GtfsRtProducer +from amarillo.plugins.enhancer.services.stops import StopsStore +from amarillo.plugins.enhancer.services.trips import TripStore +from amarillo.models.Carpool import Carpool +from datetime import datetime +import time +import pytest + + +def test_gtfs_generation(): + cp = Carpool(**data1) + stops_store = StopsStore() + trips_store = TripStore(stops_store) + trips_store.put_carpool(cp) + + exporter = GtfsExport(None, None, trips_store, stops_store) + exporter.export('target/tests/test_gtfs_generation/test.gtfs.zip', "target/tests/test_gtfs_generation") + +def test_correct_stops(): + cp = Carpool(**stop_issue) + stops_store = StopsStore([{"url": "https://datahub.bbnavi.de/export/rideshare_points.geojson", "vicinity": 250}]) + stops_store.load_stop_sources() + trips_store = TripStore(stops_store) + trips_store.put_carpool(cp) + assert len(trips_store.trips) == 1 + + +class TestTripConverter: + + def setup_method(self, method): + self.stops_store = StopsStore([{"url": "https://datahub.bbnavi.de/export/rideshare_points.geojson", "vicinity": 50}]) + self.trips_store = TripStore(self.stops_store) + + def test_as_one_time_trip_as_delete_update(self): + cp = Carpool(**data1) + self.trips_store.put_carpool(cp) + trip = next(iter(self.trips_store.trips.values())) + + converter = GtfsRtProducer(self.trips_store) + json = converter._as_delete_updates(trip, datetime(2022,4,11)) + + assert json == [{ + 'trip': { + 'tripId': 'mfdz:Eins', + 'startTime': '23:59:00', + 'startDate': '20220530', + 'scheduleRelationship': 'CANCELED', + 'routeId': 'mfdz:Eins' + } + }] + + def test_as_one_time_trip_as_added_update(self): + cp = Carpool(**data1) + self.trips_store.put_carpool(cp) + trip = next(iter(self.trips_store.trips.values())) + + converter = GtfsRtProducer(self.trips_store) + json = converter._as_added_updates(trip, datetime(2022,4,11)) + assert json == [{ + 'trip': { + 'tripId': 'mfdz:Eins', + 'startTime': '23:59:00', + 'startDate': '20220530', + 'scheduleRelationship': 'ADDED', + 'routeId': 'mfdz:Eins', + '[transit_realtime.trip_descriptor]': { + 'routeUrl' : 'https://mfdz.de/trip/123', + 'agencyId' : 'mfdz', + 'route_long_name' : 'abc nach xyz', + 'route_type': 1551 + } + }, + 'stopTimeUpdate': [{ + 'stopSequence': 1, + 'arrival': { + 'time': time.mktime(datetime(2022,5,30,23,59,0).timetuple()), + 'uncertainty': 600 + }, + 'departure': { + 'time': time.mktime(datetime(2022,5,30,23,59,0).timetuple()), + 'uncertainty': 600 + }, + 'stopId': 'mfdz:12073:001', + 'scheduleRelationship': 'SCHEDULED', + 'stop_time_properties': { + '[transit_realtime.stop_time_properties]': { + 'dropoffType': 'NONE', + 'pickupType': 'COORDINATE_WITH_DRIVER' + } + } + }, + { + 'stopSequence': 2, + 'arrival': { + 'time': time.mktime(datetime(2022,5,31,0,16,45,0).timetuple()), + 'uncertainty': 600 + }, + 'departure': { + 'time': time.mktime(datetime(2022,5,31,0,16,45,0).timetuple()), + 'uncertainty': 600 + }, + + 'stopId': 'de:12073:900340137::3', + 'scheduleRelationship': 'SCHEDULED', + 'stop_time_properties': { + '[transit_realtime.stop_time_properties]': { + 'dropoffType': 'COORDINATE_WITH_DRIVER', + 'pickupType': 'NONE' + } + } + }] + }] + + def test_as_periodic_trip_as_delete_update(self): + cp = Carpool(**carpool_repeating_json) + self.trips_store.put_carpool(cp) + trip = next(iter(self.trips_store.trips.values())) + + converter = GtfsRtProducer(self.trips_store) + json = converter._as_delete_updates(trip, datetime(2022,4,11)) + + assert json == [{ + 'trip': { + 'tripId': 'mfdz:Zwei', + 'startTime': '15:00:00', + 'startDate': '20220411', + 'scheduleRelationship': 'CANCELED', + 'routeId': 'mfdz:Zwei' + } + }, + { + 'trip': { + 'tripId': 'mfdz:Zwei', + 'startTime': '15:00:00', + 'startDate': '20220418', + 'scheduleRelationship': 'CANCELED', + 'routeId': 'mfdz:Zwei' + } + } + ] \ No newline at end of file