Skip to content

Commit 8d450fc

Browse files
fix contibutor added unit tests p1
1 parent 5757d19 commit 8d450fc

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

api/nodes/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ def create(self, validated_data):
12711271

12721272
try:
12731273
contributor_dict = {
1274-
'auth': auth, 'user_id': user_id, 'email': email, 'full_name': full_name,
1274+
'auth': auth, 'user_id': user_id, 'email': email, 'full_name': full_name, 'notification_type': False if email_pref == 'false' else None,
12751275
'bibliographic': bibliographic, 'index': index, 'permissions': permissions,
12761276
}
12771277
contributor_obj = resource.add_contributor_registered_or_not(**contributor_dict)

api_tests/nodes/views/test_node_contributors_list.py

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def test_return_public_contributor_list_logged_out(
186186
):
187187
project_public.add_contributor(
188188
user_two,
189-
save=True
189+
save=True,
190+
notification_type=False
190191
)
191192

192193
res = app.get(url_public)
@@ -203,7 +204,7 @@ def test_return_public_contributor_list_logged_out(
203204
def test_return_private_contributor_list_logged_in_contributor(
204205
self, app, user, user_two, project_private, url_private, make_contrib_id
205206
):
206-
project_private.add_contributor(user_two)
207+
project_private.add_contributor(user_two, notification_type=False)
207208
project_private.save()
208209

209210
res = app.get(url_private, auth=user.auth)
@@ -278,6 +279,7 @@ def test_total_bibliographic_contributor_count_returned_in_metadata(
278279
non_bibliographic_user,
279280
visible=False,
280281
auth=Auth(project_public.creator),
282+
notification_type=False
281283
)
282284
project_public.save()
283285
res = app.get(url_public, auth=user_two.auth)
@@ -297,7 +299,7 @@ def test_unregistered_contributor_field_is_null_if_account_claimed(self, app, us
297299
def test_unregistered_contributors_show_up_as_name_associated_with_project(self, app, user):
298300
project = ProjectFactory(creator=user, is_public=True)
299301
project.add_unregistered_contributor(
300-
'Robert Jackson', '[email protected]', auth=Auth(user)
302+
'Robert Jackson', '[email protected]', auth=Auth(user), notification_type=False
301303
)
302304
url = f'/{API_BASE}nodes/{project._id}/contributors/'
303305
res = app.get(url, auth=user.auth, expect_errors=True)
@@ -314,7 +316,7 @@ def test_unregistered_contributors_show_up_as_name_associated_with_project(self,
314316

315317
project_two = ProjectFactory(creator=user, is_public=True)
316318
project_two.add_unregistered_contributor(
317-
'Bob Jackson', '[email protected]', auth=Auth(user)
319+
'Bob Jackson', '[email protected]', auth=Auth(user), notification_type=False
318320
)
319321
url = f'/{API_BASE}nodes/{project_two._id}/contributors/'
320322
res = app.get(url, auth=user.auth, expect_errors=True)
@@ -331,7 +333,7 @@ def test_contributors_order_is_the_same_over_multiple_requests(
331333
self, app, user, project_public, url_public
332334
):
333335
project_public.add_unregistered_contributor(
334-
'Robert Jackson', '[email protected]', auth=Auth(user)
336+
'Robert Jackson', '[email protected]', auth=Auth(user), notification_type=False
335337
)
336338

337339
for i in range(0, 10):
@@ -341,7 +343,7 @@ def test_contributors_order_is_the_same_over_multiple_requests(
341343
else:
342344
visible = False
343345
project_public.add_contributor(
344-
new_user, visible=visible, auth=Auth(project_public.creator), save=True
346+
new_user, visible=visible, auth=Auth(project_public.creator), save=True, notification_type=False
345347
)
346348
req_one = app.get(f'{url_public}?page=2', auth=Auth(project_public.creator))
347349
req_two = app.get(f'{url_public}?page=2', auth=Auth(project_public.creator))
@@ -634,7 +636,7 @@ def test_adds_contributor_public_project_non_admin(
634636
url_public,
635637
):
636638
project_public.add_contributor(
637-
user_two, permissions=permissions.WRITE, auth=Auth(user), save=True
639+
user_two, permissions=permissions.WRITE, auth=Auth(user), save=True, notification_type=False
638640
)
639641
res = app.post_json_api(
640642
url_public, data_user_three, auth=user_two.auth, expect_errors=True
@@ -805,7 +807,7 @@ def test_adds_none_permission_contributor_private_project_admin_uses_default_per
805807
def test_adds_already_existing_contributor_private_project_admin(
806808
self, app, user, user_two, project_private, data_user_two, url_private
807809
):
808-
project_private.add_contributor(user_two, auth=Auth(user), save=True)
810+
project_private.add_contributor(user_two, auth=Auth(user), save=True, notification_type=False)
809811
project_private.reload()
810812

811813
res = app.post_json_api(
@@ -840,7 +842,7 @@ def test_adds_contributor_private_project_non_admin(
840842
url_private,
841843
):
842844
project_private.add_contributor(
843-
user_two, permissions=permissions.WRITE, auth=Auth(user)
845+
user_two, permissions=permissions.WRITE, auth=Auth(user), notification_type=False
844846
)
845847
res = app.post_json_api(
846848
url_private, data_user_three, auth=user_two.auth, expect_errors=True
@@ -966,7 +968,7 @@ def test_add_unregistered_contributor_already_contributor(
966968
):
967969
name, email = fake.name(), fake_email()
968970
project_public.add_unregistered_contributor(
969-
auth=Auth(user), fullname=name, email=email
971+
auth=Auth(user), fullname=name, email=email, notification_type=False
970972
)
971973
payload = {
972974
'data': {
@@ -1038,9 +1040,9 @@ def test_add_contributor_set_index_out_of_range(
10381040
self, app, user, user_two, project_public, url_public
10391041
):
10401042
user_contrib_one = UserFactory()
1041-
project_public.add_contributor(user_contrib_one, save=True)
1043+
project_public.add_contributor(user_contrib_one, save=True, notification_type=False)
10421044
user_contrib_two = UserFactory()
1043-
project_public.add_contributor(user_contrib_two, save=True)
1045+
project_public.add_contributor(user_contrib_two, save=True, notification_type=False)
10441046
payload = {
10451047
'data': {
10461048
'type': 'contributors',
@@ -1061,9 +1063,9 @@ def test_add_contributor_set_index_first(
10611063
self, app, user, user_two, project_public, url_public
10621064
):
10631065
user_contrib_one = UserFactory()
1064-
project_public.add_contributor(user_contrib_one, save=True)
1066+
project_public.add_contributor(user_contrib_one, save=True, notification_type=False)
10651067
user_contrib_two = UserFactory()
1066-
project_public.add_contributor(user_contrib_two, save=True)
1068+
project_public.add_contributor(user_contrib_two, save=True, notification_type=False)
10671069
payload = {
10681070
'data': {
10691071
'type': 'contributors',
@@ -1084,9 +1086,9 @@ def test_add_contributor_set_index_last(
10841086
self, app, user, user_two, project_public, url_public
10851087
):
10861088
user_contrib_one = UserFactory()
1087-
project_public.add_contributor(user_contrib_one, save=True)
1089+
project_public.add_contributor(user_contrib_one, save=True, notification_type=False)
10881090
user_contrib_two = UserFactory()
1089-
project_public.add_contributor(user_contrib_two, save=True)
1091+
project_public.add_contributor(user_contrib_two, save=True, notification_type=False)
10901092
payload = {
10911093
'data': {
10921094
'type': 'contributors',
@@ -1311,7 +1313,7 @@ def test_add_unregistered_contributor_sends_email(
13111313
)
13121314
assert res.status_code == 201
13131315
assert len(notifications['emits']) == 1
1314-
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
1316+
assert notifications['emits'][0]['type'] == NotificationType.Type.USER_INVITE_DEFAULT
13151317

13161318
@mock.patch('website.project.signals.unreg_contributor_added.send')
13171319
def test_add_unregistered_contributor_signal_if_default(
@@ -1333,7 +1335,7 @@ def test_add_unregistered_contributor_signal_if_default(
13331335
)
13341336
assert res.status_code == 201
13351337
assert len(notifications['emits']) == 1
1336-
assert notifications['emits'][0]['type'] == NotificationType.Type.NODE_CONTRIBUTOR_ADDED_DEFAULT
1338+
assert notifications['emits'][0]['type'] == NotificationType.Type.USER_INVITE_DEFAULT
13371339

13381340
def test_add_unregistered_contributor_signal_preprint_email_disallowed(
13391341
self, app, user, url_project_contribs
@@ -1380,7 +1382,8 @@ def test_add_unregistered_contributor_without_email_no_email(self, app, user, ur
13801382
}
13811383

13821384
with capture_signals() as mock_signal:
1383-
res = app.post_json_api(url, payload, auth=user.auth)
1385+
with capture_notifications():
1386+
res = app.post_json_api(url, payload, auth=user.auth)
13841387
assert contributor_added in mock_signal.signals_sent()
13851388
assert res.status_code == 201
13861389

@@ -1426,7 +1429,7 @@ def test_node_contributor_bulk_create_contributor_exists(
14261429
self, app, user, user_two, project_public, payload_one, payload_two, url_public
14271430
):
14281431
project_public.add_contributor(
1429-
user_two, permissions=permissions.READ, visible=True, save=True
1432+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
14301433
)
14311434
res = app.post_json_api(
14321435
url_public,
@@ -1498,7 +1501,7 @@ def test_node_contributor_bulk_create_errors(
14981501

14991502
# test_node_contributor_bulk_create_logged_in_read_only_contrib_private_project
15001503
project_private.add_contributor(
1501-
user_two, permissions=permissions.READ, save=True
1504+
user_two, permissions=permissions.READ, save=True, notification_type=False
15021505
)
15031506
res = app.post_json_api(
15041507
url_private,
@@ -1638,10 +1641,10 @@ def project_public(self, user, user_two, user_three, title, description, categor
16381641
creator=user,
16391642
)
16401643
project_public.add_contributor(
1641-
user_two, permissions=permissions.READ, visible=True, save=True
1644+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
16421645
)
16431646
project_public.add_contributor(
1644-
user_three, permissions=permissions.READ, visible=True, save=True
1647+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
16451648
)
16461649
return project_public
16471650

@@ -1655,10 +1658,10 @@ def project_private(self, user, user_two, user_three, title, description, catego
16551658
creator=user,
16561659
)
16571660
project_private.add_contributor(
1658-
user_two, permissions=permissions.READ, visible=True, save=True
1661+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
16591662
)
16601663
project_private.add_contributor(
1661-
user_three, permissions=permissions.READ, visible=True, save=True
1664+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
16621665
)
16631666
return project_private
16641667

@@ -2091,10 +2094,10 @@ def project_public(self, user, user_two, user_three, title, description, categor
20912094
creator=user,
20922095
)
20932096
project_public.add_contributor(
2094-
user_two, permissions=permissions.READ, visible=True, save=True
2097+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
20952098
)
20962099
project_public.add_contributor(
2097-
user_three, permissions=permissions.READ, visible=True, save=True
2100+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
20982101
)
20992102
return project_public
21002103

@@ -2108,10 +2111,10 @@ def project_private(self, user, user_two, user_three, title, description, catego
21082111
creator=user,
21092112
)
21102113
project_private.add_contributor(
2111-
user_two, permissions=permissions.READ, visible=True, save=True
2114+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
21122115
)
21132116
project_private.add_contributor(
2114-
user_three, permissions=permissions.READ, visible=True, save=True
2117+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
21152118
)
21162119
return project_private
21172120

@@ -2466,10 +2469,10 @@ def project_public(self, user, user_two, user_three, title, description, categor
24662469
creator=user,
24672470
)
24682471
project_public.add_contributor(
2469-
user_two, permissions=permissions.READ, visible=True, save=True
2472+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
24702473
)
24712474
project_public.add_contributor(
2472-
user_three, permissions=permissions.READ, visible=True, save=True
2475+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
24732476
)
24742477
return project_public
24752478

@@ -2483,10 +2486,10 @@ def project_private(self, user, user_two, user_three, title, description, catego
24832486
creator=user,
24842487
)
24852488
project_private.add_contributor(
2486-
user_two, permissions=permissions.READ, visible=True, save=True
2489+
user_two, permissions=permissions.READ, visible=True, save=True, notification_type=False
24872490
)
24882491
project_private.add_contributor(
2489-
user_three, permissions=permissions.READ, visible=True, save=True
2492+
user_three, permissions=permissions.READ, visible=True, save=True, notification_type=False
24902493
)
24912494
return project_private
24922495

@@ -2842,8 +2845,8 @@ def test_filtering(self, app, user, url, project):
28422845

28432846
user_two = AuthUserFactory()
28442847
user_three = AuthUserFactory()
2845-
project.add_contributor(user_two, permissions.WRITE)
2846-
project.add_contributor(user_three, permissions.READ, visible=False)
2848+
project.add_contributor(user_two, permissions.WRITE, notification_type=False)
2849+
project.add_contributor(user_three, permissions.READ, visible=False, notification_type=False)
28472850

28482851
# test_filtering_node_with_only_bibliographic_contributors
28492852
# no filter
@@ -2877,7 +2880,7 @@ def test_filtering_node_with_non_bibliographic_contributor(
28772880
self, app, user, project, url
28782881
):
28792882
non_bibliographic_contrib = UserFactory()
2880-
project.add_contributor(non_bibliographic_contrib, visible=False)
2883+
project.add_contributor(non_bibliographic_contrib, visible=False, notification_type=False)
28812884
project.save()
28822885

28832886
# no filter
@@ -2901,8 +2904,8 @@ def test_filtering_permission_field_admin(self, app, user, project, url):
29012904

29022905
user_two = AuthUserFactory()
29032906
user_three = AuthUserFactory()
2904-
project.add_contributor(user_two, permissions.WRITE)
2905-
project.add_contributor(user_three, permissions.READ, visible=False)
2907+
project.add_contributor(user_two, permissions.WRITE, notification_type=False)
2908+
project.add_contributor(user_three, permissions.READ, visible=False, notification_type=False)
29062909

29072910
# test_filtering_permission_field_admin
29082911
filter_url = f'{url}?filter[permission]=admin'
@@ -2922,8 +2925,8 @@ def test_filtering_permission_field_write(self, app, user, project, url):
29222925

29232926
user_two = AuthUserFactory()
29242927
user_three = AuthUserFactory()
2925-
project.add_contributor(user_two, permissions.WRITE)
2926-
project.add_contributor(user_three, permissions.READ, visible=False)
2928+
project.add_contributor(user_two, permissions.WRITE, notification_type=False)
2929+
project.add_contributor(user_three, permissions.READ, visible=False, notification_type=False)
29272930

29282931
# test_filtering_permission_field_write
29292932
filter_url = f'{url}?filter[permission]=write'
@@ -2942,8 +2945,8 @@ def test_filtering_permission_field_read(self, app, user, project, url):
29422945

29432946
user_two = AuthUserFactory()
29442947
user_three = AuthUserFactory()
2945-
project.add_contributor(user_two, permissions.WRITE)
2946-
project.add_contributor(user_three, permissions.READ, visible=False)
2948+
project.add_contributor(user_two, permissions.WRITE, notification_type=False)
2949+
project.add_contributor(user_three, permissions.READ, visible=False, notification_type=False)
29472950

29482951
# test_filtering_permission_field_read
29492952
filter_url = f'{url}?filter[permission]=read'

0 commit comments

Comments
 (0)