Refactor null_file assignment to use subprocess.DEVNULL and update webhook client test descriptions

This commit is contained in:
Sean Whalen
2026-03-26 02:29:39 -04:00
parent cc664540aa
commit 778bc1e7ca
2 changed files with 2 additions and 31 deletions

View File

@@ -45,7 +45,7 @@ from parsedmarc.log import logger
parenthesis_regex = re.compile(r"\s*\(.*\)\s*")
null_file = open(os.devnull, "w")
null_file = subprocess.DEVNULL
mailparser_logger = logging.getLogger("mailparser")
mailparser_logger.setLevel(logging.CRITICAL)
psl = publicsuffixlist.PublicSuffixList()

View File

@@ -5292,36 +5292,7 @@ Test body"""
class TestWebhookClient(unittest.TestCase):
"""Tests for webhook client error handling and close"""
def testSaveMethodsHandleErrors(self):
"""Each save method catches and logs errors from _send_to_webhook"""
client = parsedmarc.webhook.WebhookClient(
aggregate_url="http://invalid.test/agg",
failure_url="http://invalid.test/fail",
smtp_tls_url="http://invalid.test/tls",
)
# Mock _send_to_webhook to raise, testing the try/except in each save method
with patch.object(
client, "_send_to_webhook", side_effect=Exception("send failed")
):
# None should raise
client.save_aggregate_report_to_webhook('{"test": true}')
client.save_failure_report_to_webhook('{"test": true}')
client.save_smtp_tls_report_to_webhook('{"test": true}')
def testSendToWebhookLogsPostErrors(self):
"""_send_to_webhook catches and logs POST errors"""
client = parsedmarc.webhook.WebhookClient(
aggregate_url="http://invalid.test/agg",
failure_url="http://invalid.test/fail",
smtp_tls_url="http://invalid.test/tls",
)
with patch.object(
client.session, "post", side_effect=Exception("connection refused")
):
# Should not raise
client._send_to_webhook("http://invalid.test/agg", '{"test": true}')
"""Tests for webhook client initialization and close"""
def testClose(self):
"""WebhookClient.close() closes session"""