69 lines
2.3 KiB
Python
69 lines
2.3 KiB
Python
from datetime import date, datetime, timedelta
|
|
|
|
import agenda.busy
|
|
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()
|
|
trips = agenda.trip.build_trip_list()
|
|
|
|
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)
|
|
|
|
for year in range(2023, 2025):
|
|
start = date(2023, 1, 1)
|
|
busy_events = agenda.busy.get_busy_events(start, app.config, trips)
|
|
weekends = agenda.busy.weekends(start, busy_events, trips, data_dir)
|
|
|
|
for weekend in weekends:
|
|
for day in "saturday", "sunday":
|
|
# When free (no events), should be home (None)
|
|
# When traveling (events), should be away (City name)
|
|
assert bool(weekend[day + "_location"][0]) == bool(weekend[day])
|
|
|
|
# Test some specific cases
|
|
april_29_location = agenda.busy.get_location_for_date(
|
|
date(2023, 4, 29), trips, bookings, accommodations, airports
|
|
)
|
|
assert not april_29_location[0] # Should be home (None)
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2025, 2, 15), trips, bookings, accommodations, airports
|
|
)
|
|
assert l[0] == "Hackettstown"
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2025, 7, 1), trips, bookings, accommodations, airports
|
|
)
|
|
assert not l[0]
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2023, 12, 2), trips, bookings, accommodations, airports
|
|
)
|
|
assert not l[0]
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2023, 10, 7), trips, bookings, accommodations, airports
|
|
)
|
|
assert not l[0]
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2023, 2, 18), trips, bookings, accommodations, airports
|
|
)
|
|
assert not l[0]
|
|
|
|
l = agenda.busy.get_location_for_date(
|
|
date(2025, 8, 2), trips, bookings, accommodations, airports
|
|
)
|
|
assert not l[0]
|
|
|