57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
"""Regression tests for GWR update notifications."""
|
|
|
|
from pathlib import Path
|
|
from unittest.mock import Mock, patch
|
|
|
|
import flask
|
|
import pytest
|
|
|
|
from update import update_gwr_advance_ticket_date
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("response_html", "expect_email"),
|
|
[
|
|
(
|
|
"<p>We are sorry that we cannot show you the page you were looking for. "
|
|
"Our website is extremely busy at the moment.</p>",
|
|
False,
|
|
),
|
|
(
|
|
"<p>We are sorry that we cannot show you the page you were looking for.\n"
|
|
"Our website is extremely busy at the moment.</p>",
|
|
False,
|
|
),
|
|
("<p>Unexpected response without booking dates.</p>", True),
|
|
],
|
|
ids=["busy-page", "busy-page-whitespace", "unexpected-page"],
|
|
)
|
|
def test_gwr_missing_dates_notifications(
|
|
tmp_path: Path, response_html: str, expect_email: bool
|
|
) -> None:
|
|
"""Only known busy pages skip alerts; failed responses preserve the cache."""
|
|
cached_html = """
|
|
<table>
|
|
<tr><td>Weekdays</td><td>Friday 25 December 2026</td></tr>
|
|
<tr><td>Saturdays</td><td>Saturday 26 December 2026</td></tr>
|
|
<tr><td>Sundays</td><td>Sunday 27 December 2026</td></tr>
|
|
</table>
|
|
"""
|
|
cache = tmp_path / "advance-tickets.html"
|
|
cache.write_text(cached_html)
|
|
config = flask.config.Config(str(tmp_path))
|
|
config["DATA_DIR"] = str(tmp_path)
|
|
|
|
with (
|
|
patch("update.requests.get", return_value=Mock(text=response_html)),
|
|
patch("update.agenda.mail.send_mail") as send_mail,
|
|
):
|
|
update_gwr_advance_ticket_date(config)
|
|
|
|
if expect_email:
|
|
send_mail.assert_called_once_with(
|
|
config, "Error parsing GWR advance ticket booking dates", response_html
|
|
)
|
|
else:
|
|
send_mail.assert_not_called()
|
|
assert cache.read_text() == cached_html
|