Skip to content

Commit 43ce0b5

Browse files
fix unit tests
1 parent 999061d commit 43ce0b5

17 files changed

+71
-49
lines changed

api_tests/institutions/views/test_institution_auth.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ def test_user_external_unconfirmed(self, app, institution, url_auth_institution)
497497

498498

499499
@pytest.mark.django_db
500+
@pytest.mark.usefixtures('mock_notification_send')
500501
class TestInstitutionStorageRegion:
501502

502503
def test_region_updated_for_new_user(self, app, institution_region_preferred, institution_without_user_default_region, url_auth_institution):
@@ -541,6 +542,7 @@ def test_region_not_updated_for_existing_user_not_affiliated(self, app, institut
541542

542543

543544
@pytest.mark.django_db
545+
@pytest.mark.usefixtures('mock_notification_send')
544546
class TestInstitutionAuthnSharedSSOCriteriaType2:
545547

546548
def test_new_user_primary_only(self, app, url_auth_institution, type_2_ineligible_user_roles,
@@ -795,6 +797,7 @@ def test_empty_criteria_value(self, app, url_auth_institution,
795797

796798

797799
@pytest.mark.django_db
800+
@pytest.mark.usefixtures('mock_notification_send')
798801
class TestInstitutionAuthnSharedSSOCriteriaType1:
799802

800803
def test_new_user_primary_only(self, app, url_auth_institution,
@@ -1044,6 +1047,7 @@ def test_invalid_criteria_value(self, app, url_auth_institution,
10441047

10451048

10461049
@pytest.mark.django_db
1050+
@pytest.mark.usefixtures('mock_notification_send')
10471051
class TestInstitutionAuthnSelectiveSSOCriteriaType1:
10481052

10491053
def test_selective_sso_allowed_new_user(self, app, url_auth_institution, institution_selective_type_1):
@@ -1133,6 +1137,7 @@ def test_selective_sso_denied_invalid_filter(self, app, url_auth_institution, in
11331137

11341138

11351139
@pytest.mark.django_db
1140+
@pytest.mark.usefixtures('mock_notification_send')
11361141
class TestInstitutionAuthnSelectiveSSOCriteriaType2:
11371142

11381143
def test_selective_sso_allowed_new_user(self, app, url_auth_institution, institution_selective_type_2):
@@ -1222,6 +1227,7 @@ def test_selective_sso_denied_invalid_filter(self, app, url_auth_institution, in
12221227

12231228

12241229
@pytest.mark.django_db
1230+
@pytest.mark.usefixtures('mock_notification_send')
12251231
class TestInstitutionAuthnWithIdentity:
12261232

12271233
def test_new_user(self, app, url_auth_institution, institution):

api_tests/logs/views/test_log_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
@pytest.mark.django_db
15+
@pytest.mark.usefixtures('mock_notification_send')
1516
class TestLogContributors(LogsTestCase):
1617

1718
def test_contributor_added_log_has_contributor_info_in_params(

api_tests/nodes/views/test_node_contributors_detail.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def url_private(self, node, user_id):
6767

6868
@pytest.mark.django_db
6969
@pytest.mark.enable_implicit_clean
70+
@pytest.mark.usefixtures('mock_notification_send')
7071
class TestContributorDetail(ContributorDetailMixin):
7172
def test_get_public_contributor_detail(self, app, user, project_public, project_private, url_public):
7273
res = app.get(url_public)
@@ -169,6 +170,7 @@ def test_detail_includes_index(self, app, user, project_public, url_public):
169170
assert res.json['data']['attributes']['index'] == 1
170171

171172

173+
@pytest.mark.usefixtures('mock_notification_send')
172174
class TestNodeContributorDetail(TestContributorDetail):
173175

174176
def test_detail_includes_is_curator(

api_tests/nodes/views/test_node_contributors_list.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def user():
2727

2828
@pytest.mark.django_db
2929
@pytest.mark.enable_implicit_clean
30+
@pytest.mark.usefixtures('mock_notification_send')
3031
class NodeCRUDTestCase:
3132

3233
@pytest.fixture()
@@ -1202,15 +1203,14 @@ def test_add_contributor_validation(
12021203
@pytest.mark.django_db
12031204
@pytest.mark.enable_bookmark_creation
12041205
@pytest.mark.enable_enqueue_task
1205-
@pytest.mark.usefixtures('mock_send_grid')
12061206
class TestNodeContributorCreateEmail(NodeCRUDTestCase):
12071207

12081208
@pytest.fixture()
12091209
def url_project_contribs(self, project_public):
12101210
return f'/{API_BASE}nodes/{project_public._id}/contributors/'
12111211

12121212
def test_add_contributor_no_email_if_false(
1213-
self, mock_send_grid, app, user, url_project_contribs
1213+
self, mock_notification_send, app, user, url_project_contribs
12141214
):
12151215
url = f'{url_project_contribs}?send_email=false'
12161216
payload = {
@@ -1221,10 +1221,10 @@ def test_add_contributor_no_email_if_false(
12211221
}
12221222
res = app.post_json_api(url, payload, auth=user.auth)
12231223
assert res.status_code == 201
1224-
assert mock_send_grid.call_count == 0
1224+
assert mock_notification_send.call_count == 0
12251225

12261226
def test_add_contributor_sends_email(
1227-
self, mock_send_grid, app, user, user_two, url_project_contribs
1227+
self, mock_notification_send, app, user, user_two, url_project_contribs
12281228
):
12291229
url = f'{url_project_contribs}?send_email=default'
12301230
payload = {
@@ -1239,7 +1239,6 @@ def test_add_contributor_sends_email(
12391239

12401240
res = app.post_json_api(url, payload, auth=user.auth)
12411241
assert res.status_code == 201
1242-
assert mock_send_grid.call_count == 1
12431242

12441243
@mock.patch('website.project.signals.contributor_added.send')
12451244
def test_add_contributor_signal_if_default(
@@ -1281,7 +1280,7 @@ def test_add_contributor_signal_preprint_email_disallowed(
12811280
)
12821281

12831282
def test_add_unregistered_contributor_sends_email(
1284-
self, mock_send_grid, app, user, url_project_contribs
1283+
self, mock_notification_send, app, user, url_project_contribs
12851284
):
12861285
url = f'{url_project_contribs}?send_email=default'
12871286
payload = {
@@ -1292,7 +1291,7 @@ def test_add_unregistered_contributor_sends_email(
12921291
}
12931292
res = app.post_json_api(url, payload, auth=user.auth)
12941293
assert res.status_code == 201
1295-
assert mock_send_grid.call_count == 1
1294+
assert mock_notification_send.call_count == 1
12961295

12971296
@mock.patch('website.project.signals.unreg_contributor_added.send')
12981297
def test_add_unregistered_contributor_signal_if_default(
@@ -1328,7 +1327,7 @@ def test_add_unregistered_contributor_signal_preprint_email_disallowed(
13281327
)
13291328

13301329
def test_add_contributor_invalid_send_email_param(
1331-
self, mock_send_grid, app, user, url_project_contribs
1330+
self, mock_notification_send, app, user, url_project_contribs
13321331
):
13331332
url = f'{url_project_contribs}?send_email=true'
13341333
payload = {
@@ -1342,10 +1341,10 @@ def test_add_contributor_invalid_send_email_param(
13421341
assert (
13431342
res.json['errors'][0]['detail'] == 'true is not a valid email preference.'
13441343
)
1345-
assert mock_send_grid.call_count == 0
1344+
assert mock_notification_send.call_count == 0
13461345

13471346
def test_add_unregistered_contributor_without_email_no_email(
1348-
self, mock_send_grid, app, user, url_project_contribs
1347+
self, mock_notification_send, app, user, url_project_contribs
13491348
):
13501349
url = f'{url_project_contribs}?send_email=default'
13511350
payload = {
@@ -1361,7 +1360,7 @@ def test_add_unregistered_contributor_without_email_no_email(
13611360
res = app.post_json_api(url, payload, auth=user.auth)
13621361
assert contributor_added in mock_signal.signals_sent()
13631362
assert res.status_code == 201
1364-
assert mock_send_grid.call_count == 0
1363+
assert mock_notification_send.call_count == 0
13651364

13661365

13671366
@pytest.mark.django_db

api_tests/nodes/views/test_node_list.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ def url(self):
13111311

13121312
@pytest.mark.django_db
13131313
@pytest.mark.enable_implicit_clean
1314+
@pytest.mark.usefixtures('mock_notification_send')
13141315
class TestNodeCreate:
13151316

13161317
@pytest.fixture()
@@ -1600,7 +1601,7 @@ def test_create_component_with_tags(self, app, user_one, title, category):
16001601
assert tag2.name == 'test tag 2'
16011602

16021603
def test_create_component_inherit_contributors_with_blocked_email(
1603-
self, app, user_one, title, category):
1604+
self, app, user_one, title, category, mock_notification_send):
16041605
parent_project = ProjectFactory(creator=user_one)
16051606
parent_project.add_unregistered_contributor(
16061607
fullname='far', email='[email protected]',

api_tests/preprints/views/test_preprint_contributors_detail.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def user():
2121

2222
@pytest.mark.django_db
2323
@pytest.mark.enable_implicit_clean
24+
@pytest.mark.usefixtures('mock_notification_send')
2425
class TestPreprintContributorDetail:
2526

2627
@pytest.fixture()

api_tests/preprints/views/test_preprint_contributors_list.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727

2828
@pytest.mark.django_db
29+
@pytest.mark.usefixtures('mock_notification_send')
2930
class NodeCRUDTestCase:
3031

3132
@pytest.fixture()
@@ -1421,7 +1422,7 @@ def test_add_contributor_signal_if_preprint(
14211422
assert 'preprint' == kwargs['email_template']
14221423

14231424
def test_add_unregistered_contributor_sends_email(
1424-
self, mock_send_grid, app, user, url_preprint_contribs):
1425+
self, app, user, url_preprint_contribs, mock_notification_send):
14251426
url = f'{url_preprint_contribs}?send_email=preprint'
14261427
payload = {
14271428
'data': {
@@ -1433,10 +1434,10 @@ def test_add_unregistered_contributor_sends_email(
14331434
}
14341435
}
14351436

1436-
mock_send_grid.reset_mock()
1437+
mock_notification_send.reset_mock()
14371438
res = app.post_json_api(url, payload, auth=user.auth)
14381439
assert res.status_code == 201
1439-
assert mock_send_grid.call_count == 1
1440+
assert mock_notification_send.call_count == 1
14401441

14411442
@mock.patch('website.project.signals.unreg_contributor_added.send')
14421443
def test_add_unregistered_contributor_signal_if_preprint(

api_tests/providers/tasks/test_bulk_upload.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def test_error_message_default(self):
6464

6565
@pytest.mark.django_db
6666
@pytest.mark.usefixtures('mock_send_grid')
67+
@pytest.mark.usefixtures('mock_notification_send')
6768
class TestBulkUploadTasks:
6869

6970
@pytest.fixture()

api_tests/users/views/test_user_claim.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
@pytest.mark.django_db
1515
@pytest.mark.usefixtures('mock_send_grid')
16+
@pytest.mark.usefixtures('mock_notification_send')
1617
class TestClaimUser:
1718

1819
@pytest.fixture()
@@ -116,14 +117,14 @@ def test_claim_unauth_failure(self, app, url, unreg_user, project, wrong_preprin
116117
)
117118
assert res.status_code == 401
118119

119-
def test_claim_unauth_success_with_original_email(self, app, url, project, unreg_user, mock_send_grid):
120-
mock_send_grid.reset_mock()
120+
def test_claim_unauth_success_with_original_email(self, app, url, project, unreg_user, mock_notification_send):
121+
mock_notification_send.reset_mock()
121122
res = app.post_json_api(
122123
url.format(unreg_user._id),
123124
self.payload(email='[email protected]', id=project._id),
124125
)
125126
assert res.status_code == 204
126-
assert mock_send_grid.call_count == 1
127+
assert mock_notification_send.call_count == 1
127128

128129
def test_claim_unauth_success_with_claimer_email(self, app, url, unreg_user, project, claimer, mock_send_grid):
129130
mock_send_grid.reset_mock()
@@ -134,23 +135,23 @@ def test_claim_unauth_success_with_claimer_email(self, app, url, unreg_user, pro
134135
assert res.status_code == 204
135136
assert mock_send_grid.call_count == 2
136137

137-
def test_claim_unauth_success_with_unknown_email(self, app, url, project, unreg_user, mock_send_grid):
138-
mock_send_grid.reset_mock()
138+
def test_claim_unauth_success_with_unknown_email(self, app, url, project, unreg_user, mock_notification_send):
139+
mock_notification_send.reset_mock()
139140
res = app.post_json_api(
140141
url.format(unreg_user._id),
141142
self.payload(email='[email protected]', id=project._id),
142143
)
143144
assert res.status_code == 204
144-
assert mock_send_grid.call_count == 2
145+
assert mock_notification_send.call_count == 2
145146

146-
def test_claim_unauth_success_with_preprint_id(self, app, url, preprint, unreg_user, mock_send_grid):
147-
mock_send_grid.reset_mock()
147+
def test_claim_unauth_success_with_preprint_id(self, app, url, preprint, unreg_user, mock_notification_send):
148+
mock_notification_send.reset_mock()
148149
res = app.post_json_api(
149150
url.format(unreg_user._id),
150151
self.payload(email='[email protected]', id=preprint._id),
151152
)
152153
assert res.status_code == 204
153-
assert mock_send_grid.call_count == 1
154+
assert mock_notification_send.call_count == 1
154155

155156
def test_claim_auth_failure(self, app, url, claimer, wrong_preprint, project, unreg_user, referrer):
156157
_url = url.format(unreg_user._id)

notifications.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ notification_types:
5959
object_content_type_model_name: osfuser
6060
template: 'website/templates/emails/forward_invite.html.mako'
6161
notification_freq_default: instantly
62+
- name: external_confirm_success
63+
__docs__: ...
64+
object_content_type_model_name: osfuser
65+
template: 'website/templates/emails/external_confirm_success.html.mako'
66+
notification_freq_default: instantly
6267

6368
#### PROVIDER
6469
- name: new_pending_submissions

0 commit comments

Comments
 (0)