Skip to content

Commit 91d048d

Browse files
Update send_mail mocks
1 parent 2d3d1c0 commit 91d048d

File tree

51 files changed

+280
-273
lines changed

Some content is hidden

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

51 files changed

+280
-273
lines changed

addons/boa/tests/test_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_boa_error_code(self):
5353
assert BoaErrorCode.JOB_TIME_OUT_ERROR == 7
5454

5555
def test_handle_boa_error(self):
56-
with mock.patch('addons.boa.tasks.send_mail', return_value=None) as mock_send_mail, \
56+
with mock.patch('addons.boa.tasks.execute_email_send', return_value=None) as mock_send_mail, \
5757
mock.patch('addons.boa.tasks.sentry.log_message', return_value=None) as mock_sentry_log_message, \
5858
mock.patch('addons.boa.tasks.logger.error', return_value=None) as mock_logger_error:
5959
return_value = handle_boa_error(
@@ -179,7 +179,7 @@ async def test_submit_success(self):
179179
mock.patch('boaapi.boa_client.BoaClient.query', return_value=self.mock_job), \
180180
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
181181
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None) as mock_async_sleep, \
182-
mock.patch('addons.boa.tasks.send_mail', return_value=None) as mock_send_mail, \
182+
mock.patch('addons.boa.tasks.execute_email_send', return_value=None) as mock_send_mail, \
183183
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
184184
return_value = await submit_to_boa_async(
185185
self.host,

api_tests/crossref/views/test_crossref_email_response.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_wrong_request_context_raises_permission_error(self, app, url, error_xml
158158
def test_error_response_sends_message_does_not_set_doi(self, app, url, preprint, error_xml):
159159
assert not preprint.get_identifier_value('doi')
160160

161-
with mock.patch('framework.auth.views.mails.send_mail') as mock_send_mail:
161+
with mock.patch('framework.auth.views.mails.execute_email_send') as mock_send_mail:
162162
context_data = self.make_mailgun_payload(crossref_response=error_xml)
163163
app.post(url, context_data)
164164
assert mock_send_mail.called
@@ -167,7 +167,7 @@ def test_error_response_sends_message_does_not_set_doi(self, app, url, preprint,
167167
def test_success_response_sets_doi(self, app, url, preprint, success_xml):
168168
assert not preprint.get_identifier_value('doi')
169169

170-
with mock.patch('framework.auth.views.mails.send_mail') as mock_send_mail:
170+
with mock.patch('framework.auth.views.mails.execute_email_send') as mock_send_mail:
171171
context_data = self.make_mailgun_payload(crossref_response=success_xml)
172172
app.post(url, context_data)
173173

@@ -181,7 +181,7 @@ def test_update_success_response(self, app, preprint, url):
181181
preprint.set_identifier_value(category='doi', value=initial_value)
182182
update_xml = self.update_success_xml(preprint)
183183

184-
with mock.patch('framework.auth.views.mails.send_mail') as mock_send_mail:
184+
with mock.patch('framework.auth.views.mails.execute_email_send') as mock_send_mail:
185185
context_data = self.make_mailgun_payload(crossref_response=update_xml)
186186
app.post(url, context_data)
187187

@@ -195,7 +195,7 @@ def test_update_success_does_not_set_preprint_doi_created(self, app, preprint, u
195195
update_xml = self.update_success_xml(preprint)
196196

197197
pre_created = preprint.preprint_doi_created
198-
with mock.patch('framework.auth.views.mails.send_mail'):
198+
with mock.patch('framework.auth.views.mails.execute_email_send'):
199199
context_data = self.make_mailgun_payload(crossref_response=update_xml)
200200
app.post(url, context_data)
201201

@@ -219,7 +219,7 @@ def test_confirmation_marks_legacy_doi_as_deleted(self, app, url, preprint):
219219
preprint.set_identifier_value(category='legacy_doi', value=legacy_value)
220220
update_xml = self.update_success_xml(preprint)
221221

222-
with mock.patch('framework.auth.views.mails.send_mail') as mock_send_mail:
222+
with mock.patch('framework.auth.views.mails.execute_email_send') as mock_send_mail:
223223
context_data = self.make_mailgun_payload(crossref_response=update_xml)
224224
app.post(url, context_data)
225225

api_tests/draft_registrations/views/test_draft_registration_contributor_list.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def url_project_contribs(self, project_public):
214214
# Overrides TestNodeContributorCreateEmail
215215
return f'/{API_BASE}draft_registrations/{project_public._id}/contributors/'
216216

217-
@mock.patch('framework.auth.views.mails.send_mail')
217+
@mock.patch('framework.auth.views.mails.execute_email_send')
218218
def test_add_contributor_sends_email(
219219
self, mock_mail, app, user, user_two,
220220
url_project_contribs):
@@ -264,7 +264,7 @@ def test_add_contributor_signal_if_default(
264264
assert res.json['errors'][0]['detail'] == 'default is not a valid email preference.'
265265

266266
# Overrides TestNodeContributorCreateEmail
267-
@mock.patch('framework.auth.views.mails.send_mail')
267+
@mock.patch('framework.auth.views.mails.execute_email_send')
268268
def test_add_unregistered_contributor_sends_email(
269269
self, mock_mail, app, user, url_project_contribs):
270270
url = f'{url_project_contribs}?send_email=draft_registration'
@@ -301,7 +301,7 @@ def test_add_unregistered_contributor_signal_if_default(
301301
assert 'draft_registration' == kwargs['email_template']
302302

303303
# Overrides TestNodeContributorCreateEmail
304-
@mock.patch('framework.auth.views.mails.send_mail')
304+
@mock.patch('framework.auth.views.mails.execute_email_send')
305305
def test_add_unregistered_contributor_without_email_no_email(
306306
self, mock_mail, app, user, url_project_contribs):
307307
url = f'{url_project_contribs}?send_email=draft_registration'

api_tests/draft_registrations/views/test_draft_registration_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def test_logged_in_non_contributor_cannot_create_draft(
337337
assert res.status_code == 403
338338

339339
def test_create_project_based_draft_does_not_email_initiator(self, app, user, url_draft_registrations, payload):
340-
with mock.patch.object(mails, 'send_mail') as mock_send_mail:
340+
with mock.patch.object(mails, 'execute_email_send') as mock_send_mail:
341341
app.post_json_api(f'{url_draft_registrations}?embed=branched_from&embed=initiator', payload, auth=user.auth)
342342

343343
assert not mock_send_mail.called
@@ -430,7 +430,7 @@ def test_admin_can_create_draft(
430430

431431
def test_create_no_project_draft_emails_initiator(self, app, user, url_draft_registrations, payload):
432432
# Intercepting the send_mail call from website.project.views.contributor.notify_added_contributor
433-
with mock.patch.object(mails, 'send_mail') as mock_send_mail:
433+
with mock.patch.object(mails, 'execute_email_send') as mock_send_mail:
434434
resp = app.post_json_api(
435435
f'{url_draft_registrations}?embed=branched_from&embed=initiator',
436436
payload,

api_tests/institutions/views/test_institution_relationship_nodes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def test_email_sent_on_affiliation_addition(self, app, user, institution, node_w
378378
current_institution = InstitutionFactory()
379379
node_without_institution.affiliated_institutions.add(current_institution)
380380

381-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
381+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
382382
res = app.post_json_api(
383383
url_institution_nodes,
384384
{
@@ -398,7 +398,7 @@ def test_email_sent_on_affiliation_removal(self, app, admin, institution, node_p
398398
current_institution = InstitutionFactory()
399399
node_public.affiliated_institutions.add(current_institution)
400400

401-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
401+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
402402
res = app.delete_json_api(
403403
url_institution_nodes,
404404
{

api_tests/nodes/views/test_node_contributors_list.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ class TestNodeContributorCreateEmail(NodeCRUDTestCase):
12081208
def url_project_contribs(self, project_public):
12091209
return f'/{API_BASE}nodes/{project_public._id}/contributors/'
12101210

1211-
@mock.patch('framework.auth.views.mails.send_mail')
1211+
@mock.patch('framework.auth.views.mails.execute_email_send')
12121212
def test_add_contributor_no_email_if_false(
12131213
self, mock_mail, app, user, url_project_contribs
12141214
):
@@ -1223,7 +1223,7 @@ def test_add_contributor_no_email_if_false(
12231223
assert res.status_code == 201
12241224
assert mock_mail.call_count == 0
12251225

1226-
@mock.patch('framework.auth.views.mails.send_mail')
1226+
@mock.patch('framework.auth.views.mails.execute_email_send')
12271227
def test_add_contributor_sends_email(
12281228
self, mock_mail, app, user, user_two, url_project_contribs
12291229
):
@@ -1281,7 +1281,7 @@ def test_add_contributor_signal_preprint_email_disallowed(
12811281
== 'preprint is not a valid email preference.'
12821282
)
12831283

1284-
@mock.patch('framework.auth.views.mails.send_mail')
1284+
@mock.patch('framework.auth.views.mails.execute_email_send')
12851285
def test_add_unregistered_contributor_sends_email(
12861286
self, mock_mail, app, user, url_project_contribs
12871287
):
@@ -1329,7 +1329,7 @@ def test_add_unregistered_contributor_signal_preprint_email_disallowed(
13291329
== 'preprint is not a valid email preference.'
13301330
)
13311331

1332-
@mock.patch('framework.auth.views.mails.send_mail')
1332+
@mock.patch('framework.auth.views.mails.execute_email_send')
13331333
def test_add_contributor_invalid_send_email_param(
13341334
self, mock_mail, app, user, url_project_contribs
13351335
):
@@ -1347,7 +1347,7 @@ def test_add_contributor_invalid_send_email_param(
13471347
)
13481348
assert mock_mail.call_count == 0
13491349

1350-
@mock.patch('framework.auth.views.mails.send_mail')
1350+
@mock.patch('framework.auth.views.mails.execute_email_send')
13511351
def test_add_unregistered_contributor_without_email_no_email(
13521352
self, mock_mail, app, user, url_project_contribs
13531353
):

api_tests/nodes/views/test_node_forks_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ def test_send_email_success(
421421
self, app, user, public_project_url,
422422
fork_data_with_title, public_project):
423423

424-
with mock.patch.object(mails, 'send_mail', return_value=None) as mock_send_mail:
424+
with mock.patch.object(mails, 'execute_email_send', return_value=None) as mock_send_mail:
425425
res = app.post_json_api(
426426
public_project_url,
427427
fork_data_with_title,
@@ -440,7 +440,7 @@ def test_send_email_failed(
440440
fork_data_with_title, public_project):
441441

442442
with mock.patch.object(NodeForksSerializer, 'save', side_effect=Exception()):
443-
with mock.patch.object(mails, 'send_mail', return_value=None) as mock_send_mail:
443+
with mock.patch.object(mails, 'execute_email_send', return_value=None) as mock_send_mail:
444444
with pytest.raises(Exception):
445445
app.post_json_api(
446446
public_project_url,

api_tests/nodes/views/test_node_relationship_institutions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def test_user_with_institution_and_permissions(
206206
@mock.patch('website.mails.settings.USE_EMAIL', True)
207207
def test_user_with_institution_and_permissions_through_patch(self, app, user, institution_one, institution_two,
208208
node, node_institutions_url):
209-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
209+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
210210
res = app.patch_json_api(
211211
node_institutions_url,
212212
self.create_payload([institution_one, institution_two]),
@@ -237,7 +237,7 @@ def test_remove_institutions_with_affiliated_user(self, app, user, institution_o
237237
node.save()
238238
assert institution_one in node.affiliated_institutions.all()
239239

240-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
240+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
241241
res = app.put_json_api(
242242
node_institutions_url,
243243
{
@@ -262,7 +262,7 @@ def test_using_post_making_no_changes_returns_201(self, app, user, institution_o
262262
node.save()
263263
assert institution_one in node.affiliated_institutions.all()
264264

265-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
265+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
266266
res = app.post_json_api(
267267
node_institutions_url,
268268
self.create_payload([institution_one]),
@@ -297,7 +297,7 @@ def test_add_through_patch_one_inst_to_node_with_inst(
297297
assert institution_one in node.affiliated_institutions.all()
298298
assert institution_two not in node.affiliated_institutions.all()
299299

300-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
300+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
301301
res = app.patch_json_api(
302302
node_institutions_url,
303303
self.create_payload([institution_one, institution_two]),
@@ -324,7 +324,7 @@ def test_add_through_patch_one_inst_while_removing_other(
324324
assert institution_one in node.affiliated_institutions.all()
325325
assert institution_two not in node.affiliated_institutions.all()
326326

327-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
327+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
328328
res = app.patch_json_api(
329329
node_institutions_url,
330330
self.create_payload([institution_two]),
@@ -358,7 +358,7 @@ def test_add_one_inst_with_post_to_node_with_inst(
358358
assert institution_one in node.affiliated_institutions.all()
359359
assert institution_two not in node.affiliated_institutions.all()
360360

361-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
361+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
362362
res = app.post_json_api(
363363
node_institutions_url,
364364
self.create_payload([institution_two]),
@@ -388,7 +388,7 @@ def test_delete_existing_inst(self, app, user, institution_one, node, node_insti
388388
node.affiliated_institutions.add(institution_one)
389389
node.save()
390390

391-
with mock.patch('osf.models.mixins.mails.send_mail') as mocked_send_mail:
391+
with mock.patch('osf.models.mixins.mails.execute_email_send') as mocked_send_mail:
392392
res = app.delete_json_api(
393393
node_institutions_url,
394394
self.create_payload([institution_one]),

api_tests/preprints/views/test_preprint_contributors_list.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ class TestPreprintContributorCreateEmail(NodeCRUDTestCase):
13511351
def url_preprint_contribs(self, preprint_published):
13521352
return f'/{API_BASE}preprints/{preprint_published._id}/contributors/'
13531353

1354-
@mock.patch('framework.auth.views.mails.send_mail')
1354+
@mock.patch('framework.auth.views.mails.execute_email_send')
13551355
def test_add_contributor_no_email_if_false(
13561356
self, mock_mail, app, user, url_preprint_contribs):
13571357
url = f'{url_preprint_contribs}?send_email=false'
@@ -1368,7 +1368,7 @@ def test_add_contributor_no_email_if_false(
13681368
assert res.status_code == 201
13691369
assert mock_mail.call_count == 0
13701370

1371-
@mock.patch('framework.auth.views.mails.send_mail')
1371+
@mock.patch('framework.auth.views.mails.execute_email_send')
13721372
def test_add_contributor_needs_preprint_filter_to_send_email(
13731373
self, mock_mail, app, user, user_two,
13741374
url_preprint_contribs):
@@ -1419,7 +1419,7 @@ def test_add_contributor_signal_if_preprint(
14191419
assert mock_send.call_count == 1
14201420
assert 'preprint' == kwargs['email_template']
14211421

1422-
@mock.patch('framework.auth.views.mails.send_mail')
1422+
@mock.patch('framework.auth.views.mails.execute_email_send')
14231423
def test_add_unregistered_contributor_sends_email(
14241424
self, mock_mail, app, user, url_preprint_contribs):
14251425
url = f'{url_preprint_contribs}?send_email=preprint'
@@ -1455,7 +1455,7 @@ def test_add_unregistered_contributor_signal_if_preprint(
14551455
assert 'preprint' == kwargs['email_template']
14561456
assert mock_send.call_count == 1
14571457

1458-
@mock.patch('framework.auth.views.mails.send_mail')
1458+
@mock.patch('framework.auth.views.mails.execute_email_send')
14591459
def test_add_contributor_invalid_send_email_param(
14601460
self, mock_mail, app, user, url_preprint_contribs):
14611461
url = f'{url_preprint_contribs}?send_email=true'
@@ -1475,7 +1475,7 @@ def test_add_contributor_invalid_send_email_param(
14751475
assert res.json['errors'][0]['detail'] == 'true is not a valid email preference.'
14761476
assert mock_mail.call_count == 0
14771477

1478-
@mock.patch('framework.auth.views.mails.send_mail')
1478+
@mock.patch('framework.auth.views.mails.execute_email_send')
14791479
def test_add_unregistered_contributor_without_email_no_email(
14801480
self, mock_mail, app, user, url_preprint_contribs):
14811481
url = f'{url_preprint_contribs}?send_email=preprint'
@@ -1494,7 +1494,7 @@ def test_add_unregistered_contributor_without_email_no_email(
14941494
assert res.status_code == 201
14951495
assert mock_mail.call_count == 0
14961496

1497-
@mock.patch('framework.auth.views.mails.send_mail')
1497+
@mock.patch('framework.auth.views.mails.execute_email_send')
14981498
@mock.patch('osf.models.preprint.update_or_enqueue_on_preprint_updated')
14991499
def test_publishing_preprint_sends_emails_to_contributors(
15001500
self, mock_update, mock_mail, app, user, url_preprint_contribs, preprint_unpublished):
@@ -1535,7 +1535,7 @@ def test_contributor_added_signal_not_specified(
15351535
assert 'preprint' == kwargs['email_template']
15361536
assert mock_send.call_count == 1
15371537

1538-
@mock.patch('framework.auth.views.mails.send_mail')
1538+
@mock.patch('framework.auth.views.mails.execute_email_send')
15391539
def test_contributor_added_not_sent_if_unpublished(
15401540
self, mock_mail, app, user, preprint_unpublished):
15411541
url = f'/{API_BASE}preprints/{preprint_unpublished._id}/contributors/?send_email=preprint'

0 commit comments

Comments
 (0)