Convert test to assertLogs instead of mock logger

This commit is contained in:
John Whitlock 2024-02-22 13:21:00 -06:00
Родитель 37fad034cb
Коммит b81d984f70
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 082C735D154FB750
1 изменённых файлов: 14 добавлений и 14 удалений

Просмотреть файл

@ -549,22 +549,22 @@ class SNSNotificationIncomingTest(SNSNotificationTestBase):
assert self.ra.last_used_at is None
@patch("emails.views.generate_from_header", side_effect=InvalidFromHeader())
@patch("emails.views.info_logger")
def test_invalid_from_header(self, mock_logger, mock_generate_from_header) -> None:
def test_invalid_from_header(self, mock_generate_from_header: Mock) -> None:
"""For MPP-3407, show logging for failed from address"""
response = _sns_notification(EMAIL_SNS_BODIES["single_recipient"])
with self.assertLogs("eventsinfo", "ERROR") as event_caplog:
response = _sns_notification(EMAIL_SNS_BODIES["single_recipient"])
assert response.status_code == 503
mock_logger.error.assert_called_once_with(
"generate_from_header",
extra={
"from_address": "fxastage@protonmail.com",
"source": "fxastage@protonmail.com",
"common_headers_from": ["fxastage <fxastage@protonmail.com>"],
"headers_from": [
{"name": "From", "value": "fxastage <fxastage@protonmail.com>"}
],
},
)
assert len(event_caplog.records) == 1
event_log = event_caplog.records[0]
assert getattr(event_log, "from_address") == "fxastage@protonmail.com"
assert getattr(event_log, "source") == "fxastage@protonmail.com"
assert getattr(event_log, "common_headers_from") == [
"fxastage <fxastage@protonmail.com>"
]
assert getattr(event_log, "headers_from") == [
{"name": "From", "value": "fxastage <fxastage@protonmail.com>"}
]
self.mock_send_raw_email.assert_not_called()
self.mock_remove_message_from_s3.assert_not_called()