Skip to content

Commit

Permalink
Add test coverage for the URL migration tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Betts committed Jun 15, 2023
1 parent f722293 commit 49c3960
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/common/fixtures/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +58,7 @@
"organization_service",
"search_index",
"subscription_service",
"url_migration_service",
"user_password_service",
"user_service",
"user_password_service",
Expand Down Expand Up @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions tests/h/tasks/url_migration_test.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 49c3960

Please sign in to comment.