From 5e24e8307f650e72881f747661a2b6e52db15f2d Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Tue, 17 Nov 2026 19:43:04 +0100 Subject: 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. --- tests/views/test_endpoint.py | 49 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) (limited to 'tests/views/test_endpoint.py') 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", + ] -- cgit v1.3.1