From 6dc6264d5d40d51304ca0197b03372321758d836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Casaj=C3=BAs?= Date: Wed, 30 Jul 2025 15:49:37 +0200 Subject: [PATCH] Fix test --- app/mail_sender.py | 5 ++++- tests/test_email_utils.py | 1 + tests/test_mail_sender.py | 11 +++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/mail_sender.py b/app/mail_sender.py index ec2e9253..7add5d1a 100644 --- a/app/mail_sender.py +++ b/app/mail_sender.py @@ -200,7 +200,7 @@ class MailSender: elapsed = time.time() - start LOG.d( - f"Getting a smtp connection to {server_host} takes seconds {elapsed:.3} seconds" + f"Getting a smtp connection to {server_host}:{server_port} takes seconds {elapsed:.3} seconds" ) newrelic.agent.record_custom_metric("Custom/smtp_connection_time", elapsed) @@ -221,6 +221,9 @@ class MailSender: send_request.mail_options, send_request.rcpt_options, ) + LOG.d( + f"Email sent using {server_host}:{server_port} from {send_request.envelope_from} to {send_request.envelope_to}" + ) return True diff --git a/tests/test_email_utils.py b/tests/test_email_utils.py index 51a45df5..ccfb4cc2 100644 --- a/tests/test_email_utils.py +++ b/tests/test_email_utils.py @@ -148,6 +148,7 @@ def test_disabled_user_with_secondary_mailbox_prevents_email_from_being_used_as_ def test_mx_invalid_ip(): + ForbiddenMxIp.filter().delete() invalid_mx_ip = "12.2.23.23" valid_mx_ip = "1.1.1.1" ForbiddenMxIp.create(ip=invalid_mx_ip, flush=True) diff --git a/tests/test_mail_sender.py b/tests/test_mail_sender.py index fcbc4880..cbe7407c 100644 --- a/tests/test_mail_sender.py +++ b/tests/test_mail_sender.py @@ -106,10 +106,10 @@ def compare_send_requests(expected: SendRequest, request: SendRequest): ) def test_mail_sender_save_unsent_to_disk(server_fn): original_postfix_server = config.POSTFIX_SERVERS - config.POSTFIX_SERVERS = ["localhost"] + port_closed = closed_dummy_server() + config.POSTFIX_SERVERS = [f"localhost:{port_closed}"] config.NOT_SEND_EMAIL = False config.POSTFIX_SUBMISSION_TLS = False - config.POSTFIX_TIMEOUT = 6000 config.POSTFIX_PORT = server_fn() try: with tempfile.TemporaryDirectory() as temp_dir: @@ -156,13 +156,15 @@ def test_mail_sender_try_backup_postfix(): assert mail_sender.send(send_request, 0) finally: config.POSTFIX_SERVERS = original_postfix_server + config.POSTFIX_BACKUP_SERVERS = [] config.NOT_SEND_EMAIL = True @mail_sender.store_emails_test_decorator def test_send_unsent_email_from_fs(): original_postfix_server = config.POSTFIX_SERVERS - config.POSTFIX_SERVERS = ["localhost"] + port_closed = closed_dummy_server() + config.POSTFIX_SERVERS = [f"localhost:{port_closed}"] config.NOT_SEND_EMAIL = False with tempfile.TemporaryDirectory() as temp_dir: try: @@ -188,7 +190,8 @@ def test_send_unsent_email_from_fs(): @mail_sender.store_emails_test_decorator def test_failed_resend_does_not_delete_file(): original_postfix_server = config.POSTFIX_SERVERS - config.POSTFIX_SERVERS = ["localhost"] + port_closed = closed_dummy_server() + config.POSTFIX_SERVERS = [f"localhost:{port_closed}"] config.NOT_SEND_EMAIL = False try: with tempfile.TemporaryDirectory() as temp_dir: