aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_models.py42
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)