Skip to content

Commit

Permalink
Add shared mock AnnotationStatsService
Browse files Browse the repository at this point in the history
  • Loading branch information
seanh committed Sep 10, 2024
1 parent 01e0af1 commit 4499822
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
7 changes: 7 additions & 0 deletions tests/common/fixtures/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 4 additions & 12 deletions tests/unit/h/views/activity_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions tests/unit/h/views/admin/users_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4499822

Please sign in to comment.