diff options
| author | Dennis Fink | 2026-11-13 20:40:37 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-13 20:40:37 +0100 |
| commit | 82495162be98323fc56a35f2c2a59c143a765136 (patch) | |
| tree | ebee8daa3eabe4abd8ae6a43b22655e6e6c970f2 /tests | |
| parent | 22f453be12822f1c26f2ba6e229cdc8840ffaa92 (diff) | |
| download | webmentions-ssg-82495162be98323fc56a35f2c2a59c143a765136.tar.gz webmentions-ssg-82495162be98323fc56a35f2c2a59c143a765136.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | tests/test_models.py | 42 |
1 files changed, 42 insertions, 0 deletions
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) |
