"""Regression tests for trip page route wiring.""" from datetime import date import typing import web_view from agenda.types import Trip def test_trip_page_passes_data_dir_to_unbooked_flight_helper() -> None: """Trip page should call helper with routes, coordinates and data_dir.""" trip = Trip(start=date(2025, 1, 28)) captured: dict[str, str] = {} with web_view.app.app_context(): original_get_trip_list = web_view.get_trip_list original_add_schengen = ( web_view.agenda.trip_schengen.add_schengen_compliance_to_trip ) original_collect_trip_coordinates = ( web_view.agenda.trip.collect_trip_coordinates ) original_get_trip_routes = web_view.agenda.trip.get_trip_routes original_add_coordinates = ( web_view.agenda.trip.add_coordinates_for_unbooked_flights ) original_get_trip_weather = web_view.agenda.weather.get_trip_weather original_render_template = web_view.flask.render_template try: web_view.get_trip_list = lambda: [trip] web_view.agenda.trip_schengen.add_schengen_compliance_to_trip = lambda t: t web_view.agenda.trip.collect_trip_coordinates = lambda _trip: [] web_view.agenda.trip.get_trip_routes = lambda _trip, _data_dir: [] def fake_add_coordinates( _routes: list[typing.Any], _coordinates: list[typing.Any], data_dir: str, ) -> None: captured["data_dir"] = data_dir web_view.agenda.trip.add_coordinates_for_unbooked_flights = ( fake_add_coordinates ) web_view.agenda.weather.get_trip_weather = lambda *_args, **_kwargs: [] web_view.flask.render_template = lambda *_args, **_kwargs: "ok" with web_view.app.test_request_context("/trip/2025-01-28"): result = web_view.trip_page("2025-01-28") assert result == "ok" assert captured["data_dir"] == web_view.app.config["PERSONAL_DATA"] finally: web_view.get_trip_list = original_get_trip_list web_view.agenda.trip_schengen.add_schengen_compliance_to_trip = ( original_add_schengen ) web_view.agenda.trip.collect_trip_coordinates = ( original_collect_trip_coordinates ) web_view.agenda.trip.get_trip_routes = original_get_trip_routes web_view.agenda.trip.add_coordinates_for_unbooked_flights = ( original_add_coordinates ) web_view.agenda.weather.get_trip_weather = original_get_trip_weather web_view.flask.render_template = original_render_template