Skip to content

Commit e2c308f

Browse files
committed
improve notification mocking
1 parent eae2207 commit e2c308f

92 files changed

Lines changed: 421 additions & 498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

addons/boa/tests/test_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def test_handle_boa_error(self):
6868
output_file_name=self.output_file_name,
6969
job_id=self.job_id
7070
)
71-
assert len(notifications) == 1
72-
assert notifications[0]['type'] == NotificationType.Type.ADDONS_BOA_JOB_FAILURE
71+
assert len(notifications['emits']) == 1
72+
assert notifications['emits'][0]['type'] == NotificationType.Type.ADDONS_BOA_JOB_FAILURE
7373
mock_sentry_log_message.assert_called_with(self.error_message, skip_session=True)
7474
mock_logger_error.assert_called_with(self.error_message)
7575
assert return_value == BoaErrorCode.UNKNOWN

api_tests/crossref/views/test_crossref_email_response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def test_error_response_sends_message_does_not_set_doi(self, app, url, preprint,
162162
context_data = self.make_mailgun_payload(crossref_response=error_xml)
163163
with capture_notifications() as notifications:
164164
app.post(url, context_data)
165-
assert len(notifications) == 1
166-
assert notifications[0]['type'] == NotificationType.Type.PROVIDER_MODERATOR_ADDED
165+
assert len(notifications['emits']) == 1
166+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_MODERATOR_ADDED
167167
assert not preprint.get_identifier_value('doi')
168168

169169
def test_success_response_sets_doi(self, app, url, preprint, success_xml):

api_tests/draft_registrations/views/test_draft_registration_contributor_list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ def test_add_contributor_sends_email(self, app, user, user_two, url_project_cont
242242
auth=user.auth
243243
)
244244
assert res.status_code == 201
245-
assert len(notifications) == 1
246-
assert notifications[0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
245+
assert len(notifications['emits']) == 1
246+
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
247247

248248
# Overrides TestNodeContributorCreateEmail
249249
def test_add_contributor_signal_if_default(
@@ -285,8 +285,8 @@ def test_add_unregistered_contributor_sends_email(self, app, user, url_project_c
285285
auth=user.auth
286286
)
287287
assert res.status_code == 201
288-
assert len(notifications) == 1
289-
assert notifications[0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
288+
assert len(notifications['emits']) == 1
289+
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
290290

291291
# Overrides TestNodeContributorCreateEmail
292292
def test_add_unregistered_contributor_signal_if_default(self, app, user, url_project_contribs):
@@ -304,8 +304,8 @@ def test_add_unregistered_contributor_signal_if_default(self, app, user, url_pro
304304
}, auth=user.auth
305305
)
306306
assert res.status_code == 201
307-
assert len(notifications) == 1
308-
assert notifications[0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
307+
assert len(notifications['emits']) == 1
308+
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
309309

310310
# Overrides TestNodeContributorCreateEmail
311311
def test_add_unregistered_contributor_without_email_no_email(self, app, user, url_project_contribs):

api_tests/draft_registrations/views/test_draft_registration_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ def test_create_no_project_draft_emails_initiator(self, app, user, url_draft_reg
442442
payload,
443443
auth=user.auth
444444
)
445-
assert len(notifications) == 1
446-
assert notifications[0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
447-
assert notifications[0]['kwargs']['user'] == user
445+
assert len(notifications['emits']) == 1
446+
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
447+
assert notifications['emits'][0]['kwargs']['user'] == user
448448

449449
def test_create_draft_with_provider(
450450
self, app, user, url_draft_registrations, non_default_provider, payload_with_non_default_provider

api_tests/institutions/views/test_institution_relationship_nodes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ def test_email_sent_on_affiliation_addition(
398398
)
399399

400400
assert res.status_code == 201
401-
assert len(notifications) == 1
402-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
401+
assert len(notifications['emits']) == 1
402+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
403403

404404
def test_email_sent_on_affiliation_removal(self, app, admin, institution, node_public, url_institution_nodes):
405405
current_institution = InstitutionFactory()
@@ -421,8 +421,8 @@ def test_email_sent_on_affiliation_removal(self, app, admin, institution, node_p
421421
# Assert response is successful
422422
assert res.status_code == 204
423423

424-
assert len(notifications) == 2
425-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
426-
assert notifications[0]['kwargs']['user'] == node_public.creator
427-
assert notifications[1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
424+
assert len(notifications['emits']) == 2
425+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
426+
assert notifications['emits'][0]['kwargs']['user'] == node_public.creator
427+
assert notifications['emits'][1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
428428
assert notifications[1]['kwargs']['user'] == admin

api_tests/nodes/views/test_node_contributors_list.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,11 @@ def test_add_contributor_set_index_out_of_range(
10581058
notification_type=False,
10591059
)
10601060
user_contrib_two = UserFactory()
1061-
project_public.add_contributor(user_contrib_two, save=True)
1061+
project_public.add_contributor(
1062+
user_contrib_two,
1063+
save=True,
1064+
notification_type=False
1065+
)
10621066
payload = {
10631067
'data': {
10641068
'type': 'contributors',
@@ -1085,7 +1089,11 @@ def test_add_contributor_set_index_first(
10851089
save=True
10861090
)
10871091
user_contrib_two = UserFactory()
1088-
project_public.add_contributor(user_contrib_two, save=True)
1092+
project_public.add_contributor(
1093+
user_contrib_two,
1094+
notification_type=False,
1095+
save=True
1096+
)
10891097
payload = {
10901098
'data': {
10911099
'type': 'contributors',
@@ -1278,7 +1286,7 @@ def test_add_contributor_sends_email(
12781286
auth=user.auth
12791287
)
12801288
assert res.status_code == 201
1281-
assert len(notifications) == 1
1289+
assert len(notifications['emits']) == 1
12821290

12831291
@mock.patch('website.project.signals.contributor_added.send')
12841292
def test_add_contributor_signal_if_default(
@@ -1334,8 +1342,8 @@ def test_add_unregistered_contributor_sends_email(
13341342
auth=user.auth
13351343
)
13361344
assert res.status_code == 201
1337-
assert len(notifications) == 1
1338-
assert notifications[0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
1345+
assert len(notifications['emits']) == 1
1346+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
13391347

13401348
@mock.patch('website.project.signals.unreg_contributor_added.send')
13411349
def test_add_unregistered_contributor_signal_if_default(
@@ -1356,8 +1364,8 @@ def test_add_unregistered_contributor_signal_if_default(
13561364
auth=user.auth
13571365
)
13581366
assert res.status_code == 201
1359-
assert len(notifications) == 1
1360-
assert notifications[0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
1367+
assert len(notifications['emits']) == 1
1368+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
13611369

13621370
def test_add_unregistered_contributor_signal_preprint_email_disallowed(
13631371
self, app, user, url_project_contribs

api_tests/nodes/views/test_node_forks_list.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,10 +428,10 @@ def test_send_email_success(self, app, user, public_project_url, fork_data_with_
428428
)
429429
assert res.status_code == 201
430430
assert res.json['data']['id'] == public_project.forks.first()._id
431-
assert len(notifications) == 1
432-
assert notifications[0]['kwargs']['user'] == user
433-
assert notifications[0]['kwargs']['event_context']['guid'] == public_project.forks.first()._id
434-
assert notifications[0]['type'] == NotificationType.Type.NODE_FORK_COMPLETED
431+
assert len(notifications['emits']) == 1
432+
assert notifications['emits'][0]['kwargs']['user'] == user
433+
assert notifications['emits'][0]['kwargs']['event_context']['guid'] == public_project.forks.first()._id
434+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_FORK_COMPLETED
435435

436436
def test_send_email_failed(
437437
self, app, user, public_project_url, fork_data_with_title, public_project):
@@ -444,5 +444,5 @@ def test_send_email_failed(
444444
fork_data_with_title,
445445
auth=user.auth
446446
)
447-
assert len(notifications) == 1
448-
assert notifications[0]['type'] == NotificationType.Type.NODE_FORK_FAILED
447+
assert len(notifications['emits']) == 1
448+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_FORK_FAILED

api_tests/nodes/views/test_node_relationship_institutions.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ def test_user_with_institution_and_permissions_through_patch(
219219
auth=user.auth
220220
)
221221
assert res.status_code == 200
222-
assert len(notifications) == 2
222+
assert len(notifications['emits']) == 2
223223

224-
assert notifications[0]['kwargs']['user'] == user
225-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
224+
assert notifications['emits'][0]['kwargs']['user'] == user
225+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
226226
assert notifications[1]['kwargs']['user'] == user
227-
assert notifications[1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
227+
assert notifications['emits'][1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
228228

229229
def test_remove_institutions_with_affiliated_user(
230230
self,
@@ -246,9 +246,9 @@ def test_remove_institutions_with_affiliated_user(
246246
auth=user.auth
247247
)
248248

249-
assert len(notifications) == 1
250-
assert notifications[0]['kwargs']['user'] == user
251-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
249+
assert len(notifications['emits']) == 1
250+
assert notifications['emits'][0]['kwargs']['user'] == user
251+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
252252

253253
assert res.status_code == 200
254254
assert node.affiliated_institutions.count() == 0
@@ -305,9 +305,9 @@ def test_add_through_patch_one_inst_to_node_with_inst(
305305
self.create_payload([institution_one, institution_two]),
306306
auth=user.auth
307307
)
308-
assert len(notifications) == 1
309-
assert notifications[0]['kwargs']['user'] == user
310-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
308+
assert len(notifications['emits']) == 1
309+
assert notifications['emits'][0]['kwargs']['user'] == user
310+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
311311

312312
assert res.status_code == 200
313313
assert institution_one in node.affiliated_institutions.all()
@@ -333,12 +333,12 @@ def test_add_through_patch_one_inst_while_removing_other(
333333
self.create_payload([institution_two]),
334334
auth=user.auth
335335
)
336-
assert len(notifications) == 2
337-
assert notifications[0]['kwargs']['user'] == user
338-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
336+
assert len(notifications['emits']) == 2
337+
assert notifications['emits'][0]['kwargs']['user'] == user
338+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
339339

340340
assert notifications[1]['kwargs']['user'] == user
341-
assert notifications[1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
341+
assert notifications['emits'][1]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
342342

343343
assert res.status_code == 200
344344
assert institution_one not in node.affiliated_institutions.all()
@@ -364,9 +364,9 @@ def test_add_one_inst_with_post_to_node_with_inst(
364364
self.create_payload([institution_two]),
365365
auth=user.auth
366366
)
367-
assert len(notifications) == 1
368-
assert notifications[0]['kwargs']['user'] == user
369-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
367+
assert len(notifications['emits']) == 1
368+
assert notifications['emits'][0]['kwargs']['user'] == user
369+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
370370

371371
assert res.status_code == 201
372372
assert institution_one in node.affiliated_institutions.all()
@@ -398,9 +398,9 @@ def test_delete_existing_inst(
398398
auth=user.auth
399399
)
400400

401-
assert len(notifications) == 1
402-
assert notifications[0]['kwargs']['user'] == user
403-
assert notifications[0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
401+
assert len(notifications['emits']) == 1
402+
assert notifications['emits'][0]['kwargs']['user'] == user
403+
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_AFFILIATION_CHANGED
404404

405405
assert res.status_code == 204
406406
assert institution_one not in node.affiliated_institutions.all()

api_tests/preprints/views/test_preprint_contributors_list.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,8 +1420,8 @@ def test_add_contributor_signal_if_preprint(
14201420
auth=user.auth
14211421
)
14221422
assert res.status_code == 201
1423-
assert len(notifications) == 1
1424-
assert notifications[0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1423+
assert len(notifications['emits']) == 1
1424+
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
14251425

14261426
def test_add_unregistered_contributor_sends_email(
14271427
self, app, user, url_preprint_contribs):
@@ -1439,8 +1439,8 @@ def test_add_unregistered_contributor_sends_email(
14391439
},
14401440
auth=user.auth
14411441
)
1442-
assert len(notifications) == 1
1443-
assert notifications[0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1442+
assert len(notifications['emits']) == 1
1443+
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
14441444
assert res.status_code == 201
14451445

14461446
def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_preprint_contribs):
@@ -1459,8 +1459,8 @@ def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_pr
14591459
auth=user.auth
14601460
)
14611461
assert res.status_code == 201
1462-
assert len(notifications) == 1
1463-
assert notifications[0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1462+
assert len(notifications['emits']) == 1
1463+
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
14641464

14651465
def test_add_contributor_invalid_send_email_param(self, app, user, url_preprint_contribs):
14661466
url = f'{url_preprint_contribs}?send_email=true'
@@ -1540,8 +1540,8 @@ def test_contributor_added_signal_not_specified(self, app, user, url_preprint_co
15401540
auth=user.auth
15411541
)
15421542
assert res.status_code == 201
1543-
assert len(notifications) == 1
1544-
assert notifications[0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1543+
assert len(notifications['emits']) == 1
1544+
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
15451545

15461546
def test_contributor_added_not_sent_if_unpublished(self, app, user, preprint_unpublished):
15471547
with capture_notifications() as notifications:

api_tests/providers/collections/views/test_collections_provider_moderator_list.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ def test_POST_admin_success_existing_user(self, app, url, nonmoderator, moderato
114114

115115
with capture_notifications() as notifications:
116116
res = app.post_json_api(url, payload, auth=admin.auth)
117-
assert len(notifications) == 1
118-
assert notifications[0]['type'] == NotificationType.Type.PROVIDER_MODERATOR_ADDED
117+
assert len(notifications['emits']) == 1
118+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_MODERATOR_ADDED
119119
assert res.status_code == 201
120120
assert res.json['data']['id'] == nonmoderator._id
121121
assert res.json['data']['attributes']['permission_group'] == 'moderator'
@@ -143,9 +143,9 @@ def test_POST_admin_failure_unreg_moderator(self, app, url, moderator, nonmodera
143143
res = app.post_json_api(url, payload, auth=admin.auth)
144144

145145
assert res.status_code == 201
146-
assert len(notifications) == 1
147-
assert notifications[0]['type'] == NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
148-
assert notifications[0]['kwargs']['user'].username == unreg_user['email']
146+
assert len(notifications['emits']) == 1
147+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
148+
assert notifications['emits'][0]['kwargs']['user'].username == unreg_user['email']
149149

150150
def test_POST_admin_failure_invalid_group(self, app, url, nonmoderator, moderator, admin, provider):
151151
payload = make_payload(user_id=nonmoderator._id, permission_group='citizen')
@@ -158,8 +158,8 @@ def test_POST_admin_success_email(self, app, url, nonmoderator, moderator, admin
158158
payload = make_payload(email='somenewuser@gmail.com', full_name='Some User', permission_group='moderator')
159159
with capture_notifications() as notifications:
160160
res = app.post_json_api(url, payload, auth=admin.auth)
161-
assert len(notifications) == 1
162-
assert notifications[0]['type'] == NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
161+
assert len(notifications['emits']) == 1
162+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_CONFIRM_EMAIL_MODERATION
163163
assert res.status_code == 201
164164
assert len(res.json['data']['id']) == 5
165165
assert res.json['data']['attributes']['permission_group'] == 'moderator'

0 commit comments

Comments
 (0)