-
Notifications
You must be signed in to change notification settings - Fork 358
[ENG-8410] Refactor Notifications Phase 1 #11176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a2dd86a
46e8726
944692a
57d7a1a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,9 @@ def setUp(self): | |
| self.output_file_name = 'fake_boa_script_results.txt' | ||
| self.job_id = '1a2b3c4d5e6f7g8' | ||
|
|
||
| from conftest import start_mock_send_grid | ||
| self.mock_send_grid = start_mock_send_grid(self) | ||
|
|
||
| def tearDown(self): | ||
| super().tearDown() | ||
|
|
||
|
|
@@ -52,9 +55,10 @@ def test_boa_error_code(self): | |
| assert BoaErrorCode.FILE_TOO_LARGE_ERROR == 6 | ||
| assert BoaErrorCode.JOB_TIME_OUT_ERROR == 7 | ||
|
|
||
| @mock.patch('website.mails.settings.USE_EMAIL', True) | ||
| @mock.patch('website.mails.settings.USE_CELERY', False) | ||
| def test_handle_boa_error(self): | ||
| with mock.patch('addons.boa.tasks.send_mail', return_value=None) as mock_send_mail, \ | ||
| mock.patch('addons.boa.tasks.sentry.log_message', return_value=None) as mock_sentry_log_message, \ | ||
| with mock.patch('addons.boa.tasks.sentry.log_message', return_value=None) as mock_sentry_log_message, \ | ||
| mock.patch('addons.boa.tasks.logger.error', return_value=None) as mock_logger_error: | ||
| return_value = handle_boa_error( | ||
| self.error_message, | ||
|
|
@@ -68,24 +72,7 @@ def test_handle_boa_error(self): | |
| output_file_name=self.output_file_name, | ||
| job_id=self.job_id | ||
| ) | ||
| mock_send_mail.assert_called_with( | ||
| to_addr=self.user_username, | ||
| mail=ADDONS_BOA_JOB_FAILURE, | ||
| fullname=self.user_fullname, | ||
| code=BoaErrorCode.UNKNOWN, | ||
| message=self.error_message, | ||
| query_file_name=self.query_file_name, | ||
| file_size=self.file_size, | ||
| max_file_size=boa_settings.MAX_SUBMISSION_SIZE, | ||
| query_file_full_path=self.file_full_path, | ||
| output_file_name=self.output_file_name, | ||
| job_id=self.job_id, | ||
| max_job_wait_hours=self.max_job_wait_hours, | ||
| project_url=self.project_url, | ||
| boa_job_list_url=boa_settings.BOA_JOB_LIST_URL, | ||
| boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
| osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
| ) | ||
| self.mock_send_grid.assert_called() | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A bit lazy just to assert this but asserting every single thing in a template is unmaintainable.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm ... why is it unmaintainable? Did the test fail and we can't figure out how to fix it? The reason why we assert the details for |
||
| mock_sentry_log_message.assert_called_with(self.error_message, skip_session=True) | ||
| mock_logger_error.assert_called_with(self.error_message) | ||
| assert return_value == BoaErrorCode.UNKNOWN | ||
|
|
@@ -167,9 +154,14 @@ def setUp(self): | |
| boa_settings.REFRESH_JOB_INTERVAL = DEFAULT_REFRESH_JOB_INTERVAL | ||
| boa_settings.MAX_JOB_WAITING_TIME = DEFAULT_MAX_JOB_WAITING_TIME | ||
|
|
||
| from conftest import start_mock_send_grid | ||
| self.mock_send_grid = start_mock_send_grid(self) | ||
|
|
||
| def tearDown(self): | ||
| super().tearDown() | ||
|
|
||
| @mock.patch('website.mails.settings.USE_EMAIL', True) | ||
| @mock.patch('website.mails.settings.USE_CELERY', False) | ||
| async def test_submit_success(self): | ||
| with mock.patch('osf.models.user.OSFUser.objects.get', return_value=self.user), \ | ||
| 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): | |
| mock.patch('boaapi.boa_client.BoaClient.query', return_value=self.mock_job), \ | ||
| mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \ | ||
| mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None) as mock_async_sleep, \ | ||
| mock.patch('addons.boa.tasks.send_mail', return_value=None) as mock_send_mail, \ | ||
| mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error: | ||
| return_value = await submit_to_boa_async( | ||
| self.host, | ||
|
|
@@ -199,19 +190,7 @@ async def test_submit_success(self): | |
| assert self.mock_job.refresh.call_count == 4 | ||
| assert mock_async_sleep.call_count == 4 | ||
| mock_close.assert_called() | ||
| mock_send_mail.assert_called_with( | ||
| to_addr=self.user.username, | ||
| mail=ADDONS_BOA_JOB_COMPLETE, | ||
| fullname=self.user.fullname, | ||
| query_file_name=self.query_file_name, | ||
| query_file_full_path=self.file_full_path, | ||
| output_file_name=self.output_file_name, | ||
| job_id=self.mock_job.id, | ||
| project_url=self.project_url, | ||
| boa_job_list_url=boa_settings.BOA_JOB_LIST_URL, | ||
| boa_support_email=boa_settings.BOA_SUPPORT_EMAIL, | ||
| osf_support_email=osf_settings.OSF_SUPPORT_EMAIL, | ||
| ) | ||
| self.mock_send_grid.assert_called() | ||
| mock_handle_boa_error.assert_not_called() | ||
|
|
||
| async def test_download_error(self): | ||
|
|
||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker compose