diff --git a/MANIFEST.in b/MANIFEST.in index 5aae476..c3190c3 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ -recursive-include amarillo/static/ * \ No newline at end of file +recursive-include amarillo/static/ * +recursive-include amarillo/app/tests/ * \ No newline at end of file diff --git a/amarillo/app/tests/__init__.py b/amarillo/app/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/amarillo/app/tests/stops.csv b/amarillo/app/tests/stops.csv new file mode 100644 index 0000000..ed419bb --- /dev/null +++ b/amarillo/app/tests/stops.csv @@ -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 diff --git a/amarillo/app/tests/stops.json b/amarillo/app/tests/stops.json new file mode 100644 index 0000000..5744c13 --- /dev/null +++ b/amarillo/app/tests/stops.json @@ -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": "" + } + } + ] + } +} \ No newline at end of file diff --git a/amarillo/app/tests/test_stops_store.py b/amarillo/app/tests/test_stops_store.py new file mode 100644 index 0000000..e70f774 --- /dev/null +++ b/amarillo/app/tests/test_stops_store.py @@ -0,0 +1,24 @@ +from amarillo.app.services import stops +from amarillo.app.models.Carpool import StopTime + +def test_load_stops_from_file(): + store = stops.StopsStore([{"url": "amarillo/app/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/app/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' diff --git a/amarillo/app/tests/test_trip_store.py b/amarillo/app/tests/test_trip_store.py new file mode 100644 index 0000000..64a3665 --- /dev/null +++ b/amarillo/app/tests/test_trip_store.py @@ -0,0 +1,23 @@ +from amarillo.app.tests.sampledata import cp1, carpool_repeating +from amarillo.app.services.trips import TripStore +from amarillo.app.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 diff --git a/pyproject.toml b/pyproject.toml index a036372..1090010 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "amarillo-core" -version = "0.0.9" +version = "0.0.11" dependencies = [ "fastapi[all]==0.104.0", "geopandas==0.14", @@ -11,6 +11,7 @@ dependencies = [ "requests==2.31.0", "pyproj==3.6.1", "geojson-pydantic==1.0.1", + "pytest", ] [tool.setuptools.packages] diff --git a/requirements.txt b/requirements.txt index 8771f13..84b950e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,5 @@ protobuf==3.20.3 starlette requests==2.31.0 pyproj==3.6.1 -geojson-pydantic==1.0.1 \ No newline at end of file +geojson-pydantic==1.0.1 +pytest \ No newline at end of file