agenda/tests/test_conference_list.py

205 lines
6.7 KiB
Python

"""Tests for conference list date handling."""
from datetime import date
import typing
from types import SimpleNamespace
import yaml
import agenda.fx
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
def test_conference_page_filters_by_country(
tmp_path: typing.Any, monkeypatch: typing.Any
) -> None:
"""Conference page should filter upcoming conferences by country code."""
conferences = [
{
"name": "UK Mapping Conf 2099",
"topic": "Maps",
"location": "London",
"country": "GB",
"start": date(2099, 5, 1),
"end": date(2099, 5, 2),
},
{
"name": "US Python Conf 2099",
"topic": "Python",
"location": "Pittsburgh",
"country": "US",
"start": date(2099, 6, 1),
"end": date(2099, 6, 2),
},
]
(tmp_path / "conferences.yaml").write_text(
yaml.safe_dump(conferences), encoding="utf-8"
)
monkeypatch.setitem(web_view.app.config, "PERSONAL_DATA", str(tmp_path))
monkeypatch.setattr(agenda.trip, "build_trip_list", lambda: [])
monkeypatch.setattr(agenda.fx, "get_rates", lambda config: {})
web_view.app.config["TESTING"] = True
with web_view.app.test_client() as client:
response = client.get("/conference?country=gb")
assert response.status_code == 200
assert b"UK Mapping Conf 2099" in response.data
assert b"US Python Conf 2099" not in response.data
assert b'<option value="gb" selected>' in response.data
assert b'href="/conference"' in response.data
def test_past_conference_page_filters_by_country(
tmp_path: typing.Any, monkeypatch: typing.Any
) -> None:
"""Past conference page should filter conferences by country code."""
conferences = [
{
"name": "Past UK Conf",
"topic": "Maps",
"location": "London",
"country": "GB",
"start": date(2001, 5, 1),
"end": date(2001, 5, 2),
},
{
"name": "Past US Conf",
"topic": "Python",
"location": "Pittsburgh",
"country": "US",
"start": date(2001, 6, 1),
"end": date(2001, 6, 2),
},
]
(tmp_path / "conferences.yaml").write_text(
yaml.safe_dump(conferences), encoding="utf-8"
)
monkeypatch.setitem(web_view.app.config, "PERSONAL_DATA", str(tmp_path))
monkeypatch.setattr(agenda.trip, "build_trip_list", lambda: [])
monkeypatch.setattr(agenda.fx, "get_rates", lambda config: {})
web_view.app.config["TESTING"] = True
with web_view.app.test_client() as client:
response = client.get("/conference/past?country=us")
assert response.status_code == 200
assert b"Past US Conf" in response.data
assert b"Past UK Conf" not in response.data
assert b'href="/conference/past"' in response.data