Various improvements

This commit is contained in:
Edward Betts 2026-07-09 10:12:57 +01:00
parent b7d95f26ec
commit 442ae98463
3 changed files with 100 additions and 3 deletions

View file

@ -40,10 +40,25 @@ def test_build_prompt_uses_spec_and_keeps_trip_exclusion() -> None:
assert "Use this YAML format specification" in prompt
assert "## `trains.yaml`" in prompt
assert 'Exclude the top-level "trip" key' in prompt
assert 'Exclude these top-level keys from the YAML: "trip"' in prompt
assert "Eurostar booking details" in prompt
def test_build_prompt_for_accommodation_excludes_coordinates() -> None:
"""Accommodation prompt should exclude trip and coordinate fields."""
prompt = generate_booking_yaml.build_prompt(
"Airbnb booking details",
generate_booking_yaml.BOOKING_CONFIGS["accommodation"],
current_bookings="- type: airbnb\n",
)
assert "## `accommodation.yaml`" in prompt
assert (
'Exclude these top-level keys from the YAML: "trip", "latitude", "longitude"'
in prompt
)
def test_booking_text_from_args_fetches_url(monkeypatch: pytest.MonkeyPatch) -> None:
"""URL arguments should be fetched instead of reading stdin."""
monkeypatch.setattr(
@ -185,3 +200,58 @@ flights:
assert [item["booking_reference"] for item in written] == ["OLD", "MID", "NEWER"]
assert written[1]["trip"] == date(2026, 2, 6)
assert list(written[1]).index("trip") == 1
def test_import_accommodation_booking_adds_trip_and_inserts_chronologically(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Generated accommodation should be written into accommodation.yaml in order."""
(tmp_path / "accommodation.yaml").write_text("""---
- type: hotel
name: Earlier Hotel
location: Brussels
country: be
trip: 2026-02-01
from: 2026-02-01 15:00:00+01:00
to: 2026-02-02 11:00:00+01:00
- type: hotel
name: Later Hotel
location: Paris
country: fr
trip: 2026-02-10
from: 2026-02-10 15:00:00+01:00
to: 2026-02-11 11:00:00+01:00
""")
monkeypatch.setattr(
generate_booking_yaml,
"matching_trip_date",
lambda depart, data_dir: date(2026, 2, 6),
)
count = generate_booking_yaml.import_booking_yaml(
"""type: airbnb
name: Paris Airbnb
location: Paris
country: fr
from: 2026-02-06 15:00:00+01:00
to: 2026-02-09 11:00:00+01:00
price: '300.00'
currency: EUR
""",
generate_booking_yaml.BOOKING_CONFIGS["accommodation"],
data_dir=tmp_path,
)
text = (tmp_path / "accommodation.yaml").read_text()
written = yaml.safe_load(text)
assert count == 1
assert [item["name"] for item in written] == [
"Earlier Hotel",
"Paris Airbnb",
"Later Hotel",
]
assert written[1]["trip"] == date(2026, 2, 6)
assert list(written[1]).index("trip") == 4
assert "\n\n- type: airbnb\n" in text