From bccd18b83851975ba4ed9ceeb5c5d02b4d7d7db7 Mon Sep 17 00:00:00 2001 From: -LAN- Date: Wed, 24 Sep 2025 03:29:56 +0800 Subject: [PATCH] test(smtp): fix patch path --- api/tests/unit_tests/libs/test_smtp_client.py | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/api/tests/unit_tests/libs/test_smtp_client.py b/api/tests/unit_tests/libs/test_smtp_client.py index 7e9f194e5f..bb4ff95f41 100644 --- a/api/tests/unit_tests/libs/test_smtp_client.py +++ b/api/tests/unit_tests/libs/test_smtp_client.py @@ -1,19 +1,20 @@ from unittest.mock import MagicMock, patch import pytest -from libs.smtp import SMTPClient + +from libs.mail import SMTPClient def _mail() -> dict: return {"to": "user@example.com", "subject": "Hi", "html": "Hi"} -@patch("libs.smtp.smtplib.SMTP") +@patch("libs.mail.smtp_connection.smtplib.SMTP") def test_smtp_plain_success(mock_smtp_cls: MagicMock): mock_smtp = MagicMock() mock_smtp_cls.return_value = mock_smtp - client = SMTPClient(server="smtp.example.com", port=25, username="", password="", _from="noreply@example.com") + client = SMTPClient(server="smtp.example.com", port=25, username="", password="", from_addr="noreply@example.com") client.send(_mail()) mock_smtp_cls.assert_called_once_with("smtp.example.com", 25, timeout=10) @@ -21,7 +22,7 @@ def test_smtp_plain_success(mock_smtp_cls: MagicMock): mock_smtp.quit.assert_called_once() -@patch("libs.smtp.smtplib.SMTP") +@patch("libs.mail.smtp_connection.smtplib.SMTP") def test_smtp_tls_opportunistic_success(mock_smtp_cls: MagicMock): mock_smtp = MagicMock() mock_smtp_cls.return_value = mock_smtp @@ -31,7 +32,7 @@ def test_smtp_tls_opportunistic_success(mock_smtp_cls: MagicMock): port=587, username="user", password="pass", - _from="noreply@example.com", + from_addr="noreply@example.com", use_tls=True, opportunistic_tls=True, ) @@ -45,7 +46,7 @@ def test_smtp_tls_opportunistic_success(mock_smtp_cls: MagicMock): mock_smtp.quit.assert_called_once() -@patch("libs.smtp.smtplib.SMTP_SSL") +@patch("libs.mail.smtp_connection.smtplib.SMTP_SSL") def test_smtp_tls_ssl_branch_and_timeout(mock_smtp_ssl_cls: MagicMock): # Cover SMTP_SSL branch and TimeoutError handling mock_smtp = MagicMock() @@ -57,7 +58,7 @@ def test_smtp_tls_ssl_branch_and_timeout(mock_smtp_ssl_cls: MagicMock): port=465, username="", password="", - _from="noreply@example.com", + from_addr="noreply@example.com", use_tls=True, opportunistic_tls=False, ) @@ -66,19 +67,19 @@ def test_smtp_tls_ssl_branch_and_timeout(mock_smtp_ssl_cls: MagicMock): mock_smtp.quit.assert_called_once() -@patch("libs.smtp.smtplib.SMTP") +@patch("libs.mail.smtp_connection.smtplib.SMTP") def test_smtp_generic_exception_propagates(mock_smtp_cls: MagicMock): mock_smtp = MagicMock() mock_smtp.sendmail.side_effect = RuntimeError("oops") mock_smtp_cls.return_value = mock_smtp - client = SMTPClient(server="smtp.example.com", port=25, username="", password="", _from="noreply@example.com") + client = SMTPClient(server="smtp.example.com", port=25, username="", password="", from_addr="noreply@example.com") with pytest.raises(RuntimeError): client.send(_mail()) mock_smtp.quit.assert_called_once() -@patch("libs.smtp.smtplib.SMTP") +@patch("libs.mail.smtp_connection.smtplib.SMTP") def test_smtp_smtplib_exception_in_login(mock_smtp_cls: MagicMock): # Ensure we hit the specific SMTPException except branch import smtplib @@ -92,7 +93,7 @@ def test_smtp_smtplib_exception_in_login(mock_smtp_cls: MagicMock): port=25, username="user", # non-empty to trigger login password="pass", - _from="noreply@example.com", + from_addr="noreply@example.com", ) with pytest.raises(smtplib.SMTPException): client.send(_mail())