-
Notifications
You must be signed in to change notification settings - Fork 442
/
Copy pathservices.py
349 lines (251 loc) · 9.56 KB
/
services.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
from unittest.mock import create_autospec
import pytest
from h.services import MentionService, NotificationService
from h.services.analytics import AnalyticsService
from h.services.annotation_authority_queue import AnnotationAuthorityQueueService
from h.services.annotation_delete import AnnotationDeleteService
from h.services.annotation_json import AnnotationJSONService
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
from h.services.auth_token import AuthTokenService
from h.services.bulk_api import (
BulkAnnotationService,
BulkGroupService,
BulkLMSStatsService,
)
from h.services.developer_token import DeveloperTokenService
from h.services.email import EmailService
from h.services.feature import FeatureService
from h.services.flag import FlagService
from h.services.group import GroupService
from h.services.group_create import GroupCreateService
from h.services.group_delete import GroupDeleteService
from h.services.group_links import GroupLinksService
from h.services.group_list import GroupListService
from h.services.group_members import GroupMembersService
from h.services.group_update import GroupUpdateService
from h.services.job_queue import JobQueueService
from h.services.links import LinksService
from h.services.list_organizations import ListOrganizationsService
from h.services.nipsa import NipsaService
from h.services.oauth.service import OAuthProviderService
from h.services.organization import OrganizationService
from h.services.search_index import SearchIndexService
from h.services.subscription import SubscriptionService
from h.services.task_done import TaskDoneService
from h.services.url_migration import URLMigrationService
from h.services.user import UserService
from h.services.user_delete import UserDeleteService
from h.services.user_password import UserPasswordService
from h.services.user_signup import UserSignupService
from h.services.user_unique import UserUniqueService
from h.services.user_update import UserUpdateService
__all__ = (
"analytics_service",
"annotation_authority_queue_service",
"annotation_delete_service",
"annotation_json_service",
"annotation_metadata_service",
"annotation_read_service",
"annotation_stats_service",
"annotation_sync_service",
"annotation_write_service",
"auth_ticket_service",
"auth_token_service",
"bulk_annotation_service",
"bulk_group_service",
"bulk_stats_service",
"developer_token_service",
"email_service",
"feature_service",
"flag_service",
"group_create_service",
"group_delete_service",
"group_links_service",
"group_list_service",
"group_members_service",
"group_service",
"group_update_service",
"links_service",
"list_organizations_service",
"mention_service",
"mock_service",
"moderation_service",
"nipsa_service",
"notification_service",
"oauth_provider_service",
"organization_service",
"queue_service",
"search_index",
"subscription_service",
"task_done_service",
"url_migration_service",
"user_delete_service",
"user_password_service",
"user_password_service",
"user_service",
"user_signup_service",
"user_unique_service",
"user_update_service",
)
@pytest.fixture
def mock_service(pyramid_config):
def mock_service(service_class, name=None, iface=None, spec_set=True, **kwargs): # noqa: FBT002
service = create_autospec(
service_class, instance=True, spec_set=spec_set, **kwargs
)
if name:
pyramid_config.register_service(service, name=name)
else:
pyramid_config.register_service(service, iface=iface or service_class)
return service
return mock_service
@pytest.fixture
def analytics_service(mock_service):
return mock_service(AnalyticsService, name="analytics")
@pytest.fixture
def annotation_delete_service(mock_service):
return mock_service(AnnotationDeleteService, name="annotation_delete")
@pytest.fixture
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)
@pytest.fixture
def annotation_sync_service(mock_service):
return mock_service(AnnotationSyncService)
@pytest.fixture
def annotation_write_service(mock_service):
return mock_service(AnnotationWriteService)
@pytest.fixture
def annotation_metadata_service(mock_service):
return mock_service(AnnotationMetadataService)
@pytest.fixture
def auth_ticket_service(mock_service):
auth_ticket_service = mock_service(AuthTicketService)
auth_ticket_service.verify_ticket.return_value.deleted = False
return auth_ticket_service
@pytest.fixture
def auth_token_service(mock_service):
return mock_service(AuthTokenService, name="auth_token")
@pytest.fixture
def bulk_annotation_service(mock_service):
return mock_service(BulkAnnotationService)
@pytest.fixture
def bulk_group_service(mock_service):
return mock_service(BulkGroupService)
@pytest.fixture
def bulk_stats_service(mock_service):
return mock_service(BulkLMSStatsService)
@pytest.fixture
def developer_token_service(mock_service):
return mock_service(DeveloperTokenService, name="developer_token")
@pytest.fixture
def links_service(mock_service):
return mock_service(LinksService, name="links")
@pytest.fixture
def list_organizations_service(mock_service, default_organization):
list_organizations_service = mock_service(
ListOrganizationsService, name="list_organizations"
)
list_organizations_service.organizations.return_value = [default_organization]
return list_organizations_service
@pytest.fixture
def flag_service(pyramid_config):
service = create_autospec(FlagService, instance=True, spec_set=True)
pyramid_config.register_service(service, name="flag")
return service
@pytest.fixture
def group_create_service(mock_service):
return mock_service(GroupCreateService, name="group_create")
@pytest.fixture
def group_delete_service(mock_service):
return mock_service(GroupDeleteService, name="group_delete")
@pytest.fixture
def group_links_service(mock_service):
return mock_service(GroupLinksService, name="group_links")
@pytest.fixture
def group_list_service(mock_service):
return mock_service(GroupListService, name="group_list")
@pytest.fixture
def group_members_service(mock_service):
return mock_service(GroupMembersService, name="group_members")
@pytest.fixture
def group_service(mock_service):
return mock_service(GroupService, name="group")
@pytest.fixture
def group_update_service(mock_service):
return mock_service(GroupUpdateService, name="group_update")
@pytest.fixture
def moderation_service(mock_service):
return mock_service(AnnotationModerationService, name="annotation_moderation")
@pytest.fixture
def nipsa_service(mock_service):
nipsa_service = mock_service(NipsaService, name="nipsa")
nipsa_service.is_flagged.return_value = False
return nipsa_service
@pytest.fixture
def oauth_provider_service(mock_service):
return mock_service(OAuthProviderService, name="oauth_provider")
@pytest.fixture
def organization_service(mock_service):
return mock_service(OrganizationService, name="organization")
@pytest.fixture
def search_index(mock_service):
return mock_service(SearchIndexService, "search_index", spec_set=False)
@pytest.fixture
def queue_service(mock_service):
return mock_service(JobQueueService, name="queue_service")
@pytest.fixture
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_delete_service(mock_service):
return mock_service(UserDeleteService, name="user_delete")
@pytest.fixture
def user_password_service(mock_service):
return mock_service(UserPasswordService, name="user_password")
@pytest.fixture
def user_service(mock_service):
user_service = mock_service(UserService, name="user")
user_service.fetch.return_value.deleted = False
return user_service
@pytest.fixture
def user_signup_service(mock_service):
return mock_service(UserSignupService, name="user_signup")
@pytest.fixture
def user_unique_service(mock_service):
return mock_service(UserUniqueService, name="user_unique")
@pytest.fixture
def user_update_service(mock_service):
return mock_service(UserUpdateService, name="user_update")
@pytest.fixture
def mention_service(mock_service):
return mock_service(MentionService)
@pytest.fixture
def notification_service(mock_service):
return mock_service(NotificationService)
@pytest.fixture
def annotation_authority_queue_service(mock_service):
return mock_service(AnnotationAuthorityQueueService)
@pytest.fixture
def feature_service(mock_service):
return mock_service(FeatureService, name="feature")
@pytest.fixture
def email_service(mock_service):
return mock_service(EmailService)
@pytest.fixture
def task_done_service(mock_service):
return mock_service(TaskDoneService)