aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/forms/test_sent.py (renamed from tests/forms/test_sources.py)24
-rw-r--r--tests/views/test_sent.py (renamed from tests/views/test_sources.py)147
2 files changed, 89 insertions, 82 deletions
diff --git a/tests/forms/test_sources.py b/tests/forms/test_sent.py
index 082b0d3..1cdd463 100644
--- a/tests/forms/test_sources.py
+++ b/tests/forms/test_sent.py
@@ -2,18 +2,18 @@
#
# SPDX-License-Identifier: BSD-3-Clause
-"""Validation of source-list GET filters."""
+"""Validation of sent Webmentions GET filters."""
import pytest
from flask import Flask
from werkzeug.datastructures import MultiDict
-from webmentions_ssg.forms.sources import SourceFilterForm
+from webmentions_ssg.forms.sent import SentFilterForm
-def test_source_filter_form_accepts_get_params(app: Flask) -> None:
- with app.test_request_context("/sources"):
- form = SourceFilterForm(
+def test_sent_filter_form_accepts_get_params(app: Flask) -> None:
+ with app.test_request_context("/sent"):
+ form = SentFilterForm(
formdata=MultiDict(
{
"status": "retrying",
@@ -55,19 +55,19 @@ def test_source_filter_form_accepts_get_params(app: Flask) -> None:
{"date_from": "2026-11-15", "date_to": "2026-11-08"},
],
)
-def test_source_filter_form_rejects_bad_get_params(
+def test_sent_filter_form_rejects_bad_get_params(
app: Flask, data: dict[str, str]
) -> None:
- with app.test_request_context("/sources"):
- form = SourceFilterForm(formdata=MultiDict(data), meta={"csrf": False})
+ with app.test_request_context("/sent"):
+ form = SentFilterForm(formdata=MultiDict(data), meta={"csrf": False})
assert not form.validate()
assert form.errors
-def test_source_filter_form_defaults_and_configured_maximum(app: Flask) -> None:
+def test_sent_filter_form_defaults_and_configured_maximum(app: Flask) -> None:
app.config["SOURCES_MAX_PAGE_SIZE"] = 10
- with app.test_request_context("/sources"):
- form = SourceFilterForm(formdata=MultiDict(), meta={"csrf": False})
+ with app.test_request_context("/sent"):
+ form = SentFilterForm(formdata=MultiDict(), meta={"csrf": False})
assert form.validate()
assert (
form.status.data,
@@ -75,7 +75,7 @@ def test_source_filter_form_defaults_and_configured_maximum(app: Flask) -> None:
form.order.data,
form.per_page.data,
) == ("", "last_seen", "desc", 10)
- form = SourceFilterForm(
+ form = SentFilterForm(
formdata=MultiDict({"per_page": "11"}), meta={"csrf": False}
)
assert not form.validate()
diff --git a/tests/views/test_sources.py b/tests/views/test_sent.py
index 8f5672c..9f9e65f 100644
--- a/tests/views/test_sources.py
+++ b/tests/views/test_sent.py
@@ -41,14 +41,14 @@ def _href(tag: Tag) -> str:
@pytest.fixture
-def sources_module(app: Flask) -> ModuleType:
+def sent_module(app: Flask) -> ModuleType:
_ = app
- from webmentions_ssg.views import sources as module
+ from webmentions_ssg.views import sent as module
return module
-@pytest.mark.parametrize("path", ["/sources", f"/sources/{uuid.uuid7()}"])
+@pytest.mark.parametrize("path", ["/sent", f"/sent/{uuid.uuid7()}"])
def test_sent_views_require_login(client: FlaskClient, path: str) -> None:
response = client.get(path)
@@ -56,28 +56,33 @@ def test_sent_views_require_login(client: FlaskClient, path: str) -> None:
assert "/login" in response.headers["Location"]
-def test_sent_lists_sources(app: Flask, client: FlaskClient) -> None:
+def test_sent_lists_source_documents(app: Flask, client: FlaskClient) -> None:
log_in(app, client)
identifier = create_sent_source(app)
- response = client.get("/sources")
+ response = client.get("/sent")
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
+ soup = BeautifulSoup(html, "html.parser")
+ assert soup.h1 is not None
+ assert soup.h1.get_text(strip=True) == "Sent Webmentions"
+ assert "1 source document" in html
+ assert soup.select_one('form[action="/sent"]') is not None
assert "blog/example/index.html" in html
assert "https://dennisfink.me/blog/example/" in html
- assert f"/sources/{identifier}" in html
+ assert f"/sent/{identifier}" in html
-def test_sent_sources_table_hides_secondary_columns_on_mobile(
+def test_sent_source_documents_table_hides_secondary_columns_on_mobile(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
create_sent_source(app)
- response = client.get("/sources")
+ response = client.get("/sent")
assert response.status_code == HTTPStatus.OK
html = BeautifulSoup(response.get_data(as_text=True), "html.parser")
@@ -100,7 +105,7 @@ def test_sent_source_lists_webmentions(app: Flask, client: FlaskClient) -> None:
log_in(app, client)
identifier = create_sent_source(app)
- response = client.get(f"/sources/{identifier}")
+ response = client.get(f"/sent/{identifier}")
assert response.status_code == HTTPStatus.OK
@@ -108,6 +113,8 @@ def test_sent_source_lists_webmentions(app: Flask, client: FlaskClient) -> None:
assert "blog/example/index.html" in html
assert "https://dennisfink.me/blog/example/" in html
+ assert "Sent Webmention Source" in html
+ assert "Back to Sent Webmentions" in html
first_target = "https://example.com/a"
second_target = "https://example.com/b"
@@ -126,7 +133,7 @@ def test_sent_webmentions_table_keeps_status_and_actions_on_mobile(
log_in(app, client)
identifier = create_sent_source(app)
- response = client.get(f"/sources/{identifier}")
+ response = client.get(f"/sent/{identifier}")
assert response.status_code == HTTPStatus.OK
html = BeautifulSoup(response.get_data(as_text=True), "html.parser")
@@ -149,12 +156,12 @@ def test_sent_source_returns_404_for_unknown_source(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
- response = client.get(f"/sources/{uuid.uuid7()}")
+ response = client.get(f"/sent/{uuid.uuid7()}")
assert response.status_code == HTTPStatus.NOT_FOUND
def test_rescan_sent_sources_requires_login(client: FlaskClient) -> None:
- response = client.post("/sources/rescan")
+ response = client.post("/sent/rescan")
assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -164,16 +171,16 @@ def test_rescan_sent_sources_requires_login(client: FlaskClient) -> None:
def test_rescan_sent_sources(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
valid: bool,
) -> None:
log_in(app, client)
- form = mock_admin_action_form(sources_module, monkeypatch, valid=valid)
+ form = mock_admin_action_form(sent_module, monkeypatch, valid=valid)
manual_scan_sources = Mock()
- monkeypatch.setattr(sources_module, "manual_scan_sources", manual_scan_sources)
+ monkeypatch.setattr(sent_module, "manual_scan_sources", manual_scan_sources)
- response = client.post("/sources/rescan")
+ response = client.post("/sent/rescan")
assert response.status_code == (
HTTPStatus.FOUND if valid else HTTPStatus.BAD_REQUEST
@@ -181,14 +188,14 @@ def test_rescan_sent_sources(
form.validate_on_submit.assert_called_once_with()
if valid:
- assert response.headers["Location"].endswith("/sources")
+ assert response.headers["Location"].endswith("/sent")
manual_scan_sources.assert_called_once_with()
else:
manual_scan_sources.assert_not_called()
def test_resend_sent_webmention_requires_login(client: FlaskClient) -> None:
- response = client.post(f"/sources/{uuid.uuid7()}/{uuid.uuid7()}/resend")
+ response = client.post(f"/sent/{uuid.uuid7()}/{uuid.uuid7()}/resend")
assert response.status_code == HTTPStatus.FOUND
assert "/login" in response.headers["Location"]
@@ -197,15 +204,15 @@ def test_resend_sent_webmention_requires_login(client: FlaskClient) -> None:
def test_resend_sent_webmention_rejects_invalid_form(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
source_identifier, webmention_identifier = create_resendable_sent_webmention(app)
- mock_admin_action_form(sources_module, monkeypatch, valid=False)
+ mock_admin_action_form(sent_module, monkeypatch, valid=False)
response = client.post(
- f"/sources/{source_identifier}/{webmention_identifier}/resend"
+ f"/sent/{source_identifier}/{webmention_identifier}/resend"
)
assert response.status_code == HTTPStatus.BAD_REQUEST
@@ -214,14 +221,14 @@ def test_resend_sent_webmention_rejects_invalid_form(
def test_resend_sent_webmention_returns_404_for_unknown_webmention(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
source_identifier = create_sent_source(app)
- mock_admin_action_form(sources_module, monkeypatch, valid=True)
+ mock_admin_action_form(sent_module, monkeypatch, valid=True)
- response = client.post(f"/sources/{source_identifier}/{uuid.uuid7()}/resend")
+ response = client.post(f"/sent/{source_identifier}/{uuid.uuid7()}/resend")
assert response.status_code == HTTPStatus.NOT_FOUND
@@ -229,16 +236,16 @@ def test_resend_sent_webmention_returns_404_for_unknown_webmention(
def test_resend_sent_webmention_rejects_wrong_source(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
_, webmention_identifier = create_resendable_sent_webmention(app)
wrong_source_identifier = create_sent_source(app)
- mock_admin_action_form(sources_module, monkeypatch, valid=True)
+ mock_admin_action_form(sent_module, monkeypatch, valid=True)
response = client.post(
- f"/sources/{wrong_source_identifier}/{webmention_identifier}/resend"
+ f"/sent/{wrong_source_identifier}/{webmention_identifier}/resend"
)
assert response.status_code == HTTPStatus.NOT_FOUND
@@ -247,14 +254,14 @@ def test_resend_sent_webmention_rejects_wrong_source(
def test_resend_sent_webmention_reopens_current_revision(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
source_identifier, webmention_identifier = create_resendable_sent_webmention(app)
- mock_admin_action_form(sources_module, monkeypatch, valid=True)
+ mock_admin_action_form(sent_module, monkeypatch, valid=True)
send_webmention = Mock()
- monkeypatch.setattr(sources_module, "send_webmention", send_webmention)
+ monkeypatch.setattr(sent_module, "send_webmention", send_webmention)
with app.app_context():
webmention = db.session.get(SentWebmention, webmention_identifier)
@@ -264,11 +271,11 @@ def test_resend_sent_webmention_reopens_current_revision(
db.session.commit()
response = client.post(
- f"/sources/{source_identifier}/{webmention_identifier}/resend"
+ f"/sent/{source_identifier}/{webmention_identifier}/resend"
)
assert response.status_code == HTTPStatus.FOUND
- assert response.headers["Location"].endswith(f"/sources/{source_identifier}")
+ assert response.headers["Location"].endswith(f"/sent/{source_identifier}")
with app.app_context():
webmention = db.session.get(SentWebmention, webmention_identifier)
@@ -311,7 +318,7 @@ def test_admin_only_links_safe_existing_status_urls(
session["_user_id"] = str(user_id)
session["_fresh"] = True
- response = client.get(f"/sources/{source_identifier}")
+ response = client.get(f"/sent/{source_identifier}")
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
assert (f'href="{status_url}"' in html) is safe
@@ -366,7 +373,7 @@ def make_source(
("deleted", {"deleted"}),
],
)
-def test_sources_filter_by_delivery_state_without_duplicate_rows(
+def test_sent_filter_by_delivery_state_without_duplicate_rows(
app: Flask, client: FlaskClient, status: str, expected: set[str]
) -> None:
log_in(app, client)
@@ -388,7 +395,7 @@ def test_sources_filter_by_delivery_state_without_duplicate_rows(
make_source(app, "sent")
make_source(app, "pending", statuses=(None,), processed=False)
- response = client.get("/sources", query_string={"status": status})
+ response = client.get("/sent", query_string={"status": status})
assert response.status_code == HTTPStatus.OK
soup = BeautifulSoup(response.get_data(as_text=True), "html.parser")
paths = []
@@ -414,23 +421,23 @@ def test_sources_filter_by_delivery_state_without_duplicate_rows(
("alpha%", None),
],
)
-def test_sources_search_matches_path_source_url_and_sent_target(
+def test_sent_search_matches_path_source_url_and_sent_target(
app: Flask, client: FlaskClient, q: str, expected: str | None
) -> None:
log_in(app, client)
make_source(app, "alpha")
make_source(app, "beta")
- response = client.get("/sources", query_string={"q": f" {q} "})
+ response = client.get("/sent", query_string={"q": f" {q} "})
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
assert ("blog/alpha/index.html" in html) == (expected == "alpha")
assert "blog/beta/index.html" not in html
if expected is None:
- assert "No sources match these filters." in html
+ assert "No source documents match these filters." in html
-def test_sources_filter_by_inclusive_last_seen_dates(
+def test_sent_filter_by_inclusive_last_seen_dates(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
@@ -438,7 +445,7 @@ def test_sources_filter_by_inclusive_last_seen_dates(
make_source(app, "included", last_seen_at=datetime(2026, 11, 10, 22, tzinfo=UTC))
make_source(app, "new", last_seen_at=datetime(2026, 11, 15, tzinfo=UTC))
response = client.get(
- "/sources", query_string={"date_from": "2026-11-08", "date_to": "2026-11-10"}
+ "/sent", query_string={"date_from": "2026-11-08", "date_to": "2026-11-10"}
)
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
@@ -450,13 +457,13 @@ def test_sources_filter_by_inclusive_last_seen_dates(
@pytest.mark.parametrize(
"sort", ["path", "url", "webmentions", "revision", "created", "last_seen", "status"]
)
-def test_sources_sort_links_preserve_filters(
+def test_sent_sort_links_preserve_filters(
app: Flask, client: FlaskClient, sort: str
) -> None:
log_in(app, client)
make_source(app, "alpha", statuses=(SentWebmentionStatus.FAILED,))
response = client.get(
- "/sources",
+ "/sent",
query_string={
"status": "failing",
"q": "alpha",
@@ -473,7 +480,7 @@ def test_sources_sort_links_preserve_filters(
links = [
parse_qs(urlsplit(_href(a)).query)
for a in soup.select("th a[href]")
- if urlsplit(_href(a)).path == "/sources"
+ if urlsplit(_href(a)).path == "/sent"
]
assert len(links) == 7
for link in links:
@@ -493,7 +500,7 @@ def test_sources_sort_links_preserve_filters(
assert any(link["sort"] == [sort] and link["order"] == ["desc"] for link in links)
-def test_sources_sort_orders_by_count_and_path(app: Flask, client: FlaskClient) -> None:
+def test_sent_sort_orders_by_count_and_path(app: Flask, client: FlaskClient) -> None:
log_in(app, client)
make_source(app, "z", statuses=(SentWebmentionStatus.SENT,))
make_source(
@@ -505,7 +512,7 @@ def test_sources_sort_orders_by_count_and_path(app: Flask, client: FlaskClient)
("path", "asc", "a"),
("path", "desc", "z"),
):
- response = client.get("/sources", query_string={"sort": sort, "order": order})
+ response = client.get("/sent", query_string={"sort": sort, "order": order})
assert response.status_code == HTTPStatus.OK
soup = BeautifulSoup(response.get_data(as_text=True), "html.parser")
link = soup.select_one("tbody tr td a")
@@ -513,7 +520,7 @@ def test_sources_sort_orders_by_count_and_path(app: Flask, client: FlaskClient)
assert link.get_text(strip=True) == f"blog/{expected_first}/index.html"
-def test_sources_filter_pagination_and_navigation_preserve_parameters(
+def test_sent_filter_pagination_and_navigation_preserve_parameters(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
@@ -526,21 +533,21 @@ def test_sources_filter_pagination_and_navigation_preserve_parameters(
"order": "asc",
"per_page": "10",
}
- response = client.get("/sources", query_string={**filters, "page": "2"})
+ response = client.get("/sent", query_string={**filters, "page": "2"})
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
- assert "28 sources" in html
+ assert "28 source documents" in html
soup = BeautifulSoup(html, "html.parser")
assert len(soup.select("tbody tr")) == 10
urls = [_href(a) for a in soup.select("a[href]")]
assert any(
- urlsplit(url).path == "/sources"
+ urlsplit(url).path == "/sent"
and parse_qs(urlsplit(url).query)
== {**{k: [v] for k, v in filters.items()}, "page": ["3"]}
for url in urls
)
detail_urls = [
- url for url in urls if re.search(r"/sources/[0-9a-f-]{36}", urlsplit(url).path)
+ url for url in urls if re.search(r"/sent/[0-9a-f-]{36}", urlsplit(url).path)
]
assert detail_urls
assert parse_qs(urlsplit(detail_urls[0]).query) == {
@@ -550,7 +557,7 @@ def test_sources_filter_pagination_and_navigation_preserve_parameters(
detail = client.get(detail_urls[0])
assert detail.status_code == HTTPStatus.OK
back = BeautifulSoup(detail.get_data(as_text=True), "html.parser").select_one(
- 'a[href*="/sources?"]'
+ 'a[href*="/sent?"]'
)
assert back is not None
assert parse_qs(urlsplit(_href(back)).query) == {
@@ -573,25 +580,25 @@ def test_sources_filter_pagination_and_navigation_preserve_parameters(
"date_from=2026-11-10&date_to=2026-11-01",
],
)
-def test_sources_bad_filters_return_400(
+def test_sent_bad_filters_return_400(
app: Flask, client: FlaskClient, invalid: str
) -> None:
log_in(app, client)
- assert client.get(f"/sources?{invalid}").status_code == HTTPStatus.BAD_REQUEST
+ assert client.get(f"/sent?{invalid}").status_code == HTTPStatus.BAD_REQUEST
def test_rescan_sources_preserves_filter_query(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
- mock_admin_action_form(sources_module, monkeypatch, valid=True)
+ mock_admin_action_form(sent_module, monkeypatch, valid=True)
scan = Mock()
- monkeypatch.setattr(sources_module, "manual_scan_sources", scan)
+ monkeypatch.setattr(sent_module, "manual_scan_sources", scan)
response = client.post(
- "/sources/rescan",
+ "/sent/rescan",
query_string={"status": "retrying", "per_page": 37, "page": 2},
)
assert response.status_code == HTTPStatus.FOUND
@@ -603,7 +610,7 @@ def test_rescan_sources_preserves_filter_query(
scan.assert_called_once_with()
-def test_sources_show_failed_and_retrying_counts_and_retry_deadline(
+def test_sent_show_failed_and_retrying_counts_and_retry_deadline(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
@@ -614,13 +621,13 @@ def test_sources_show_failed_and_retrying_counts_and_retry_deadline(
retrying=True,
processed=False,
)
- response = client.get("/sources", query_string={"status": "retrying"})
+ response = client.get("/sent", query_string={"status": "retrying"})
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
assert "1 failed" in html
assert "1 awaiting retry" in html
- response = client.get(f"/sources/{identifier}")
+ response = client.get(f"/sent/{identifier}")
assert response.status_code == HTTPStatus.OK
assert "Retry scheduled after attempt 2:" in response.get_data(as_text=True)
@@ -628,17 +635,17 @@ def test_sources_show_failed_and_retrying_counts_and_retry_deadline(
def test_resend_preserves_source_filter_context(
app: Flask,
client: FlaskClient,
- sources_module: ModuleType,
+ sent_module: ModuleType,
monkeypatch: pytest.MonkeyPatch,
) -> None:
log_in(app, client)
source_id, mention_id = create_resendable_sent_webmention(app)
- mock_admin_action_form(sources_module, monkeypatch, valid=True)
+ mock_admin_action_form(sent_module, monkeypatch, valid=True)
send = Mock()
- monkeypatch.setattr(sources_module, "send_webmention", send)
+ monkeypatch.setattr(sent_module, "send_webmention", send)
response = client.post(
- f"/sources/{source_id}/{mention_id}/resend",
+ f"/sent/{source_id}/{mention_id}/resend",
query_string={
"status": "failing",
"q": "resend",
@@ -648,7 +655,7 @@ def test_resend_preserves_source_filter_context(
},
)
assert response.status_code == HTTPStatus.FOUND
- assert urlsplit(response.headers["Location"]).path == f"/sources/{source_id}"
+ assert urlsplit(response.headers["Location"]).path == f"/sent/{source_id}"
assert parse_qs(urlsplit(response.headers["Location"]).query) == {
"status": ["failing"],
"q": ["resend"],
@@ -659,7 +666,7 @@ def test_resend_preserves_source_filter_context(
send.assert_called_once_with(mention_id)
-def test_sources_show_sql_statistics_with_zero_webmentions(
+def test_sent_show_sql_statistics_with_zero_webmentions(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
@@ -675,7 +682,7 @@ def test_sources_show_sql_statistics_with_zero_webmentions(
)
make_source(app, "empty-stats", statuses=())
- response = client.get("/sources", query_string={"sort": "path", "order": "asc"})
+ response = client.get("/sent", query_string={"sort": "path", "order": "asc"})
assert response.status_code == HTTPStatus.OK
rows = BeautifulSoup(response.get_data(as_text=True), "html.parser").select(
"tbody tr"
@@ -690,12 +697,12 @@ def test_sources_show_sql_statistics_with_zero_webmentions(
assert "awaiting retry" not in mixed
-def test_sources_empty_filter_result_keeps_rescan_modal(
+def test_sent_empty_filter_result_keeps_rescan_modal(
app: Flask, client: FlaskClient
) -> None:
log_in(app, client)
- response = client.get("/sources", query_string={"status": "failing"})
+ response = client.get("/sent", query_string={"status": "failing"})
assert response.status_code == HTTPStatus.OK
html = response.get_data(as_text=True)
- assert "No sources match these filters." in html
+ assert "No source documents match these filters." in html
assert 'id="confirmation-modal"' in html