aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tasks')
-rw-r--r--tests/tasks/test_sender.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py
index 0d68933..5be2177 100644
--- a/tests/tasks/test_sender.py
+++ b/tests/tasks/test_sender.py
@@ -11,12 +11,14 @@ from unittest.mock import MagicMock, Mock
import httpx
import pytest
+import sqlalchemy as sa
from flask import Flask
from webmentions_ssg import db
from webmentions_ssg.models.sources import (
SentWebmention,
SentWebmentionStatus,
+ SentWebmentionStatusEvent,
SourceDocument,
)
@@ -184,6 +186,16 @@ def test_send_webmention_persists_success(
assert webmention.last_sent_at is not None
assert webmention.attempt_count == 1
assert webmention.next_retry_at is None
+ history = db.session.scalars(
+ sa.select(SentWebmentionStatusEvent).where(
+ SentWebmentionStatusEvent.webmention_uuid == identifier
+ )
+ ).all()
+ assert len(history) == 1
+ assert history[0].action == "Delivery succeeded"
+ assert history[0].status == SentWebmentionStatus.SENT
+ assert history[0].attempt_count == 1
+ assert history[0].endpoint_response_status == HTTPStatus.CREATED
def test_send_webmention_marks_unsupported_target_processed(
@@ -221,6 +233,10 @@ def test_send_webmention_marks_unsupported_target_processed(
assert webmention.endpoint_response_status is None
assert webmention.status_url is None
assert webmention.last_attempted_at is not None
+ history = db.session.scalars(sa.select(SentWebmentionStatusEvent)).all()
+ assert len(history) == 1
+ assert history[0].action == "No endpoint discovered"
+ assert history[0].status == SentWebmentionStatus.NO_ENDPOINT
def test_send_webmention_persists_permanent_failure(
@@ -252,6 +268,10 @@ def test_send_webmention_persists_permanent_failure(
assert webmention.webmention_endpoint == ENDPOINT_URL
assert webmention.endpoint_response_status == HTTPStatus.BAD_REQUEST
assert webmention.status_url is None
+ history = db.session.scalars(sa.select(SentWebmentionStatusEvent)).all()
+ assert len(history) == 1
+ assert history[0].action == "Delivery failed"
+ assert history[0].failure_reason == webmention.failure_reason
def test_send_webmention_persists_temporary_failure_with_backoff(
@@ -291,6 +311,10 @@ def test_send_webmention_persists_temporary_failure_with_backoff(
webmention.next_retry_at.replace(tzinfo=None)
- webmention.last_attempted_at.replace(tzinfo=None)
).total_seconds() == 3600
+ history = db.session.scalars(sa.select(SentWebmentionStatusEvent)).all()
+ assert len(history) == 1
+ assert history[0].action == "Delivery failed; automatic retry scheduled"
+ assert history[0].attempt_count == 1
def test_backoff_delay_is_exponential_and_capped(