From 82495162be98323fc56a35f2c2a59c143a765136 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 13 Nov 2026 20:40:37 +0100 Subject: refactor(core): centralize pending revision logic Make `SentWebmention.pending` a hybrid property so the same definition works in Python and SQL expressions. Reuse it across sender and scanner guards to remove duplicated revision checks. --- tests/test_models.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/test_models.py b/tests/test_models.py index b1eed94..7ec7df7 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -77,6 +77,48 @@ def test_sent_webmention_pending( assert webmention.pending is expected +def test_sent_webmention_pending_sql_matches_python(app: Flask) -> None: + cases = [(1, None, True), (1, 0, True), (2, 1, True), (1, 1, False), (1, 2, False)] + + with app.app_context(): + now = datetime.now(UTC) + source = Source( + path="pending/index.html", + url="https://site.example/pending/", + content_hash="0" * 32, + last_seen_at=now, + revised_at=now, + ) + for i, (desired, processed, _) in enumerate(cases): + source.sent_webmentions.append( + SentWebmention( + target=f"https://example.com/post/{i}", + desired_revision=desired, + processed_revision=processed, + ) + ) + db.session.add(source) + db.session.commit() + + pending_ids = set( + db.session.scalars( + sa.select(SentWebmention.uuid).where(SentWebmention.pending) + ) + ) + for webmention, (_, _, expected) in zip( + source.sent_webmentions, cases, strict=True + ): + assert webmention.pending is expected + assert (webmention.uuid in pending_ids) is expected + + result = db.session.execute( + sa.update(SentWebmention) + .where(SentWebmention.pending) + .values(attempt_count=1) + ) + assert result.rowcount == 3 + + def test_uuid7_to_datetime() -> None: identifier = uuid.uuid7() timestamp = uuid7_to_datetime(identifier) -- cgit v1.3.1