aboutsummaryrefslogtreecommitdiff
path: root/tests/views/test_endpoint.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-17 19:43:04 +0100
committerDennis Fink2026-11-17 19:43:04 +0100
commit5e24e8307f650e72881f747661a2b6e52db15f2d (patch)
tree585b456b9439a17957e8633f566c0725bb9d8595 /tests/views/test_endpoint.py
parent6d6d079a3a99d3d3a922a640b6925eb2adf044de (diff)
downloadwebmentions-ssg-5e24e8307f650e72881f747661a2b6e52db15f2d.tar.gz
webmentions-ssg-5e24e8307f650e72881f747661a2b6e52db15f2d.zip
feat(receiver): add Webmention detail and status history
Add an authenticated detail view with full failure information, timestamps, actions, public status links, and recorded lifecycle transitions. Persist verification and resubmission events, backfill existing rows during migration, and clean up history when received Webmentions are deleted.
Diffstat (limited to '')
-rw-r--r--tests/views/test_endpoint.py49
1 files changed, 45 insertions, 4 deletions
diff --git a/tests/views/test_endpoint.py b/tests/views/test_endpoint.py
index 23643d9..4a2abde 100644
--- a/tests/views/test_endpoint.py
+++ b/tests/views/test_endpoint.py
@@ -6,7 +6,7 @@ import uuid
from datetime import UTC, datetime, timedelta
from http import HTTPStatus
from types import ModuleType
-from unittest.mock import ANY, Mock
+from unittest.mock import Mock
import pytest
import sqlalchemy as sa
@@ -227,9 +227,9 @@ def test_endpoint_recovers_from_concurrent_insert(
assert response.headers["Location"].endswith(f"/status/{competing_identifier}")
assert execute.call_count == 3
- add.assert_called_once_with(ANY)
- rollback.assert_called_once_with()
- assert commit.call_count == 2
+ assert add.call_count == (2 if reopened else 1)
+ assert rollback.call_count == (1 if reopened else 2)
+ assert commit.call_count == (2 if reopened else 1)
if reopened:
verify_webmention.assert_called_once_with(competing_identifier)
@@ -469,3 +469,44 @@ def test_endpoint_rejects_bad_url_before_inserting_row(
)
== 0
)
+
+
+def test_endpoint_records_initial_and_resubmission_events(
+ app: Flask,
+ client: FlaskClient,
+ views_module: ModuleType,
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ from webmentions_ssg.models.received import ReceivedWebmentionStatusEvent
+
+ mock_endpoint_form(views_module, monkeypatch, valid=True)
+ monkeypatch.setattr(views_module, "verify_webmention", Mock())
+
+ response = client.post("/endpoint")
+ assert response.status_code == HTTPStatus.CREATED
+ with app.app_context():
+ mention = db.session.scalar(sa.select(ReceivedWebmention))
+ assert mention is not None
+ identifier = mention.uuid
+ events = db.session.scalars(
+ sa.select(ReceivedWebmentionStatusEvent).where(
+ ReceivedWebmentionStatusEvent.webmention_uuid == identifier
+ )
+ ).all()
+ assert [event.action for event in events] == ["Received submission"]
+ mention.status = "failed"
+ mention.failure_reason = "Previous failure"
+ mention.updated_at = datetime.now(UTC) - timedelta(minutes=11)
+ db.session.commit()
+
+ assert client.post("/endpoint").status_code == HTTPStatus.CREATED
+ with app.app_context():
+ events = db.session.scalars(
+ sa.select(ReceivedWebmentionStatusEvent)
+ .where(ReceivedWebmentionStatusEvent.webmention_uuid == identifier)
+ .order_by(ReceivedWebmentionStatusEvent.id)
+ ).all()
+ assert [event.action for event in events] == [
+ "Received submission",
+ "Resubmitted after cooldown",
+ ]