Refactor get_location_for_date to use trip data directly

Simplify the location tracking function by extracting travel data directly
from trip objects instead of requiring separate YAML file parameters.

Changes:
- Remove airport, train, and ferry location helper functions that required
  separate YAML data lookups
- Update get_location_for_date signature to only take target_date and trips
- Extract flight/train/ferry details directly from trip.travel items
- Use embedded airport/station/terminal objects from trip data
- Remove YAML file parsing from weekends function
- Update test calls to use new simplified signature

This eliminates duplicate data loading and simplifies the API while
maintaining all existing functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Edward Betts 2025-07-16 12:08:19 +02:00
parent 0e2c95117c
commit 29d5145b87
2 changed files with 260 additions and 367 deletions

View file

@ -73,9 +73,6 @@ def test_specific_home_dates(travel_data):
location = agenda.busy.get_location_for_date(
test_date,
trips,
travel_data["bookings"],
travel_data["accommodations"],
travel_data["airports"],
)
assert not location[
0
@ -94,9 +91,6 @@ def test_specific_away_dates(travel_data):
location = agenda.busy.get_location_for_date(
test_date,
trips,
travel_data["bookings"],
travel_data["accommodations"],
travel_data["airports"],
)
assert (
location[0] == expected_city
@ -111,9 +105,6 @@ def test_get_location_for_date_basic(travel_data):
location = agenda.busy.get_location_for_date(
test_date,
trips,
travel_data["bookings"],
travel_data["accommodations"],
travel_data["airports"],
)
# Should return a tuple with (city|None, country)
@ -178,68 +169,6 @@ def test_parse_datetime_field():
assert parsed_dt.day == 1
def test_train_location_helpers():
"""Test the train location helper functions."""
from agenda.busy import _get_train_location
# Mock station data
stations = [
{"name": "London St Pancras", "country": "gb"},
{"name": "Brussels Midi", "country": "be"},
{"name": "Edinburgh Waverley", "country": "gb"},
]
# Test UK station when not on trip (should return None for home)
train_leg = {"to": "London St Pancras"}
location = _get_train_location(train_leg, stations, on_trip=False)
assert location[0] is None # Should be home
assert location[1].alpha_2 == "GB"
# Test UK station when on trip (should return city name)
location = _get_train_location(train_leg, stations, on_trip=True)
assert location[0] == "London St Pancras"
assert location[1].alpha_2 == "GB"
# Test non-UK station
train_leg = {"to": "Brussels Midi"}
location = _get_train_location(train_leg, stations, on_trip=False)
assert location[0] == "Brussels Midi"
assert location[1].alpha_2 == "BE"
def test_ferry_location_helpers():
"""Test the ferry location helper functions."""
from agenda.busy import _get_ferry_location
# Mock terminal data
terminals = [
{"name": "Dover Eastern Docks", "country": "gb", "city": "Dover"},
{"name": "Calais Ferry Terminal", "country": "fr", "city": "Calais"},
{
"name": "Portsmouth Continental Terminal",
"country": "gb",
"city": "Portsmouth",
},
]
# Test UK terminal when not on trip (should return None for home)
ferry = {"to": "Dover Eastern Docks"}
location = _get_ferry_location(ferry, terminals, on_trip=False)
assert location[0] is None # Should be home
assert location[1].alpha_2 == "GB"
# Test UK terminal when on trip (should return city name)
location = _get_ferry_location(ferry, terminals, on_trip=True)
assert location[0] == "Dover"
assert location[1].alpha_2 == "GB"
# Test non-UK terminal
ferry = {"to": "Calais Ferry Terminal"}
location = _get_ferry_location(ferry, terminals, on_trip=False)
assert location[0] == "Calais"
assert location[1].alpha_2 == "FR"
def test_get_busy_events(app_context, trips):
"""Test get_busy_events function."""
start_date = date(2023, 1, 1)