def test_view_response_improperly_configured(self):
"""
Test that the SearchResultMailView will raise ImproperlyConfigured if mailgun returns 401, which
results in returning 500 since micromasters.utils.custom_exception_handler catches ImproperlyConfigured
"""
with patch(
'mail.views.get_all_query_matching_emails', autospec=True, return_value=self.email_results
), patch(
'mail.views.MailgunClient'
) as mock_mailgun_client, patch(
'mail.views.get_mail_vars', autospec=True, return_value=self.email_vars,
) as mock_get_mail_vars:
mock_mailgun_client.send_batch.side_effect = ImproperlyConfigured
resp = self.client.post(self.search_result_mail_url, data=self.request_data, format='json')
assert resp.status_code == status.HTTP_500_INTERNAL_SERVER_ERROR
mock_get_mail_vars.assert_called_once_with(self.email_results)
评论列表
文章目录