mirror of
https://github.com/domainaware/parsedmarc.git
synced 2026-04-20 04:19:31 +00:00
Refactor null_file assignment to use subprocess.DEVNULL and update webhook client test descriptions
This commit is contained in:
@@ -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()
|
||||
|
||||
31
tests.py
31
tests.py
@@ -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"""
|
||||
|
||||
Reference in New Issue
Block a user