moved tests to enhancer
This commit is contained in:
parent
532a229c46
commit
3638e81d08
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -160,3 +160,4 @@ cython_debug/
|
||||||
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
|
data/
|
||||||
0
amarillo/plugins/enhancer/tests/__init__.py
Normal file
0
amarillo/plugins/enhancer/tests/__init__.py
Normal file
5
amarillo/plugins/enhancer/tests/stops.csv
Normal file
5
amarillo/plugins/enhancer/tests/stops.csv
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
stop_id;stop_code;stop_lat;stop_lon;stop_name
|
||||||
|
mfdz:x;x;52.11901;14.2;Stop x
|
||||||
|
mfdz:y;y;53.1;14.01;Stop y
|
||||||
|
mfdz:z;z;54.11;14.0;Stop z
|
||||||
|
mfdz:Ang001;Ang001;53.11901;14.015776;Mitfahrbank Biesenbrow
|
||||||
|
39
amarillo/plugins/enhancer/tests/stops.json
Normal file
39
amarillo/plugins/enhancer/tests/stops.json
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"pointsOfInterest": [
|
||||||
|
{
|
||||||
|
"id": "14622",
|
||||||
|
"externalId": "bbnavi:12073:0001",
|
||||||
|
"name": "Parkbank",
|
||||||
|
"description": "Parkbank",
|
||||||
|
"dataProvider": {
|
||||||
|
"id": "1",
|
||||||
|
"name": "Administrator"
|
||||||
|
},
|
||||||
|
"addresses": [
|
||||||
|
{
|
||||||
|
"street": "Hauptstrasse",
|
||||||
|
"city": "Wittenberge",
|
||||||
|
"zip": "12345",
|
||||||
|
"geoLocation": {
|
||||||
|
"latitude": 52.9932971109789,
|
||||||
|
"longitude": 11.767383582547
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"openStreetMap": {
|
||||||
|
"capacity": 112,
|
||||||
|
"capacityCharging": "2",
|
||||||
|
"capacityDisabled": "",
|
||||||
|
"fee": "No",
|
||||||
|
"lit": "Yes",
|
||||||
|
"parking": "",
|
||||||
|
"shelter": "No",
|
||||||
|
"surface": "",
|
||||||
|
"utilization": "",
|
||||||
|
"website": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
142
amarillo/plugins/enhancer/tests/test_gtfs.py
Normal file
142
amarillo/plugins/enhancer/tests/test_gtfs.py
Normal file
|
|
@ -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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
24
amarillo/plugins/enhancer/tests/test_stops_store.py
Normal file
24
amarillo/plugins/enhancer/tests/test_stops_store.py
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
from amarillo.plugins.enhancer.services import stops
|
||||||
|
from amarillo.models.Carpool import StopTime
|
||||||
|
|
||||||
|
def test_load_stops_from_file():
|
||||||
|
store = stops.StopsStore([{"url": "amarillo/plugins/enhancer/tests/stops.csv", "vicinity": 50}])
|
||||||
|
store.load_stop_sources()
|
||||||
|
assert len(store.stopsDataFrames[0]['stops']) > 0
|
||||||
|
|
||||||
|
def test_load_csv_stops_from_web_():
|
||||||
|
store = stops.StopsStore([{"url": "https://data.mfdz.de/mfdz/stops/custom.csv", "vicinity": 50}])
|
||||||
|
store.load_stop_sources()
|
||||||
|
assert len(store.stopsDataFrames[0]['stops']) > 0
|
||||||
|
|
||||||
|
def test_load_geojson_stops_from_web_():
|
||||||
|
store = stops.StopsStore([{"url": "https://datahub.bbnavi.de/export/rideshare_points.geojson", "vicinity": 50}])
|
||||||
|
store.load_stop_sources()
|
||||||
|
assert len(store.stopsDataFrames[0]['stops']) > 0
|
||||||
|
|
||||||
|
def test_find_closest_stop():
|
||||||
|
store = stops.StopsStore([{"url": "amarillo/plugins/enhancer/tests/stops.csv", "vicinity": 50}])
|
||||||
|
store.load_stop_sources()
|
||||||
|
carpool_stop = StopTime(name="start", lat=53.1191, lon=14.01577)
|
||||||
|
stop = store.find_closest_stop(carpool_stop, 1000)
|
||||||
|
assert stop.name=='Mitfahrbank Biesenbrow'
|
||||||
23
amarillo/plugins/enhancer/tests/test_trip_store.py
Normal file
23
amarillo/plugins/enhancer/tests/test_trip_store.py
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
from amarillo.tests.sampledata import cp1, carpool_repeating
|
||||||
|
from amarillo.plugins.enhancer.services.trips import TripStore
|
||||||
|
from amarillo.plugins.enhancer.services.stops import StopsStore
|
||||||
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def test_trip_store_put_one_time_carpool():
|
||||||
|
trip_store = TripStore(StopsStore())
|
||||||
|
|
||||||
|
t = trip_store.put_carpool(cp1)
|
||||||
|
assert t != None
|
||||||
|
assert len(t.stop_times) >= 2
|
||||||
|
assert t.stop_times[0].stop_id == 'mfdz:12073:001'
|
||||||
|
assert t.stop_times[-1].stop_id == 'de:12073:900340137::3'
|
||||||
|
|
||||||
|
def test_trip_store_put_repeating_carpool():
|
||||||
|
trip_store = TripStore(StopsStore())
|
||||||
|
|
||||||
|
t = trip_store.put_carpool(carpool_repeating)
|
||||||
|
assert t != None
|
||||||
|
assert len(t.stop_times) >= 2
|
||||||
5
config
Normal file
5
config
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Bounding-Box Germany
|
||||||
|
ride2go_query_data = '{ "southWestCoordinates": { "lat": 47.3, "lon": 5.98 }, "northEastCoordinates": { "lat": 54.99, "lon": 15.02 }, "lastModifiedSinceDays": 180 }'
|
||||||
|
env = 'PROD'
|
||||||
|
graphhopper_base_url = 'https://api.mfdz.de/gh'
|
||||||
|
stop_sources_file = 'conf/stop_sources.json'
|
||||||
22
logging.conf
Normal file
22
logging.conf
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
[loggers]
|
||||||
|
keys=root
|
||||||
|
|
||||||
|
[handlers]
|
||||||
|
keys=consoleHandler
|
||||||
|
|
||||||
|
[formatters]
|
||||||
|
keys=simpleFormatter
|
||||||
|
|
||||||
|
[logger_root]
|
||||||
|
level=INFO
|
||||||
|
handlers=consoleHandler
|
||||||
|
propagate=yes
|
||||||
|
|
||||||
|
[handler_consoleHandler]
|
||||||
|
class=StreamHandler
|
||||||
|
level=DEBUG
|
||||||
|
formatter=simpleFormatter
|
||||||
|
args=(sys.stdout,)
|
||||||
|
|
||||||
|
[formatter_simpleFormatter]
|
||||||
|
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||||
Loading…
Reference in a new issue