fix: update email test mocks to use imap.uid() instead of imap.search/fetch

Tests were still mocking imap.search() and imap.fetch() but the
implementation was changed to use imap.uid("search", ...) and
imap.uid("fetch", ...) for proper UID-based IMAP operations.
This commit is contained in:
Himess 2026-03-14 13:01:51 +03:00 committed by teknium1
parent fa72f4ff55
commit 344adc72a1

View file

@ -797,7 +797,7 @@ class TestConnectDisconnect(unittest.TestCase):
adapter = self._make_adapter() adapter = self._make_adapter()
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b"1 2 3"]) mock_imap.uid.return_value = ("OK", [b"1 2 3"])
with patch("imaplib.IMAP4_SSL", return_value=mock_imap), \ with patch("imaplib.IMAP4_SSL", return_value=mock_imap), \
patch("smtplib.SMTP") as mock_smtp: patch("smtplib.SMTP") as mock_smtp:
@ -831,7 +831,7 @@ class TestConnectDisconnect(unittest.TestCase):
adapter = self._make_adapter() adapter = self._make_adapter()
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b""]) mock_imap.uid.return_value = ("OK", [b""])
with patch("imaplib.IMAP4_SSL", return_value=mock_imap), \ with patch("imaplib.IMAP4_SSL", return_value=mock_imap), \
patch("smtplib.SMTP", side_effect=Exception("SMTP down")): patch("smtplib.SMTP", side_effect=Exception("SMTP down")):
@ -880,8 +880,15 @@ class TestFetchNewMessages(unittest.TestCase):
raw_email["Message-ID"] = "<msg@test.com>" raw_email["Message-ID"] = "<msg@test.com>"
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b"1 2 3"])
mock_imap.fetch.return_value = ("OK", [(b"3", raw_email.as_bytes())]) def uid_handler(command, *args):
if command == "search":
return ("OK", [b"1 2 3"])
if command == "fetch":
return ("OK", [(b"3", raw_email.as_bytes())])
return ("NO", [])
mock_imap.uid.side_effect = uid_handler
with patch("imaplib.IMAP4_SSL", return_value=mock_imap): with patch("imaplib.IMAP4_SSL", return_value=mock_imap):
results = adapter._fetch_new_messages() results = adapter._fetch_new_messages()
@ -896,7 +903,7 @@ class TestFetchNewMessages(unittest.TestCase):
adapter = self._make_adapter() adapter = self._make_adapter()
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b""]) mock_imap.uid.return_value = ("OK", [b""])
with patch("imaplib.IMAP4_SSL", return_value=mock_imap): with patch("imaplib.IMAP4_SSL", return_value=mock_imap):
results = adapter._fetch_new_messages() results = adapter._fetch_new_messages()
@ -922,8 +929,15 @@ class TestFetchNewMessages(unittest.TestCase):
raw_email["Message-ID"] = "<msg@test.com>" raw_email["Message-ID"] = "<msg@test.com>"
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b"1"])
mock_imap.fetch.return_value = ("OK", [(b"1", raw_email.as_bytes())]) def uid_handler(command, *args):
if command == "search":
return ("OK", [b"1"])
if command == "fetch":
return ("OK", [(b"1", raw_email.as_bytes())])
return ("NO", [])
mock_imap.uid.side_effect = uid_handler
with patch("imaplib.IMAP4_SSL", return_value=mock_imap): with patch("imaplib.IMAP4_SSL", return_value=mock_imap):
results = adapter._fetch_new_messages() results = adapter._fetch_new_messages()
@ -966,8 +980,15 @@ class TestPollLoop(unittest.TestCase):
raw_email["Message-ID"] = "<inbox@test.com>" raw_email["Message-ID"] = "<inbox@test.com>"
mock_imap = MagicMock() mock_imap = MagicMock()
mock_imap.search.return_value = ("OK", [b"1"])
mock_imap.fetch.return_value = ("OK", [(b"1", raw_email.as_bytes())]) def uid_handler(command, *args):
if command == "search":
return ("OK", [b"1"])
if command == "fetch":
return ("OK", [(b"1", raw_email.as_bytes())])
return ("NO", [])
mock_imap.uid.side_effect = uid_handler
with patch("imaplib.IMAP4_SSL", return_value=mock_imap): with patch("imaplib.IMAP4_SSL", return_value=mock_imap):
asyncio.run(adapter._check_inbox()) asyncio.run(adapter._check_inbox())