-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: enable UTF8 IMAP capability (#671)
- Loading branch information
Showing
3 changed files
with
60 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ def mock_imap(): | |
mock_conn.search.return_value = ("OK", [b"1"]) | ||
mock_conn.uid.return_value = ("OK", [b"1"]) | ||
mock_conn.select.return_value = ("OK", []) | ||
mock_conn.enable.return_value = ("OK", []) | ||
yield mock_conn | ||
|
||
|
||
|
@@ -123,6 +124,7 @@ def mock_imap_no_email(): | |
mock_conn.search.return_value = ("OK", [b""]) | ||
mock_conn.uid.return_value = ("OK", [b""]) | ||
mock_conn.select.return_value = ("OK", []) | ||
mock_conn.enable.return_value = ("OK", []) | ||
yield mock_conn | ||
|
||
|
||
|
@@ -390,17 +392,44 @@ def mock_imap_dhl_out_for_delivery(): | |
email_file = f.read() | ||
mock_conn.fetch.return_value = ("OK", [(b"", email_file.encode("utf-8"))]) | ||
mock_conn.select.return_value = ("OK", []) | ||
mock_conn.enable.return_value = ("OK", []) | ||
yield mock_conn | ||
|
||
@pytest.fixture() | ||
def mock_imap_dhl_no_utf8(): | ||
"""Mock imap class values.""" | ||
with patch( | ||
"custom_components.mail_and_packages.helpers.imaplib" | ||
) as mock_imap_dhl_no_utf8: | ||
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL) | ||
mock_imap_dhl_no_utf8.IMAP4_SSL.return_value = mock_conn | ||
|
||
mock_conn.login.return_value = ( | ||
"OK", | ||
[b"[email protected] authenticated (Success)"], | ||
) | ||
mock_conn.list.return_value = ( | ||
"OK", | ||
[b'(\\HasNoChildren) "/" "INBOX"'], | ||
) | ||
mock_conn.search.return_value = ("OK", [b"1"]) | ||
mock_conn.uid.return_value = ("OK", [b"1"]) | ||
f = open("tests/test_emails/dhl_out_for_delivery.eml", "r") | ||
email_file = f.read() | ||
mock_conn.fetch.return_value = ("OK", [(b"", email_file.encode("utf-8"))]) | ||
mock_conn.select.return_value = ("OK", []) | ||
mock_conn.enable.side_effect = Exception("BAD", ["Unsupported"]) | ||
yield mock_conn | ||
|
||
|
||
@pytest.fixture() | ||
def mock_imap_fedex_out_for_delivery(): | ||
"""Mock imap class values.""" | ||
with patch( | ||
"custom_components.mail_and_packages.helpers.imaplib" | ||
) as mock_imap_dhl_out_for_delivery: | ||
) as mock_imap_fedex_out_for_delivery: | ||
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL) | ||
mock_imap_dhl_out_for_delivery.IMAP4_SSL.return_value = mock_conn | ||
mock_imap_fedex_out_for_delivery.IMAP4_SSL.return_value = mock_conn | ||
|
||
mock_conn.login.return_value = ( | ||
"OK", | ||
|
@@ -416,6 +445,7 @@ def mock_imap_fedex_out_for_delivery(): | |
email_file = f.read() | ||
mock_conn.fetch.return_value = ("OK", [(b"", email_file.encode("utf-8"))]) | ||
mock_conn.select.return_value = ("OK", []) | ||
mock_conn.enable.return_value = ("OK", []) | ||
yield mock_conn | ||
|
||
|
||
|
@@ -424,9 +454,9 @@ def mock_imap_fedex_out_for_delivery_2(): | |
"""Mock imap class values.""" | ||
with patch( | ||
"custom_components.mail_and_packages.helpers.imaplib" | ||
) as mock_imap_dhl_out_for_delivery: | ||
) as mock_imap_fedex_out_for_delivery_2: | ||
mock_conn = mock.Mock(spec=imaplib.IMAP4_SSL) | ||
mock_imap_dhl_out_for_delivery.IMAP4_SSL.return_value = mock_conn | ||
mock_imap_fedex_out_for_delivery_2.IMAP4_SSL.return_value = mock_conn | ||
|
||
mock_conn.login.return_value = ( | ||
"OK", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters