aboutsummaryrefslogtreecommitdiff
path: root/tests/views/test_endpoint.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/views/test_endpoint.py')
-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",
+ ]