Fix trip map unbooked flight pins and timezone-safe busy date comparisons
This commit is contained in:
parent
f38c5327ea
commit
f9b79d5a51
3 changed files with 150 additions and 7 deletions
101
tests/test_trip.py
Normal file
101
tests/test_trip.py
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
"""Tests for trip map coordinate assembly."""
|
||||
|
||||
from datetime import date
|
||||
|
||||
import agenda.trip
|
||||
from agenda.types import Trip
|
||||
from web_view import app
|
||||
|
||||
|
||||
def test_add_coordinates_for_unbooked_flights_adds_missing_airports() -> None:
|
||||
"""Unbooked routes should contribute missing airport pins."""
|
||||
routes = [
|
||||
{
|
||||
"type": "unbooked_flight",
|
||||
"key": "LHR_Paris_fr",
|
||||
"from_iata": "LHR",
|
||||
"to_iata": "CDG",
|
||||
"from": (51.47, -0.45),
|
||||
"to": (49.01, 2.55),
|
||||
}
|
||||
]
|
||||
coordinates = [
|
||||
{
|
||||
"name": "Heathrow Airport",
|
||||
"type": "airport",
|
||||
"latitude": 51.47,
|
||||
"longitude": -0.45,
|
||||
}
|
||||
]
|
||||
airports = {
|
||||
"LHR": {
|
||||
"name": "Heathrow Airport",
|
||||
"latitude": 51.47,
|
||||
"longitude": -0.45,
|
||||
},
|
||||
"CDG": {
|
||||
"name": "Paris Charles de Gaulle Airport",
|
||||
"latitude": 49.01,
|
||||
"longitude": 2.55,
|
||||
},
|
||||
}
|
||||
|
||||
with app.app_context():
|
||||
original_parse_yaml = agenda.trip.travel.parse_yaml
|
||||
try:
|
||||
agenda.trip.travel.parse_yaml = lambda _name, _data_dir: airports
|
||||
agenda.trip.add_coordinates_for_unbooked_flights(routes, coordinates)
|
||||
finally:
|
||||
agenda.trip.travel.parse_yaml = original_parse_yaml
|
||||
|
||||
airport_names = {
|
||||
coord["name"] for coord in coordinates if coord["type"] == "airport"
|
||||
}
|
||||
assert airport_names == {"Heathrow Airport", "Paris Charles de Gaulle Airport"}
|
||||
|
||||
|
||||
def test_get_coordinates_and_routes_adds_unbooked_flight_airports() -> None:
|
||||
"""Trip list map data should include pins for unbooked flights."""
|
||||
trips = [Trip(start=date(2026, 7, 20))]
|
||||
unbooked_routes = [
|
||||
{
|
||||
"type": "unbooked_flight",
|
||||
"key": "LHR_Paris_fr",
|
||||
"from_iata": "LHR",
|
||||
"to_iata": "CDG",
|
||||
"from": (51.47, -0.45),
|
||||
"to": (49.01, 2.55),
|
||||
}
|
||||
]
|
||||
airports = {
|
||||
"LHR": {
|
||||
"name": "Heathrow Airport",
|
||||
"latitude": 51.47,
|
||||
"longitude": -0.45,
|
||||
},
|
||||
"CDG": {
|
||||
"name": "Paris Charles de Gaulle Airport",
|
||||
"latitude": 49.01,
|
||||
"longitude": 2.55,
|
||||
},
|
||||
}
|
||||
|
||||
with app.app_context():
|
||||
original_collect_trip_coordinates = agenda.trip.collect_trip_coordinates
|
||||
original_get_trip_routes = agenda.trip.get_trip_routes
|
||||
original_parse_yaml = agenda.trip.travel.parse_yaml
|
||||
try:
|
||||
agenda.trip.collect_trip_coordinates = lambda _trip: []
|
||||
agenda.trip.get_trip_routes = lambda _trip, _data_dir: unbooked_routes
|
||||
agenda.trip.travel.parse_yaml = lambda _name, _data_dir: airports
|
||||
|
||||
coordinates, _routes = agenda.trip.get_coordinates_and_routes(trips)
|
||||
finally:
|
||||
agenda.trip.collect_trip_coordinates = original_collect_trip_coordinates
|
||||
agenda.trip.get_trip_routes = original_get_trip_routes
|
||||
agenda.trip.travel.parse_yaml = original_parse_yaml
|
||||
|
||||
airport_names = {
|
||||
coord["name"] for coord in coordinates if coord["type"] == "airport"
|
||||
}
|
||||
assert airport_names == {"Heathrow Airport", "Paris Charles de Gaulle Airport"}
|
||||
Loading…
Add table
Add a link
Reference in a new issue