From 4da341989908a82500cd3ebfacbe4f0d0ae5627e Mon Sep 17 00:00:00 2001 From: Sean Hammond Date: Fri, 6 Sep 2024 13:27:22 +0100 Subject: [PATCH] Add shared mock AnnotationStatsService --- tests/common/fixtures/services.py | 7 +++++++ tests/unit/h/views/activity_test.py | 16 ++++------------ tests/unit/h/views/admin/users_test.py | 10 +++------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/common/fixtures/services.py b/tests/common/fixtures/services.py index a9a8369c84d..6d008002ff7 100644 --- a/tests/common/fixtures/services.py +++ b/tests/common/fixtures/services.py @@ -8,6 +8,7 @@ from h.services.annotation_metadata import AnnotationMetadataService from h.services.annotation_moderation import AnnotationModerationService from h.services.annotation_read import AnnotationReadService +from h.services.annotation_stats import AnnotationStatsService from h.services.annotation_sync import AnnotationSyncService from h.services.annotation_write import AnnotationWriteService from h.services.auth_ticket import AuthTicketService @@ -49,6 +50,7 @@ "annotation_json_service", "annotation_metadata_service", "annotation_read_service", + "annotation_stats_service", "annotation_sync_service", "annotation_write_service", "auth_ticket_service", @@ -116,6 +118,11 @@ def annotation_json_service(mock_service): return mock_service(AnnotationJSONService, name="annotation_json") +@pytest.fixture +def annotation_stats_service(mock_service): + return mock_service(AnnotationStatsService, name="annotation_stats") + + @pytest.fixture def annotation_read_service(mock_service): return mock_service(AnnotationReadService) diff --git a/tests/unit/h/views/activity_test.py b/tests/unit/h/views/activity_test.py index 759875b0bd8..f3decfe9abc 100644 --- a/tests/unit/h/views/activity_test.py +++ b/tests/unit/h/views/activity_test.py @@ -9,7 +9,6 @@ from h.activity.query import ActivityResults from h.security import Permission -from h.services.annotation_stats import AnnotationStatsService from h.traversal import UserContext from h.traversal.group import GroupContext from h.views import activity @@ -1279,17 +1278,10 @@ def routes(pyramid_config): @pytest.fixture -def annotation_stats_service(pyramid_config): - ann_stat_svc = mock.create_autospec( - AnnotationStatsService, instance=True, spec_set=True - ) - - ann_stat_svc.user_annotation_count.return_value = 6 - ann_stat_svc.group_annotation_count.return_value = 5 - - pyramid_config.register_service(ann_stat_svc, name="annotation_stats") - - return ann_stat_svc +def annotation_stats_service(annotation_stats_service): + annotation_stats_service.user_annotation_count.return_value = 6 + annotation_stats_service.group_annotation_count.return_value = 5 + return annotation_stats_service @pytest.fixture diff --git a/tests/unit/h/views/admin/users_test.py b/tests/unit/h/views/admin/users_test.py index 586064ed185..30119e4e9b3 100644 --- a/tests/unit/h/views/admin/users_test.py +++ b/tests/unit/h/views/admin/users_test.py @@ -5,7 +5,6 @@ from pyramid import httpexceptions from h.models import Annotation -from h.services.annotation_stats import AnnotationStatsService from h.services.user_delete import UserDeleteService from h.views.admin.users import ( UserNotFoundError, @@ -211,12 +210,9 @@ def models(patch): @pytest.fixture -def annotation_stats_service(pyramid_config, pyramid_request): - service = mock.create_autospec(AnnotationStatsService, instance=True, spec_set=True) - service.return_value.request = pyramid_request - service.total_user_annotation_count.return_value = 0 - pyramid_config.register_service(service, name="annotation_stats") - return service +def annotation_stats_service(annotation_stats_service): + annotation_stats_service.total_user_annotation_count.return_value = 0 + return annotation_stats_service @pytest.fixture