From 2dedaf31271ae92c170aa3e46358d90439a2da30 Mon Sep 17 00:00:00 2001 From: eezd Date: Mon, 26 Oct 2026 22:07:42 +0800 Subject: [PATCH] Limit German archive pagination to filtered results Exclude the independent latest-release list from archived links and date boundaries. Cover stopping before the requested year, continuing within range, and rejecting pages without a filtered result block. --- .../alphapulse/calendar/europe_archives.py | 6 +++- .../europe/de_archive_before_start.html | 28 +++++++++++++++++++ backend/tests/test_europe_archives.py | 22 +++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 backend/tests/fixtures/europe/de_archive_before_start.html create mode 100644 backend/tests/test_europe_archives.py diff --git a/backend/src/alphapulse/calendar/europe_archives.py b/backend/src/alphapulse/calendar/europe_archives.py index 84c371f..dff4564 100644 --- a/backend/src/alphapulse/calendar/europe_archives.py +++ b/backend/src/alphapulse/calendar/europe_archives.py @@ -29,7 +29,11 @@ def ons_links(body: str) -> tuple[list[str], str | None]: def destatis_links(body: str, start: date, end: date) -> tuple[list[str], str | None]: - s = Selector(text=body) + sections = Selector(text=body).css(".s-press-search-results") + if not sections: + raise ValueError("Destatis 历史索引缺少筛选结果列表") + # 第二块是独立的最新新闻,日期不能参与筛选列表的翻页边界。 + s = sections[0] links, days = [], [] for node in s.css(".c-result"): date_text = compact(node.css(".c-result__date").xpath("string(.)").get() or "") diff --git a/backend/tests/fixtures/europe/de_archive_before_start.html b/backend/tests/fixtures/europe/de_archive_before_start.html new file mode 100644 index 0000000..ae34121 --- /dev/null +++ b/backend/tests/fixtures/europe/de_archive_before_start.html @@ -0,0 +1,28 @@ + + +
+ + + + next page + +
+
+ +
+ diff --git a/backend/tests/test_europe_archives.py b/backend/tests/test_europe_archives.py new file mode 100644 index 0000000..6528fa1 --- /dev/null +++ b/backend/tests/test_europe_archives.py @@ -0,0 +1,22 @@ +from datetime import date +from pathlib import Path + +import pytest + +from alphapulse.calendar.europe_archives import destatis_links + + +@pytest.mark.parametrize("start,expected,has_next", [ + (date(2025, 1, 1), [], False), + (date(2024, 1, 1), ["EN/Press/2024/09/PE24_340_611.html", "EN/Press/2024/08/PE24_329_611.html"], True), +]) +def test_destatis_archive_only_uses_filtered_results_for_links_and_date_boundary(start, expected, has_next): + body = (Path(__file__).parent / "fixtures/europe/de_archive_before_start.html").read_text() + links, following = destatis_links(body, start, date(2026, 10, 26)) + assert links == ["https://www.destatis.de/" + path for path in expected] + assert (following is not None) is has_next + + +def test_destatis_archive_rejects_a_page_without_the_filtered_result_block(): + with pytest.raises(ValueError, match="筛选结果"): + destatis_links("Access denied", date(2025, 1, 1), date(2026, 10, 26))