1818from website import settings
1919from website .preprints .tasks import on_preprint_updated
2020from ._utils import expect_preprint_ingest_request
21+ from tests .utils import capture_notifications
2122
2223
2324@pytest .mark .django_db
@@ -72,54 +73,59 @@ def test_save_unpublished_not_called(self, mock_share_responses, preprint):
7273 preprint .save ()
7374
7475 def test_save_published_called (self , mock_share_responses , preprint , user , auth ):
75- with expect_preprint_ingest_request (mock_share_responses , preprint ):
76- preprint .set_published (True , auth = auth , save = True )
76+ with capture_notifications ():
77+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
78+ preprint .set_published (True , auth = auth , save = True )
7779
7880 # This covers an edge case where a preprint is forced back to unpublished
7981 # that it sends the information back to share
8082 def test_save_unpublished_called_forced (self , mock_share_responses , auth , preprint ):
81- with expect_preprint_ingest_request (mock_share_responses , preprint ):
82- preprint .set_published (True , auth = auth , save = True )
83- with expect_preprint_ingest_request (mock_share_responses , preprint , delete = True ):
84- preprint .is_published = False
85- preprint .save (** {'force_update' : True })
83+ with capture_notifications ():
84+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
85+ preprint .set_published (True , auth = auth , save = True )
86+ with expect_preprint_ingest_request (mock_share_responses , preprint , delete = True ):
87+ preprint .is_published = False
88+ preprint .save (** {'force_update' : True })
8689
8790 def test_save_published_subject_change_called (self , mock_share_responses , auth , preprint , subject , subject_two ):
88- preprint .set_published (True , auth = auth , save = True )
89- with expect_preprint_ingest_request (mock_share_responses , preprint ):
90- preprint .set_subjects ([[subject_two ._id ]], auth = auth )
91+ with capture_notifications ():
92+ preprint .set_published (True , auth = auth , save = True )
93+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
94+ preprint .set_subjects ([[subject_two ._id ]], auth = auth )
9195
9296 def test_save_unpublished_subject_change_not_called (self , mock_share_responses , auth , preprint , subject_two ):
9397 with expect_preprint_ingest_request (mock_share_responses , preprint , delete = True ):
9498 preprint .set_subjects ([[subject_two ._id ]], auth = auth )
9599
96100 def test_send_to_share_is_true (self , mock_share_responses , auth , preprint ):
97- preprint .set_published (True , auth = auth , save = True )
98- with expect_preprint_ingest_request (mock_share_responses , preprint ):
99- on_preprint_updated (preprint ._id , saved_fields = ['title' ])
101+ with capture_notifications ():
102+ preprint .set_published (True , auth = auth , save = True )
103+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
104+ on_preprint_updated (preprint ._id , saved_fields = ['title' ])
100105
101106 def test_preprint_contributor_changes_updates_preprints_share (self , mock_share_responses , user , auth ):
102- preprint = PreprintFactory (is_published = True , creator = user )
103- preprint .set_published (True , auth = auth , save = True )
104- user2 = AuthUserFactory ()
107+ with capture_notifications ():
108+ preprint = PreprintFactory (is_published = True , creator = user )
109+ preprint .set_published (True , auth = auth , save = True )
110+ user2 = AuthUserFactory ()
105111
106- with expect_preprint_ingest_request (mock_share_responses , preprint ):
107- preprint .add_contributor (contributor = user2 , auth = auth , save = True )
112+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
113+ preprint .add_contributor (contributor = user2 , auth = auth , save = True )
108114
109- with expect_preprint_ingest_request (mock_share_responses , preprint ):
110- preprint .move_contributor (contributor = user , index = 0 , auth = auth , save = True )
115+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
116+ preprint .move_contributor (contributor = user , index = 0 , auth = auth , save = True )
111117
112- data = [{'id' : user ._id , 'permissions' : ADMIN , 'visible' : True },
113- {'id' : user2 ._id , 'permissions' : WRITE , 'visible' : False }]
118+ data = [{'id' : user ._id , 'permissions' : ADMIN , 'visible' : True },
119+ {'id' : user2 ._id , 'permissions' : WRITE , 'visible' : False }]
114120
115- with expect_preprint_ingest_request (mock_share_responses , preprint ):
116- preprint .manage_contributors (data , auth = auth , save = True )
121+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
122+ preprint .manage_contributors (data , auth = auth , save = True )
117123
118- with expect_preprint_ingest_request (mock_share_responses , preprint ):
119- preprint .update_contributor (user2 , READ , True , auth = auth , save = True )
124+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
125+ preprint .update_contributor (user2 , READ , True , auth = auth , save = True )
120126
121- with expect_preprint_ingest_request (mock_share_responses , preprint ):
122- preprint .remove_contributor (contributor = user2 , auth = auth )
127+ with expect_preprint_ingest_request (mock_share_responses , preprint ):
128+ preprint .remove_contributor (contributor = user2 , auth = auth )
123129
124130 @pytest .mark .skip ('Synchronous retries not supported if celery >=5.0' )
125131 def test_call_async_update_on_500_failure (self , mock_share_responses , preprint , auth ):
@@ -129,10 +135,11 @@ def test_call_async_update_on_500_failure(self, mock_share_responses, preprint,
129135 preprint .update_search ()
130136
131137 def test_no_call_async_update_on_400_failure (self , mock_share_responses , preprint , auth ):
132- mock_share_responses .replace (responses .POST , shtrove_ingest_url (), status = 400 )
133- preprint .set_published (True , auth = auth , save = True )
134- with expect_preprint_ingest_request (mock_share_responses , preprint , count = 1 , error_response = True ):
135- preprint .update_search ()
138+ with capture_notifications ():
139+ mock_share_responses .replace (responses .POST , shtrove_ingest_url (), status = 400 )
140+ preprint .set_published (True , auth = auth , save = True )
141+ with expect_preprint_ingest_request (mock_share_responses , preprint , count = 1 , error_response = True ):
142+ preprint .update_search ()
136143
137144 def test_delete_from_share (self , mock_share_responses ):
138145 preprint = PreprintFactory ()
0 commit comments