"""Tests for conference list date handling.""" from datetime import date import typing from types import SimpleNamespace import yaml import agenda.trip import web_view def test_build_conference_list_supports_inexact_dates( tmp_path: typing.Any, monkeypatch: typing.Any ) -> None: """Conference list should include tentative and approximate dates.""" conferences = [ { "name": "PyCascades 2027", "series": "pycascades", "topic": "Python", "location": "TBC", "dates": { "status": "approximate", "label": "March 2027", "earliest": date(2027, 3, 1), "latest": date(2027, 3, 31), }, }, { "name": "FOSDEM 2027", "topic": "FOSDEM", "location": "Brussels", "dates": { "status": "tentative", "start": date(2027, 1, 30), "end": date(2027, 1, 31), "label": "likely first weekend of February 2027", }, }, ] (tmp_path / "conferences.yaml").write_text( yaml.safe_dump(conferences), encoding="utf-8" ) (tmp_path / "conference_series.yaml").write_text( yaml.safe_dump( { "pycascades": { "name": "PyCascades", "topic": "Python", "cadence": "annual", "url": "https://pycascades.com/", } } ), encoding="utf-8", ) monkeypatch.setitem(web_view.app.config, "PERSONAL_DATA", str(tmp_path)) monkeypatch.setattr(agenda.trip, "build_trip_list", lambda: []) items = web_view.build_conference_list() assert [item["name"] for item in items] == ["FOSDEM 2027", "PyCascades 2027"] assert items[0]["date_status"] == "tentative" assert items[0]["display_date"] == "likely first weekend of February 2027" assert items[0]["sort_date"] == date(2027, 1, 30) assert items[1]["date_status"] == "approximate" assert items[1]["display_date"] == "March 2027" assert items[1]["latest_date"] == date(2027, 3, 31) assert items[1]["series_detail"]["name"] == "PyCascades" def test_conference_series_pages(tmp_path: typing.Any, monkeypatch: typing.Any) -> None: """Series index and detail pages should render linked conferences.""" conferences = [ { "name": "PyCascades 2027", "series": "pycascades", "topic": "Python", "location": "TBC", "trip": date(2027, 3, 1), "dates": { "status": "exact", "start": date(2027, 3, 5), "end": date(2027, 3, 6), }, "going": True, } ] series = { "pycascades": { "name": "PyCascades", "topic": "Python", "cadence": "annual", "url": "https://pycascades.com/", } } (tmp_path / "conferences.yaml").write_text( yaml.safe_dump(conferences), encoding="utf-8" ) (tmp_path / "conference_series.yaml").write_text( yaml.safe_dump(series), encoding="utf-8" ) monkeypatch.setitem(web_view.app.config, "PERSONAL_DATA", str(tmp_path)) fake_trip = SimpleNamespace( start=date(2027, 3, 1), title="Seattle Python trip", conferences=[{"start": date(2027, 3, 5), "name": "PyCascades 2027"}], ) monkeypatch.setattr(agenda.trip, "build_trip_list", lambda: [fake_trip]) web_view.app.config["TESTING"] = True with web_view.app.test_client() as client: index_response = client.get("/conference/series") detail_response = client.get("/conference/series/pycascades") assert index_response.status_code == 200 assert b"PyCascades" in index_response.data assert b"attended" in index_response.data assert detail_response.status_code == 200 assert b"trip: Seattle Python trip" in detail_response.data