From 49c3960ed2ec5b843a0e69888330309165bbf96b Mon Sep 17 00:00:00 2001 From: Jon Betts Date: Tue, 23 May 2023 14:11:50 +0100 Subject: [PATCH] Add test coverage for the URL migration tasks --- tests/common/fixtures/services.py | 7 +++++++ tests/h/tasks/url_migration_test.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/h/tasks/url_migration_test.py diff --git a/tests/common/fixtures/services.py b/tests/common/fixtures/services.py index f369dfe68d6..18495c3498c 100644 --- a/tests/common/fixtures/services.py +++ b/tests/common/fixtures/services.py @@ -26,6 +26,7 @@ from h.services.search_index import SearchIndexService from h.services.search_index._queue import Queue from h.services.subscription import SubscriptionService +from h.services.url_migration import URLMigrationService from h.services.user import UserService from h.services.user_password import UserPasswordService from h.services.user_signup import UserSignupService @@ -57,6 +58,7 @@ "organization_service", "search_index", "subscription_service", + "url_migration_service", "user_password_service", "user_service", "user_password_service", @@ -213,6 +215,11 @@ def subscription_service(mock_service): return mock_service(SubscriptionService) +@pytest.fixture +def url_migration_service(mock_service): + return mock_service(URLMigrationService, name="url_migration") + + @pytest.fixture def user_password_service(mock_service): return mock_service(UserPasswordService, name="user_password") diff --git a/tests/h/tasks/url_migration_test.py b/tests/h/tasks/url_migration_test.py new file mode 100644 index 00000000000..a56fe009e35 --- /dev/null +++ b/tests/h/tasks/url_migration_test.py @@ -0,0 +1,29 @@ +from unittest.mock import sentinel + +import pytest + +from h.tasks.url_migration import move_annotations, move_annotations_by_url + + +class TestURLMigrationTasks: + def test_move_annotations_by_url(self, url_migration_service): + move_annotations_by_url(sentinel.old_url, sentinel.new_url_info) + + url_migration_service.move_annotations_by_url.assert_called_once_with( + sentinel.old_url, sentinel.new_url_info + ) + + def test_move_annotations(self, url_migration_service): + move_annotations( + sentinel.annotation_ids, sentinel.current_uri_normalized, sentinel.url_info + ) + + url_migration_service.move_annotations.assert_called_once_with( + sentinel.annotation_ids, sentinel.current_uri_normalized, sentinel.url_info + ) + + @pytest.fixture(autouse=True) + def celery(self, patch, pyramid_request): + celery = patch("h.tasks.url_migration.celery") + celery.request = pyramid_request + return celery