aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/tasks')
-rw-r--r--tests/tasks/test_scanner.py54
-rw-r--r--tests/tasks/test_source_parser.py5
-rw-r--r--tests/tasks/test_verification.py18
3 files changed, 67 insertions, 10 deletions
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py
index af5a64e..dae4628 100644
--- a/tests/tasks/test_scanner.py
+++ b/tests/tasks/test_scanner.py
@@ -1521,3 +1521,57 @@ def test_failed_scan_does_not_update_completion_time(
state = db.session.get(ScanState, 1)
assert state is not None
assert state.last_completed_at == previous_time
+
+
+def test_source_lifecycle_history_records_real_transitions_only(
+ app: Flask, scanner_module: ModuleType
+) -> None:
+ """An unchanged rescan is not an event; changes are preserved per source."""
+ from webmentions_ssg.models.sources import SourceDocumentEvent
+
+ timestamp = datetime(2026, 11, 1, tzinfo=UTC)
+ original = source_parser.ScannedSource(
+ path="tracked/index.html",
+ url="https://site.example/tracked/",
+ content_hash="0" * 32,
+ targets=frozenset({"https://example.org/linked"}),
+ )
+ changed = source_parser.ScannedSource(
+ path=original.path,
+ url=original.url,
+ content_hash="1" * 32,
+ targets=original.targets,
+ )
+
+ with app.app_context():
+ source = scanner_module.build_source(original, timestamp)
+ db.session.add(source)
+ db.session.commit()
+ assert [(event.action, event.revision) for event in source.history_events] == [
+ ("Discovered", 1)
+ ]
+ scanner_module.apply_scan_to_source(
+ source, original, timestamp + timedelta(days=1)
+ )
+ assert len(source.history_events) == 1
+ scanner_module.apply_scan_to_source(
+ source, changed, timestamp + timedelta(days=2)
+ )
+ scanner_module.mark_missing_sources_deleted(
+ {source.path: source}, frozenset(), timestamp + timedelta(days=3)
+ )
+ scanner_module.apply_scan_to_source(
+ source, original, timestamp + timedelta(days=4)
+ )
+ db.session.commit()
+ persisted = db.session.scalars(
+ sa.select(SourceDocumentEvent)
+ .where(SourceDocumentEvent.source_uuid == source.uuid)
+ .order_by(SourceDocumentEvent.id)
+ ).all()
+ assert [(event.action, event.revision) for event in persisted] == [
+ ("Discovered", 1),
+ ("Revised", 2),
+ ("Deleted", 3),
+ ("Restored", 4),
+ ]
diff --git a/tests/tasks/test_source_parser.py b/tests/tasks/test_source_parser.py
index 38a5dc1..8c9b74a 100644
--- a/tests/tasks/test_source_parser.py
+++ b/tests/tasks/test_source_parser.py
@@ -1035,10 +1035,7 @@ def test_outgoing_targets_skip_urls_with_unparseable_hostname(
monkeypatch.setattr(source_parser_module, "normalize_hostname", invalid_hostname)
assert list(
source_parser_module.iter_outgoing_targets(
- content,
- {},
- base_url=SOURCE_URL,
- source_url=SOURCE_URL,
+ content, {}, base_url=SOURCE_URL, source_url=SOURCE_URL
)
) == ["https://good.example/post"]
diff --git a/tests/tasks/test_verification.py b/tests/tasks/test_verification.py
index d9c2f77..a581cc1 100644
--- a/tests/tasks/test_verification.py
+++ b/tests/tasks/test_verification.py
@@ -849,9 +849,12 @@ def test_verification_claim_race_rolls_back_without_status_event(
row = db.session.get(ReceivedWebmention, identifier)
assert row is not None
assert row.status == "received"
- assert db.session.scalar(
- sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id))
- ) == 0
+ assert (
+ db.session.scalar(
+ sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id))
+ )
+ == 0
+ )
def test_stale_verification_claim_race_does_not_enqueue(
@@ -870,7 +873,10 @@ def test_stale_verification_claim_race_does_not_enqueue(
row = db.session.get(ReceivedWebmention, identifier)
assert row is not None
assert row.status == "verifying"
- assert db.session.scalar(
- sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id))
- ) == 0
+ assert (
+ db.session.scalar(
+ sa.select(sa.func.count(ReceivedWebmentionStatusEvent.id))
+ )
+ == 0
+ )
enqueue.assert_not_called()