Skip to content

Commit ae2f742

Browse files
fix unit tests
1 parent a7c675d commit ae2f742

File tree

5 files changed

+10
-23
lines changed

5 files changed

+10
-23
lines changed

api_tests/draft_registrations/views/test_draft_registration_contributor_list.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def test_add_unregistered_contributor_sends_email(self, app, user, url_project_c
281281
)
282282
assert res.status_code == 201
283283
assert len(notifications['emits']) == 1
284-
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
284+
assert notifications['emits'][0]['type'] == NotificationType.Type.USER_INVITE_DRAFT_REGISTRATION
285285

286286
# Overrides TestNodeContributorCreateEmail
287287
def test_add_unregistered_contributor_signal_if_default(self, app, user, url_project_contribs):
@@ -300,7 +300,7 @@ def test_add_unregistered_contributor_signal_if_default(self, app, user, url_pro
300300
)
301301
assert res.status_code == 201
302302
assert len(notifications['emits']) == 1
303-
assert notifications['emits'][0]['type'] == NotificationType.Type.DRAFT_REGISTRATION_CONTRIBUTOR_ADDED_DEFAULT
303+
assert notifications['emits'][0]['type'] == NotificationType.Type.USER_INVITE_DRAFT_REGISTRATION
304304

305305
# Overrides TestNodeContributorCreateEmail
306306
def test_add_unregistered_contributor_without_email_no_email(self, app, user, url_project_contribs):

api_tests/nodes/views/test_node_list.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,8 +1660,7 @@ def test_create_component_inherit_contributors(
16601660
}
16611661
}
16621662
}
1663-
with capture_notifications():
1664-
res = app.post_json_api(url, component_data, auth=user_one.auth)
1663+
res = app.post_json_api(url, component_data, auth=user_one.auth)
16651664
assert res.status_code == 201
16661665
json_data = res.json['data']
16671666

api_tests/preprints/views/test_preprint_contributors_list.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ def test_add_unregistered_contributor_sends_email(
14631463
auth=user.auth
14641464
)
14651465
assert len(notifications['emits']) == 1
1466-
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1466+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT
14671467
assert res.status_code == 201
14681468

14691469
def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_preprint_contribs):
@@ -1483,7 +1483,7 @@ def test_add_unregistered_contributor_signal_if_preprint(self, app, user, url_pr
14831483
)
14841484
assert res.status_code == 201
14851485
assert len(notifications['emits']) == 1
1486-
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1486+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT
14871487

14881488
def test_add_contributor_invalid_send_email_param(self, app, user, url_preprint_contribs):
14891489
url = f'{url_preprint_contribs}?send_email=true'
@@ -1564,23 +1564,7 @@ def test_contributor_added_signal_not_specified(self, app, user, url_preprint_co
15641564
)
15651565
assert res.status_code == 201
15661566
assert len(notifications['emits']) == 1
1567-
assert notifications['emits'][0]['type'] == NotificationType.Type.PREPRINT_CONTRIBUTOR_ADDED_DEFAULT
1568-
1569-
def test_contributor_added_not_sent_if_unpublished(self, app, user, preprint_unpublished):
1570-
res = app.post_json_api(
1571-
f'/{API_BASE}preprints/{preprint_unpublished._id}/contributors/?send_email=preprint',
1572-
{
1573-
'data': {
1574-
'type': 'contributors',
1575-
'attributes': {
1576-
'full_name': 'Jalen Hurt',
1577-
'email': '[email protected]'
1578-
}
1579-
}
1580-
},
1581-
auth=user.auth
1582-
)
1583-
assert res.status_code == 201
1567+
assert notifications['emits'][0]['type'] == NotificationType.Type.PROVIDER_USER_INVITE_PREPRINT
15841568

15851569
@pytest.mark.django_db
15861570
class TestPreprintContributorBulkCreate(NodeCRUDTestCase):

osf/models/mixins.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,7 @@ def add_contributors(
14991499
auth=None,
15001500
log=True,
15011501
save=False,
1502+
notification_type=False,
15021503
):
15031504
"""Add multiple contributors
15041505
@@ -1520,6 +1521,7 @@ def add_contributors(
15201521
auth=auth,
15211522
log=False,
15221523
save=False,
1524+
notification_type=notification_type,
15231525
)
15241526
if log and contributors:
15251527
params = self.log_params

website/project/views/contributor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ def notify_added_contributor(resource, contributor, notification_type, auth=None
620620
"""
621621
if not notification_type:
622622
return
623+
if not contributor.email:
624+
return
623625

624626
logo = settings.OSF_LOGO
625627
if getattr(resource, 'has_linked_published_preprints', None):

0 commit comments

Comments
 (0)