diff options
author | Martin Polden <mpolden@mpolden.no> | 2023-03-04 12:31:26 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2023-03-04 12:31:26 +0100 |
commit | abe770c4200480726a42da722c8a760329432373 (patch) | |
tree | eba3fb6c2017f1091bdd3c8a5cdaa42870cc2804 | |
parent | 51da7de124cb2c58aaffc36918ab5d25f4b23f99 (diff) |
vaernesekspressen: follow api changes
-rw-r--r-- | docs/WIDGETS.md | 8 | ||||
-rw-r--r-- | jarvis/config.py.sample | 2 | ||||
-rw-r--r-- | jarvis/jobs/vaernesekspressen.py | 94 | ||||
-rw-r--r-- | jarvis/test_data/vaernesekspressen_departures.json | 2 | ||||
-rw-r--r-- | jarvis/test_data/vaernesekspressen_stops.json | 2 | ||||
-rwxr-xr-x | jarvis/tests.py | 31 |
6 files changed, 52 insertions, 87 deletions
diff --git a/docs/WIDGETS.md b/docs/WIDGETS.md index eb066a8..563444d 100644 --- a/docs/WIDGETS.md +++ b/docs/WIDGETS.md @@ -289,8 +289,7 @@ departures from the configured bus stop. JOBS["vaernesekspressen"] = { "enabled": True, "interval": 600, - "from_stop_id": 133, - # or "from_stop": "FB 73 Nidarosdomen", + "from_stop": "Solsiden", } ``` @@ -300,11 +299,6 @@ See the [Vaernesekspressen website](https://www.vaernesekspressen.no) for valid stop names. Trondheim airport is the only possible destination and is thus not configurable. -The `from_stop_id` field is the ID of a bust stop. When set this takes -precedence over `from_stop`. This is likely more robust in practice as the stop -name may change occasionally. Stop IDs can be found at -https://www.vaernesekspressen.no/Umbraco/Api/TicketOrderApi/GetStops?routeId=31. - yr -- Displays weather data from https://www.yr.no. The `url` field specifies the diff --git a/jarvis/config.py.sample b/jarvis/config.py.sample index 010ac68..0a67ae6 100644 --- a/jarvis/config.py.sample +++ b/jarvis/config.py.sample @@ -145,7 +145,7 @@ JOBS["uptime"] = { JOBS["vaernesekspressen"] = { "enabled": True, "interval": 600, - "from_stop": "FB 73 Nidarosdomen", + "from_stop": "Solsiden", "timeout": 10, # Very slow API "widget": "flybussen", } diff --git a/jarvis/jobs/vaernesekspressen.py b/jarvis/jobs/vaernesekspressen.py index 214a937..455437b 100644 --- a/jarvis/jobs/vaernesekspressen.py +++ b/jarvis/jobs/vaernesekspressen.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import re +import json import requests from datetime import datetime, timedelta @@ -9,78 +9,62 @@ from jobs import AbstractJob class Vaernesekspressen(AbstractJob): def __init__(self, conf): - self.airport_id = 113 # Vaernes is the the only supported destination self.from_stop = conf.get("from_stop") - self.from_stop_id = conf.get("from_stop_id") self.interval = conf["interval"] self.timeout = conf.get("timeout") - self.base_url = conf.get("base_url", "https://www.vaernesekspressen.no") + self.base_url = conf.get("base_url", "https://unibussticket.azurewebsites.net") self.now = datetime.now if self.from_stop is None and self.from_stop_id is None: raise ValueError("Either from_stop or from_stop_id must be set") - def _find_stop_id(self): - url = "{}/Umbraco/Api/TicketOrderApi/GetStops".format(self.base_url) - params = {"routeId": 31} # There is only one route - r = requests.get(url, params=params, timeout=self.timeout) + def _find_stop(self, now): + today = now.strftime("%Y-%m-%d") + url = f"{self.base_url}/api/operators/UNI:Operator:VerExp/lines/3/routes/8/stops?lang=no&date={today}" + r = requests.get(url, timeout=self.timeout) r.raise_for_status() for stop in r.json(): - if stop["Name"].lower() == self.from_stop.lower(): - return stop["Id"] + if stop["name"].lower() == self.from_stop.lower(): + return stop["id"], stop["name"] raise ValueError('Could not find ID for stop "{}"'.format(self.from_stop)) - def _timestamp(self, dt, tz): - # I hate Python. - utc_offset = timedelta(0) - if tz == "CET": - utc_offset = timedelta(hours=1) - elif tz == "CEST": - utc_offset = timedelta(hours=2) - else: - raise ValueError('Unexpected time zone "{}"'.format(tz)) - epoch = datetime(1970, 1, 1) - return (dt - utc_offset - epoch).total_seconds() - - def _parse_time(self, date): - parts = date.rsplit(" ", 1) - tz = parts[1] - dt = datetime.strptime(parts[0], "%Y-%m-%d %H:%M:%S.0") - return int(self._timestamp(dt, tz)) - - def _departures(self, stop_id, dt): - url = "{}/Umbraco/Api/TicketOrderApi/GetJourneys".format(self.base_url) + def _departures(self, stop_id, stop_name, dt): + url = f"{self.base_url}/api/operators/UNI:Operator:VerExp/lines/3/routes/8/departures" + today = dt.strftime("%Y-%m-%d") data = { - "From": str(stop_id), - "To": str(self.airport_id), - "Route": "31", - "Date": dt.strftime("%d.%m.%Y"), - "Adult": "1", - "Student": "0", - "Child": "0", - "Baby": "0", - "Senior": "0", - "isRoundTrip": False, + "from": str(stop_id), + "to": "NSR:Quay:100211", # Trondheim lufthavn + "date": today, + "type": "NORMAL", + "travelers": json.dumps( + [ + { + "travellerProfileId": 1, + "maximumAge": 120, + "isAdult": True, + "name": "Voksen", + "count": 1, + } + ] + ), } - r = requests.post(url, json=data, timeout=self.timeout) + r = requests.get(url, params=data, timeout=self.timeout) r.raise_for_status() - return [ - { - "stop_name": self._trim_name(d["Start"]["Name"]), - "destination_name": self._trim_name(d["End"]["Name"]), - "departure_time": str(self._parse_time(d["DepartureTime"])), + departures = [] + for d in r.json(): + time = f"{today} {d['time']}" + departure_time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S") + departure = { + "stop_name": stop_name, + "destination_name": "Trondheim lufthavn", + "departure_time": int(departure_time.timestamp()), } - for d in r.json() - ] - - def _trim_name(self, name): - return re.sub(r"^FB \d+ ", "", name) + departures.append(departure) + return departures def get(self): - stop_id = self.from_stop_id - if stop_id is None: - stop_id = self._find_stop_id() now = self.now() - departures = self._departures(stop_id, now) + stop_id, stop_name = self._find_stop(now) + departures = self._departures(stop_id, stop_name, now) if len(departures) < 2: # Few departures today, include tomorrow's departures tomorrow = (now + timedelta(days=1)).date() diff --git a/jarvis/test_data/vaernesekspressen_departures.json b/jarvis/test_data/vaernesekspressen_departures.json index ad34923..9c90b72 100644 --- a/jarvis/test_data/vaernesekspressen_departures.json +++ b/jarvis/test_data/vaernesekspressen_departures.json @@ -1 +1 @@ -[{"Departure":263468,"DepartureTime":"2020-02-01 16:15:00.0 CET","ArrivalTime":"2020-02-01 17:00:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263469,"DepartureTime":"2020-02-01 16:30:00.0 CET","ArrivalTime":"2020-02-01 17:15:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263470,"DepartureTime":"2020-02-01 16:45:00.0 CET","ArrivalTime":"2020-02-01 17:30:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263471,"DepartureTime":"2020-02-01 17:00:00.0 CET","ArrivalTime":"2020-02-01 17:45:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263472,"DepartureTime":"2020-02-01 17:15:00.0 CET","ArrivalTime":"2020-02-01 18:00:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263473,"DepartureTime":"2020-02-01 17:45:00.0 CET","ArrivalTime":"2020-02-01 18:30:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263474,"DepartureTime":"2020-02-01 18:15:00.0 CET","ArrivalTime":"2020-02-01 19:00:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263475,"DepartureTime":"2020-02-01 18:45:00.0 CET","ArrivalTime":"2020-02-01 19:30:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}},{"Departure":263476,"DepartureTime":"2020-02-01 19:15:00.0 CET","ArrivalTime":"2020-02-01 20:00:00.0 CET","IsClosed":false,"Start":{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},"End":{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"},"Notice":"","LowPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]},"FullPrices":{"TripPrices":[{"Amount":139,"PassengerType":1}]}}]
\ No newline at end of file +[{"id":156472,"time":"12:00:00","journey":6571,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156672,"time":"12:30:00","journey":6579,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156497,"time":"13:00:00","journey":6572,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156522,"time":"13:30:00","journey":6573,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156547,"time":"14:00:00","journey":6574,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156747,"time":"14:30:00","journey":6582,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156572,"time":"15:00:00","journey":6575,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156597,"time":"15:30:00","journey":6576,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156622,"time":"16:00:00","journey":6577,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156397,"time":"16:30:00","journey":6568,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156272,"time":"17:00:00","journey":6563,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156647,"time":"17:30:00","journey":6578,"price":199,"netPrice":177.68,"duration":35,"info":""},{"id":156722,"time":"18:30:00","journey":6581,"price":199,"netPrice":177.68,"duration":35,"info":""}] diff --git a/jarvis/test_data/vaernesekspressen_stops.json b/jarvis/test_data/vaernesekspressen_stops.json index 07d4e4e..3c2692d 100644 --- a/jarvis/test_data/vaernesekspressen_stops.json +++ b/jarvis/test_data/vaernesekspressen_stops.json @@ -1 +1 @@ -[{"Id":178,"Name":"FB 73 Nidarvoll skole","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":182,"Name":"FB 73 Nardokrysset/Omkjøringsvegen","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":142,"Name":"FB 73 Voll studentby","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":141,"Name":"FB 73 Moholt studentby","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":140,"Name":"FB 73 Østre Berg ","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":139,"Name":"FB 73 Berg studentby ","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":179,"Name":"FB 73 Lerkendal gård","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":183,"Name":"FB 73 Scandic Lerkendal","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":180,"Name":"FB 73 Lerkendal stadion","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":128,"Name":"FB 73 Hesthagen.","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":130,"Name":"FB 73 Studentersamfundet","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":133,"Name":"FB 73 Nidarosdomen","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":131,"Name":"FB 73 Dronningens gate D2","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":158,"Name":"FB 73 Britannia hotell (betjent kun FRA Værnes)","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":157,"Name":"FB 73 Radisson BLU Royal Garden","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":151,"Name":"FB 73 Søndre gate v/Chesterfield hotell","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":160,"Name":"FB 73 Bakkegata","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":155,"Name":"FB 73 Solsiden","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":186,"Name":"FB 75 Pirbadet (Clarion Congress)","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":188,"Name":"FB 75 Buran","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":190,"Name":"FB 75 Rønningsbakken","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":192,"Name":"FB 75 Dalen Hageby","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":193,"Name":"FB 75 Strindheim","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":194,"Name":"FB 75 Gildheim","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":195,"Name":"FB 75 Leangen Travbane","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":196,"Name":"FB 75 Ranheim fabrikker E6","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":197,"Name":"FB 75 Leistadkrysset","Description":"","Destinations":[{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4"}]},{"Id":113,"Name":"Trondheim Lufthavn Værnes","Description":"Påstigning holdeplass A4","Destinations":[{"Id":178,"Name":"FB 73 Nidarvoll skole","Description":""},{"Id":182,"Name":"FB 73 Nardokrysset/Omkjøringsvegen","Description":""},{"Id":142,"Name":"FB 73 Voll studentby","Description":""},{"Id":141,"Name":"FB 73 Moholt studentby","Description":""},{"Id":140,"Name":"FB 73 Østre Berg ","Description":""},{"Id":139,"Name":"FB 73 Berg studentby ","Description":""},{"Id":179,"Name":"FB 73 Lerkendal gård","Description":""},{"Id":183,"Name":"FB 73 Scandic Lerkendal","Description":""},{"Id":180,"Name":"FB 73 Lerkendal stadion","Description":""},{"Id":128,"Name":"FB 73 Hesthagen.","Description":""},{"Id":130,"Name":"FB 73 Studentersamfundet","Description":""},{"Id":133,"Name":"FB 73 Nidarosdomen","Description":""},{"Id":131,"Name":"FB 73 Dronningens gate D2","Description":""},{"Id":158,"Name":"FB 73 Britannia hotell (betjent kun FRA Værnes)","Description":""},{"Id":157,"Name":"FB 73 Radisson BLU Royal Garden","Description":""},{"Id":151,"Name":"FB 73 Søndre gate v/Chesterfield hotell","Description":""},{"Id":160,"Name":"FB 73 Bakkegata","Description":""},{"Id":155,"Name":"FB 73 Solsiden","Description":""},{"Id":186,"Name":"FB 75 Pirbadet (Clarion Congress)","Description":""},{"Id":188,"Name":"FB 75 Buran","Description":""},{"Id":190,"Name":"FB 75 Rønningsbakken","Description":""},{"Id":192,"Name":"FB 75 Dalen Hageby","Description":""},{"Id":193,"Name":"FB 75 Strindheim","Description":""},{"Id":194,"Name":"FB 75 Gildheim","Description":""},{"Id":195,"Name":"FB 75 Leangen Travbane","Description":""},{"Id":196,"Name":"FB 75 Ranheim fabrikker E6","Description":""},{"Id":197,"Name":"FB 75 Leistadkrysset","Description":""}]}]
\ No newline at end of file +[{"id":"NSR:Quay:73979","name":"Nidarvoll skole"},{"id":"NSR:Quay:74658","name":"Omkjøringsveien Nardo"},{"id":"NSR:Quay:72401","name":"Voll studentby"},{"id":"NSR:Quay:73260","name":"Moholt studentby"},{"id":"NSR:Quay:72852","name":"Østre Berg Ligger i Dybdahls veg mot sentrum"},{"id":"NSR:Quay:74954","name":"Berg studentby"},{"id":"NSR:Quay:73415","name":"Lerkendal gård"},{"id":"NSR:Quay:99507","name":"Scandic Lerkendal hotell"},{"id":"NSR:Quay:73421","name":"Lerkendal i Strindvegen ved gressvoll"},{"id":"NSR:Quay:71204","name":"Hesthagen"},{"id":"NSR:Quay:73101","name":"Studentersamfundet i Elgsetergate ved Studentersamfundet"},{"id":"NSR:Quay:71175","name":"Nidarosdomen"},{"id":"NSR:Quay:74649","name":"Dronningens gate ved Deli de Luca"},{"id":"NSR:Quay:73574","name":"Søndre gate Regionbuss"},{"id":"NSR:Quay:74793","name":"Bakkegata"},{"id":"NSR:Quay:73976","name":"Solsiden"},{"id":"NSR:Quay:103007","name":"Buran i Innherredsveien ut av sentrum"},{"id":"NSR:Quay:71686","name":"Rønningsbakken"},{"id":"NSR:Quay:74498","name":"Dalen Hageby"},{"id":"NSR:Quay:73033","name":"Strindheim i Innherredsveien over veien for Sirkus shopping"},{"id":"NSR:Quay:75658","name":"Gildheim"},{"id":"NSR:Quay:71363","name":"Leangen"},{"id":"NSR:Quay:71246","name":"Ranheim fabrikker E6"},{"id":"NSR:Quay:73356","name":"Leistadkrysset"}] diff --git a/jarvis/tests.py b/jarvis/tests.py index d27a2f5..27c9edc 100755 --- a/jarvis/tests.py +++ b/jarvis/tests.py @@ -431,14 +431,12 @@ class Flybussen(unittest.TestCase): class Vaernesekspressen(unittest.TestCase): def _test_responses(self): - stop_path = "/Umbraco/Api/TicketOrderApi/GetStops?routeId=31" - departure_path = "/Umbraco/Api/TicketOrderApi/GetJourneys" + stop_path = "/api/operators/UNI:Operator:VerExp/lines/3/routes/8/stops?lang=no&date=2020-02-01" + departure_path = "/api/operators/UNI:Operator:VerExp/lines/3/routes/8/departures?from=NSR%3AQuay%3A73976&to=NSR%3AQuay%3A100211&date=2020-02-01&type=NORMAL&travelers=%5B%7B%22travellerProfileId%22%3A+1%2C+%22maximumAge%22%3A+120%2C+%22isAdult%22%3A+true%2C+%22name%22%3A+%22Voksen%22%2C+%22count%22%3A+1%7D%5D" return { "GET": { stop_path: test_data("vaernesekspressen_stops.json", True), - }, - "POST": { - departure_path: test_data("vaernesekspressen_departures.json", True) + departure_path: test_data("vaernesekspressen_departures.json", True), }, } @@ -453,26 +451,15 @@ class Vaernesekspressen(unittest.TestCase): self.p = Process(target=self.server.serve_forever) self.p.start() - def test_get_by_name(self): - self._get(stop_name="fb 73 nidarosdomen") - - def test_get_by_id(self): - self._get(stop_id=131) - - def _get(self, stop_id=None, stop_name=None): - config = {"interval": None, "base_url": self.url} - if stop_id is not None: - config["from_stop_id"] = stop_id - if stop_name is not None: - config["from_stop"] = stop_name + def test_get(self, stop_id=None, stop_name=None): + config = {"interval": None, "base_url": self.url, "from_stop": "solsiden"} f = vaernesekspressen.Vaernesekspressen(config) f.now = lambda: datetime(2020, 2, 1, 10) data = f.get() - self.assertEqual(9, len(data["departures"])) - self.assertEqual("1580570100", data["departures"][0]["departure_time"]) - self.assertEqual("Nidarosdomen", data["departures"][0]["stop_name"]) - self.assertEqual("Nidarosdomen", data["from"]) - self.assertEqual("Trondheim Lufthavn Værnes", data["to"]) + self.assertEqual(13, len(data["departures"])) + self.assertEqual(1580554800, data["departures"][0]["departure_time"]) + self.assertEqual("Solsiden", data["departures"][0]["stop_name"]) + self.assertEqual("Trondheim lufthavn", data["to"]) def tearDown(self): self.server.socket.close() |