diff options
Diffstat (limited to '')
| -rw-r--r-- | tests/tasks/test_scanner.py | 84 |
1 files changed, 46 insertions, 38 deletions
diff --git a/tests/tasks/test_scanner.py b/tests/tasks/test_scanner.py index 00256d0..4cf2a67 100644 --- a/tests/tasks/test_scanner.py +++ b/tests/tasks/test_scanner.py @@ -17,7 +17,7 @@ from huey.exceptions import RetryTask from pytest import MonkeyPatch from webmentions_ssg import db -from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, Source +from webmentions_ssg.models import SentWebmention, SentWebmentionStatus, SourceDocument from webmentions_ssg.tasks import source_parser from .scanner_helpers import BASE_URL, SOURCE_URL, configure_scanner, write_post @@ -65,7 +65,7 @@ def test_manual_scan_runs_without_lock_contention( with app.app_context(): scanner_module.manual_scan_sources.call_local() source = db.session.scalar( - sa.select(Source).where(Source.path == "manual/index.html") + sa.select(SourceDocument).where(SourceDocument.path == "manual/index.html") ) assert source is not None assert source.url == f"{BASE_URL}manual/" @@ -101,7 +101,7 @@ def test_reconcile_source_tree_returns_count_and_seen_paths( ) monkeypatch.setattr(scanner_module, "scan_source_file", parse) - sources: dict[str, Source] = {} + sources: dict[str, SourceDocument] = {} urls: dict[str, str] = {} with app.app_context(): @@ -141,7 +141,7 @@ def test_scan_creates_source_and_webmentions( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) assert source is not None assert source.path == "example/index.html" @@ -161,7 +161,7 @@ def test_scan_creates_source_and_webmentions( "https://example.com/b", ] - assert all(webmention.active for webmention in webmentions) + assert all(webmention.linked for webmention in webmentions) assert all(webmention.desired_revision == 1 for webmention in webmentions) assert all(webmention.processed_revision is None for webmention in webmentions) @@ -198,7 +198,7 @@ def test_duplicate_canonical_url_skips_alias_and_commits_other_sources( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) webmentions = list(db.session.scalars(sa.select(SentWebmention))) assert len(sources) == 2 @@ -262,7 +262,7 @@ def test_existing_source_owns_canonical_url_when_alias_is_added( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) targets = list(db.session.scalars(sa.select(SentWebmention.target))) assert len(sources) == 1 @@ -311,7 +311,8 @@ def test_deleted_source_still_reserves_its_canonical_url( with app.app_context(): sources = { - source.path: source for source in db.session.scalars(sa.select(Source)) + source.path: source + for source in db.session.scalars(sa.select(SourceDocument)) } assert set(sources) == {"owner/index.html", "unrelated/index.html"} assert sources["owner/index.html"].deleted_at is not None @@ -358,7 +359,7 @@ def test_unchanged_source_does_not_increment_revision( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) assert source is not None assert source.revision == 1 @@ -388,7 +389,7 @@ def test_changing_relative_timestamp_does_not_resend( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None and webmention is not None original_hash = source.content_hash @@ -405,7 +406,7 @@ def test_changing_relative_timestamp_does_not_resend( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None and webmention is not None assert source.content_hash == original_hash @@ -485,7 +486,7 @@ def test_updated_source_increments_revision( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -493,7 +494,7 @@ def test_updated_source_increments_revision( assert source.revision == 2 - assert webmention.active + assert webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision == 1 assert webmention.sent_revision == 1 @@ -555,7 +556,7 @@ def test_new_target_is_added_on_update( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -564,7 +565,7 @@ def test_new_target_is_added_on_update( assert source.revision == 2 assert webmention.target == ("https://example.com/new") - assert webmention.active + assert webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision is None assert webmention.sent_revision is None @@ -638,7 +639,7 @@ def test_removed_sent_target_is_queued_again( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -646,7 +647,7 @@ def test_removed_sent_target_is_queued_again( assert source.revision == 2 - assert not webmention.active + assert not webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision == 1 assert webmention.sent_revision == 1 @@ -706,7 +707,7 @@ def test_removed_unsent_target_is_not_queued( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -714,7 +715,7 @@ def test_removed_unsent_target_is_not_queued( assert source.revision == 2 - assert not webmention.active + assert not webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision == 2 assert webmention.sent_revision is None @@ -756,14 +757,14 @@ def test_empty_output_directory_does_not_delete_sources_or_queue_removals( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) webmentions = list(db.session.scalars(sa.select(SentWebmention))) assert len(sources) == 2 assert all(source.revision == 1 for source in sources) assert all(source.deleted_at is None for source in sources) assert len(webmentions) == 2 - assert all(webmention.active for webmention in webmentions) + assert all(webmention.linked for webmention in webmentions) assert all(webmention.desired_revision == 1 for webmention in webmentions) assert queued == [] @@ -775,7 +776,7 @@ def test_empty_output_directory_does_not_delete_sources_or_queue_removals( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) assert all(source.revision == 1 for source in sources) assert all(source.deleted_at is None for source in sources) @@ -802,7 +803,7 @@ def test_no_successful_pages_defers_pending_webmentions( assert queued == [] with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None and source.deleted_at is None assert webmention is not None and webmention.desired_revision == 1 @@ -826,7 +827,7 @@ def test_failed_scan_does_not_delete_missing_source( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) assert len(sources) == 2 assert all(source.revision == 1 for source in sources) assert all(source.deleted_at is None for source in sources) @@ -873,7 +874,9 @@ def test_deleted_source_queues_previously_sent_webmention( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL)) + source = db.session.scalar( + sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL) + ) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -882,7 +885,7 @@ def test_deleted_source_queues_previously_sent_webmention( assert source.revision == 2 assert source.deleted_at is not None - assert not webmention.active + assert not webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision == 1 assert webmention.sent_revision == 1 @@ -919,7 +922,9 @@ def test_deleted_source_does_not_queue_unsent_webmention( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL)) + source = db.session.scalar( + sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL) + ) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -928,7 +933,7 @@ def test_deleted_source_does_not_queue_unsent_webmention( assert source.revision == 2 assert source.deleted_at is not None - assert not webmention.active + assert not webmention.linked assert webmention.desired_revision == 2 assert webmention.processed_revision == 2 assert webmention.sent_revision is None @@ -988,7 +993,9 @@ def test_restored_source_creates_new_revision( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source).where(Source.url == SOURCE_URL)) + source = db.session.scalar( + sa.select(SourceDocument).where(SourceDocument.url == SOURCE_URL) + ) webmention = db.session.scalar(sa.select(SentWebmention)) assert source is not None @@ -997,7 +1004,7 @@ def test_restored_source_creates_new_revision( assert source.revision == 3 assert source.deleted_at is None - assert webmention.active + assert webmention.linked assert webmention.desired_revision == 3 assert webmention.sent_revision == 1 @@ -1129,7 +1136,7 @@ def test_invalid_known_source_is_not_deleted( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) assert source is not None assert source.revision == 1 @@ -1186,7 +1193,7 @@ def test_unexpected_parser_error_does_not_abort_other_sources( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) webmention = db.session.scalar(sa.select(SentWebmention)) assert [source.path for source in sources] == ["good/index.html"] @@ -1225,7 +1232,8 @@ def test_unexpected_parser_error_does_not_delete_known_source( with app.app_context(): sources = { - source.path: source for source in db.session.scalars(sa.select(Source)) + source.path: source + for source in db.session.scalars(sa.select(SourceDocument)) } bad = sources["bad/index.html"] good = sources["good/index.html"] @@ -1274,7 +1282,7 @@ def test_scan_sources_skips_symlink_outside_root( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) assert len(sources) == 1 assert sources[0].path == "example/index.html" assert "escapes source directory" in caplog.text @@ -1314,7 +1322,7 @@ def test_scan_sources_accepts_valid_base_url( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) assert source is not None assert source.url == SOURCE_URL @@ -1364,7 +1372,7 @@ def test_changed_source_url_is_rejected( run_scan(app, scanner_module) with app.app_context(): - source = db.session.scalar(sa.select(Source)) + source = db.session.scalar(sa.select(SourceDocument)) assert source is not None assert source.url == SOURCE_URL @@ -1381,7 +1389,7 @@ def test_scan_sources_returns_when_source_directory_is_not_configured( run_scan(app, scanner_module) with app.app_context(): - assert db.session.scalar(sa.select(Source)) is None + assert db.session.scalar(sa.select(SourceDocument)) is None def test_scan_sources_rejects_missing_source_directory( @@ -1448,7 +1456,7 @@ def test_scan_sources_ignores_root_index( run_scan(app, scanner_module) with app.app_context(): - sources = list(db.session.scalars(sa.select(Source))) + sources = list(db.session.scalars(sa.select(SourceDocument))) assert len(sources) == 1 assert sources[0].path == "example/index.html" |
