aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/models/test_sources.py70
-rw-r--r--tests/views/test_sources.py31
2 files changed, 101 insertions, 0 deletions
diff --git a/tests/models/test_sources.py b/tests/models/test_sources.py
index 10af3d6..100572f 100644
--- a/tests/models/test_sources.py
+++ b/tests/models/test_sources.py
@@ -98,6 +98,76 @@ def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None:
assert result.rowcount == 3
+def test_source_sent_webmention_statistics_sql(app: Flask) -> None:
+ """SQL counts every delivery state and includes sources with no targets."""
+ now = datetime.now(UTC)
+ with app.app_context():
+ source = SourceDocument(
+ path="stats/index.html",
+ url="https://site.example/stats/",
+ content_hash="0" * 32,
+ last_seen_at=now,
+ revised_at=now,
+ )
+ empty = SourceDocument(
+ path="empty/index.html",
+ url="https://site.example/empty/",
+ content_hash="0" * 32,
+ last_seen_at=now,
+ revised_at=now,
+ )
+ for index, (status, processed, attempts, retry_at) in enumerate(
+ [
+ (SentWebmentionStatus.SENT, 1, 0, None),
+ (SentWebmentionStatus.SENT, 1, 0, None),
+ (SentWebmentionStatus.FAILED, None, 2, now),
+ (SentWebmentionStatus.NO_ENDPOINT, 1, 0, None),
+ (None, None, 1, None),
+ ]
+ ):
+ source.sent_webmentions.append(
+ SentWebmention(
+ target=f"https://target.example/{index}",
+ desired_revision=1,
+ processed_revision=processed,
+ status=status,
+ attempt_count=attempts,
+ next_retry_at=retry_at,
+ )
+ )
+ db.session.add_all([source, empty])
+ db.session.commit()
+
+ results = {
+ row.source_uuid: row
+ for row in db.session.execute(
+ SourceDocument.sent_webmention_statistics([source.uuid, empty.uuid])
+ )
+ }
+ assert set(results) == {source.uuid, empty.uuid}
+ assert (
+ results[source.uuid].total,
+ results[source.uuid].sent,
+ results[source.uuid].failed,
+ results[source.uuid].retrying,
+ ) == (5, 2, 1, 1)
+ assert (
+ results[empty.uuid].total,
+ results[empty.uuid].sent,
+ results[empty.uuid].failed,
+ results[empty.uuid].retrying,
+ ) == (0, 0, 0, 0)
+
+
+def test_source_sent_webmention_statistics_is_scoped_to_page(app: Flask) -> None:
+ """An empty UUID selection must not aggregate unrelated sources."""
+ with app.app_context():
+ assert (
+ list(db.session.execute(SourceDocument.sent_webmention_statistics([])))
+ == []
+ )
+
+
def test_source_repr() -> None:
source = SourceDocument(
path="example/index.html",
diff --git a/tests/views/test_sources.py b/tests/views/test_sources.py
index a41c18c..8f5672c 100644
--- a/tests/views/test_sources.py
+++ b/tests/views/test_sources.py
@@ -659,6 +659,37 @@ def test_resend_preserves_source_filter_context(
send.assert_called_once_with(mention_id)
+def test_sources_show_sql_statistics_with_zero_webmentions(
+ app: Flask, client: FlaskClient
+) -> None:
+ log_in(app, client)
+ make_source(
+ app,
+ "mixed-stats",
+ statuses=(
+ SentWebmentionStatus.SENT,
+ SentWebmentionStatus.SENT,
+ SentWebmentionStatus.FAILED,
+ SentWebmentionStatus.NO_ENDPOINT,
+ ),
+ )
+ make_source(app, "empty-stats", statuses=())
+
+ response = client.get("/sources", 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"
+ )
+ assert len(rows) == 2
+ assert "0 Total" in rows[0].get_text(" ", strip=True)
+ assert " sent" not in rows[0].get_text(" ", strip=True)
+ mixed = rows[1].get_text(" ", strip=True)
+ assert "4 Total" in mixed
+ assert "2 sent" in mixed
+ assert "1 failed" in mixed
+ assert "awaiting retry" not in mixed
+
+
def test_sources_empty_filter_result_keeps_rescan_modal(
app: Flask, client: FlaskClient
) -> None: