parent
14f5baf77c
commit
098c7e4447
9 changed files with 464 additions and 66 deletions
|
|
@ -47,6 +47,33 @@ def test_insert_sorted_allows_same_url_different_year_without_year_component() -
|
|||
assert updated[1]["name"] == "NewConf"
|
||||
|
||||
|
||||
def test_insert_sorted_supports_nested_dates() -> None:
|
||||
"""Nested dates should be used for sorting."""
|
||||
conferences: list[dict[str, typing.Any]] = [
|
||||
{
|
||||
"name": "PyCascades",
|
||||
"dates": {
|
||||
"status": "approximate",
|
||||
"label": "March 2027",
|
||||
"earliest": date(2027, 3, 1),
|
||||
"latest": date(2027, 3, 31),
|
||||
},
|
||||
}
|
||||
]
|
||||
new_conf: dict[str, typing.Any] = {
|
||||
"name": "FOSDEM",
|
||||
"dates": {
|
||||
"status": "tentative",
|
||||
"start": date(2027, 1, 30),
|
||||
"end": date(2027, 1, 31),
|
||||
},
|
||||
}
|
||||
|
||||
updated = add_new_conference.insert_sorted(conferences, new_conf)
|
||||
|
||||
assert [conf["name"] for conf in updated] == ["FOSDEM", "PyCascades"]
|
||||
|
||||
|
||||
def test_validate_country_normalises_name() -> None:
|
||||
"""Country names should be normalised to alpha-2 codes."""
|
||||
conf: dict[str, typing.Any] = {"country": "United Kingdom"}
|
||||
|
|
@ -68,6 +95,21 @@ def test_normalise_end_field_defaults_single_day_date() -> None:
|
|||
assert conf["end"] == date(2026, 4, 10)
|
||||
|
||||
|
||||
def test_normalise_end_field_defaults_nested_exact_date() -> None:
|
||||
"""Nested exact dates should get a default end date."""
|
||||
conf: dict[str, typing.Any] = {
|
||||
"name": "PyCon",
|
||||
"dates": {
|
||||
"status": "exact",
|
||||
"start": date(2026, 4, 10),
|
||||
},
|
||||
}
|
||||
|
||||
add_new_conference.normalise_end_field(conf, "plain text")
|
||||
|
||||
assert conf["dates"]["end"] == date(2026, 4, 10)
|
||||
|
||||
|
||||
def test_normalise_end_field_sets_geomob_end_time() -> None:
|
||||
"""Geomob conferences should default to a 22:00 end time."""
|
||||
conf: dict[str, typing.Any] = {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ from typing import Any
|
|||
import pytest
|
||||
import yaml
|
||||
|
||||
from agenda.conference import Conference, get_list
|
||||
from agenda.conference import Conference, conference_date_fields, get_list
|
||||
from agenda.event import Event
|
||||
|
||||
|
||||
|
|
@ -298,6 +298,104 @@ class TestGetList:
|
|||
assert event.date == datetime(2024, 5, 15, 9, 0)
|
||||
assert event.end_date == datetime(2024, 5, 17, 17, 0)
|
||||
|
||||
def test_get_list_nested_exact_dates(self) -> None:
|
||||
"""Test reading conference with nested exact dates."""
|
||||
yaml_data = [
|
||||
{
|
||||
"name": "PyCon",
|
||||
"topic": "Python",
|
||||
"location": "Portland",
|
||||
"dates": {
|
||||
"status": "exact",
|
||||
"start": date(2024, 5, 15),
|
||||
"end": date(2024, 5, 17),
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
yaml.dump(yaml_data, f)
|
||||
f.flush()
|
||||
|
||||
events = get_list(f.name)
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].date == date(2024, 5, 15)
|
||||
assert events[0].end_date == date(2024, 5, 17)
|
||||
|
||||
def test_get_list_tentative_dates_do_not_create_conference_event(self) -> None:
|
||||
"""Test tentative conference dates are not emitted as calendar events."""
|
||||
yaml_data = [
|
||||
{
|
||||
"name": "FOSDEM",
|
||||
"topic": "FOSDEM",
|
||||
"location": "Brussels",
|
||||
"dates": {
|
||||
"status": "tentative",
|
||||
"start": date(2027, 1, 30),
|
||||
"end": date(2027, 1, 31),
|
||||
"label": "likely first weekend of February 2027",
|
||||
},
|
||||
}
|
||||
]
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
yaml.dump(yaml_data, f)
|
||||
f.flush()
|
||||
|
||||
events = get_list(f.name)
|
||||
|
||||
assert events == []
|
||||
|
||||
def test_get_list_approximate_dates_keep_cfp_event(self) -> None:
|
||||
"""Test approximate dates do not block CFP reminders."""
|
||||
yaml_data = [
|
||||
{
|
||||
"name": "PyCascades",
|
||||
"topic": "Python",
|
||||
"location": "TBC",
|
||||
"dates": {
|
||||
"status": "approximate",
|
||||
"label": "March 2027",
|
||||
"earliest": date(2027, 3, 1),
|
||||
"latest": date(2027, 3, 31),
|
||||
},
|
||||
"cfp_end": date(2026, 11, 1),
|
||||
}
|
||||
]
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) as f:
|
||||
yaml.dump(yaml_data, f)
|
||||
f.flush()
|
||||
|
||||
events = get_list(f.name)
|
||||
|
||||
assert len(events) == 1
|
||||
assert events[0].name == "cfp_end"
|
||||
assert events[0].date == date(2026, 11, 1)
|
||||
|
||||
def test_conference_date_fields_approximate(self) -> None:
|
||||
"""Test derived fields for approximate conference dates."""
|
||||
fields = conference_date_fields(
|
||||
{
|
||||
"name": "PyCascades",
|
||||
"topic": "Python",
|
||||
"location": "TBC",
|
||||
"dates": {
|
||||
"status": "approximate",
|
||||
"label": "March 2027",
|
||||
"earliest": date(2027, 3, 1),
|
||||
"latest": date(2027, 3, 31),
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
assert fields["date_status"] == "approximate"
|
||||
assert fields["sort_date"] == date(2027, 3, 1)
|
||||
assert fields["latest_date"] == date(2027, 3, 31)
|
||||
assert fields["display_date"] == "March 2027"
|
||||
assert fields["has_exact_dates"] is False
|
||||
|
||||
def test_get_list_invalid_date_order(self) -> None:
|
||||
"""Test that conferences with end before start raise assertion error."""
|
||||
yaml_data = [
|
||||
|
|
|
|||
55
tests/test_conference_list.py
Normal file
55
tests/test_conference_list.py
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
"""Tests for conference list date handling."""
|
||||
|
||||
from datetime import date
|
||||
import typing
|
||||
|
||||
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",
|
||||
"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"
|
||||
)
|
||||
|
||||
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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue