When a trip ended in the UK but had foreign accommodations during the trip, location tracking would incorrectly show the foreign location even after returning home. Added logic to detect when the most recent travel occurred within a completed trip that ended in the UK, and override foreign accommodations to show "Bristol" (home) for dates after the trip. Example: Trip Sep 8-17 with accommodation in Kochi, India on Sep 10, but trip ended at Gatwick Airport, UK. Oct 7 now correctly shows "Bristol" instead of "Kochi". 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
from datetime import date, datetime
|
|
|
|
import agenda.travel as travel
|
|
import agenda.trip
|
|
from web_view import app
|
|
|
|
|
|
def test_get_location_for_date() -> None:
|
|
app.config["SERVER_NAME"] = "test"
|
|
with app.app_context():
|
|
today = datetime.now().date()
|
|
start = date(today.year, 1, 1)
|
|
trips = [
|
|
t
|
|
for t in agenda.trip.build_trip_list()
|
|
if t.start in [date(2023, 9, 8), date(2023, 11, 14), date(2025, 2, 9)]
|
|
]
|
|
assert len(trips) == 3
|
|
|
|
data_dir = app.config["PERSONAL_DATA"]
|
|
|
|
# Parse YAML files once for the test
|
|
bookings = travel.parse_yaml("flights", data_dir)
|
|
accommodations = travel.parse_yaml("accommodation", data_dir)
|
|
airports = travel.parse_yaml("airports", data_dir)
|
|
|
|
l1 = agenda.busy.get_location_for_date(
|
|
date(2025, 2, 15), trips, bookings, accommodations, airports
|
|
)
|
|
assert l1[0] == "Hackettstown"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2025, 7, 1), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2023, 12, 2), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|
|
|
|
l2 = agenda.busy.get_location_for_date(
|
|
date(2023, 10, 7), trips, bookings, accommodations, airports
|
|
)
|
|
assert l2[0] == "Bristol"
|