@@ -38,6 +38,9 @@ def setUp(self):
38
38
self .output_file_name = 'fake_boa_script_results.txt'
39
39
self .job_id = '1a2b3c4d5e6f7g8'
40
40
41
+ from conftest import start_mock_send_grid
42
+ self .mock_send_grid = start_mock_send_grid (self )
43
+
41
44
def tearDown (self ):
42
45
super ().tearDown ()
43
46
@@ -52,9 +55,10 @@ def test_boa_error_code(self):
52
55
assert BoaErrorCode .FILE_TOO_LARGE_ERROR == 6
53
56
assert BoaErrorCode .JOB_TIME_OUT_ERROR == 7
54
57
58
+ @mock .patch ('website.mails.settings.USE_EMAIL' , True )
59
+ @mock .patch ('website.mails.settings.USE_CELERY' , False )
55
60
def test_handle_boa_error (self ):
56
- with mock .patch ('addons.boa.tasks.send_mail' , return_value = None ) as mock_send_mail , \
57
- mock .patch ('addons.boa.tasks.sentry.log_message' , return_value = None ) as mock_sentry_log_message , \
61
+ with mock .patch ('addons.boa.tasks.sentry.log_message' , return_value = None ) as mock_sentry_log_message , \
58
62
mock .patch ('addons.boa.tasks.logger.error' , return_value = None ) as mock_logger_error :
59
63
return_value = handle_boa_error (
60
64
self .error_message ,
@@ -68,24 +72,7 @@ def test_handle_boa_error(self):
68
72
output_file_name = self .output_file_name ,
69
73
job_id = self .job_id
70
74
)
71
- mock_send_mail .assert_called_with (
72
- to_addr = self .user_username ,
73
- mail = ADDONS_BOA_JOB_FAILURE ,
74
- fullname = self .user_fullname ,
75
- code = BoaErrorCode .UNKNOWN ,
76
- message = self .error_message ,
77
- query_file_name = self .query_file_name ,
78
- file_size = self .file_size ,
79
- max_file_size = boa_settings .MAX_SUBMISSION_SIZE ,
80
- query_file_full_path = self .file_full_path ,
81
- output_file_name = self .output_file_name ,
82
- job_id = self .job_id ,
83
- max_job_wait_hours = self .max_job_wait_hours ,
84
- project_url = self .project_url ,
85
- boa_job_list_url = boa_settings .BOA_JOB_LIST_URL ,
86
- boa_support_email = boa_settings .BOA_SUPPORT_EMAIL ,
87
- osf_support_email = osf_settings .OSF_SUPPORT_EMAIL ,
88
- )
75
+ self .mock_send_grid .assert_called ()
89
76
mock_sentry_log_message .assert_called_with (self .error_message , skip_session = True )
90
77
mock_logger_error .assert_called_with (self .error_message )
91
78
assert return_value == BoaErrorCode .UNKNOWN
@@ -167,9 +154,14 @@ def setUp(self):
167
154
boa_settings .REFRESH_JOB_INTERVAL = DEFAULT_REFRESH_JOB_INTERVAL
168
155
boa_settings .MAX_JOB_WAITING_TIME = DEFAULT_MAX_JOB_WAITING_TIME
169
156
157
+ from conftest import start_mock_send_grid
158
+ self .mock_send_grid = start_mock_send_grid (self )
159
+
170
160
def tearDown (self ):
171
161
super ().tearDown ()
172
162
163
+ @mock .patch ('website.mails.settings.USE_EMAIL' , True )
164
+ @mock .patch ('website.mails.settings.USE_CELERY' , False )
173
165
async def test_submit_success (self ):
174
166
with mock .patch ('osf.models.user.OSFUser.objects.get' , return_value = self .user ), \
175
167
mock .patch ('osf.models.user.OSFUser.get_or_create_cookie' , return_value = self .user_cookie ), \
@@ -179,7 +171,6 @@ async def test_submit_success(self):
179
171
mock .patch ('boaapi.boa_client.BoaClient.query' , return_value = self .mock_job ), \
180
172
mock .patch ('boaapi.boa_client.BoaClient.close' , return_value = None ) as mock_close , \
181
173
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 , \
183
174
mock .patch ('addons.boa.tasks.handle_boa_error' , return_value = None ) as mock_handle_boa_error :
184
175
return_value = await submit_to_boa_async (
185
176
self .host ,
@@ -199,19 +190,7 @@ async def test_submit_success(self):
199
190
assert self .mock_job .refresh .call_count == 4
200
191
assert mock_async_sleep .call_count == 4
201
192
mock_close .assert_called ()
202
- mock_send_mail .assert_called_with (
203
- to_addr = self .user .username ,
204
- mail = ADDONS_BOA_JOB_COMPLETE ,
205
- fullname = self .user .fullname ,
206
- query_file_name = self .query_file_name ,
207
- query_file_full_path = self .file_full_path ,
208
- output_file_name = self .output_file_name ,
209
- job_id = self .mock_job .id ,
210
- project_url = self .project_url ,
211
- boa_job_list_url = boa_settings .BOA_JOB_LIST_URL ,
212
- boa_support_email = boa_settings .BOA_SUPPORT_EMAIL ,
213
- osf_support_email = osf_settings .OSF_SUPPORT_EMAIL ,
214
- )
193
+ self .mock_send_grid .assert_called ()
215
194
mock_handle_boa_error .assert_not_called ()
216
195
217
196
async def test_download_error (self ):
0 commit comments