Skip to content

Commit

Permalink
feat: add amazon.es support (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
firstof9 authored Aug 1, 2022
2 parents f6c5050 + 17dc0a7 commit ae43183
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
3 changes: 3 additions & 0 deletions custom_components/mail_and_packages/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"amazon.it",
"amazon.com.au",
"amazon.pl",
"amazon.es",
]
AMAZON_DELIVERED_SUBJECT = [
"Delivered: Your",
Expand Down Expand Up @@ -111,6 +112,8 @@
"arriving:",
"Dostawa:",
"Zustellung:",
"Entrega:",
"A chegar:",
]
AMAZON_EXCEPTION_SUBJECT = "Delivery update:"
AMAZON_EXCEPTION_BODY = "running late"
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,7 @@ def mock_imap_amazon_fwd():
mock_conn.select.return_value = ("OK", [])
yield mock_conn


@pytest.fixture()
def mock_update_amazon_image():
"""Mock email data update class values."""
Expand All @@ -1432,7 +1433,7 @@ def mock_update_amazon_image():
) as mock_update:
# value = mock.Mock()
mock_update.return_value = FAKE_UPDATE_DATA_BIN
yield mock_update
yield mock_update


@pytest.fixture(autouse=True)
Expand Down
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,4 +788,4 @@
"gls_delivering": 1,
"gls_packages": 3,
"gls_tracking": ["51687952111"],
}
}
6 changes: 3 additions & 3 deletions tests/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from unittest.mock import patch


async def test_binary_sensor_no_updates(hass, mock_imap_no_email):
entry = MockConfigEntry(
domain=DOMAIN,
Expand Down Expand Up @@ -39,15 +40,14 @@ async def test_binary_sensor_updated(hass, mock_update_amazon_image):

entry.add_to_hass(hass)
with patch("os.path.exists", return_value=True), patch(
"custom_components.mail_and_packages.binary_sensor.hash_file"
"custom_components.mail_and_packages.binary_sensor.hash_file"
) as mock_hash_file:
mock_hash_file.side_effect = hash_side_effect
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()

assert "mail_and_packages" in hass.config.components


state = hass.states.get("binary_sensor.usps_image_updated")
assert state
assert state.state == "on"
Expand All @@ -64,4 +64,4 @@ def hash_side_effect(value):
elif "no_deliveries.jpg" in value:
return "633d7356947ffc643c50b76a1852f92427f4dca9"
else:
return "133d7356947fec542c50b76b1856f92427f5dca9"
return "133d7356947fec542c50b76b1856f92427f5dca9"
14 changes: 7 additions & 7 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ async def test_amazon_search_results(hass, mock_imap_amazon_shipped):
result = amazon_search(
mock_imap_amazon_shipped, "test/path", hass, "testfilename.jpg"
)
assert result == 40
assert result == 44


async def test_amazon_search_delivered(
Expand All @@ -805,7 +805,7 @@ async def test_amazon_search_delivered(
result = amazon_search(
mock_imap_amazon_delivered, "test/path", hass, "testfilename.jpg"
)
assert result == 40
assert result == 44
assert mock_download_img.called


Expand All @@ -815,7 +815,7 @@ async def test_amazon_search_delivered_it(
result = amazon_search(
mock_imap_amazon_delivered_it, "test/path", hass, "testfilename.jpg"
)
assert result == 40
assert result == 44


async def test_amazon_hub(hass, mock_imap_amazon_the_hub):
Expand Down Expand Up @@ -1026,13 +1026,13 @@ async def test_image_file_name(

async def test_amazon_exception(hass, mock_imap_amazon_exception, caplog):
result = amazon_exception(mock_imap_amazon_exception, ['""'])
assert result["order"] == ["123-1234567-1234567"] * 10
assert result["count"] == 10
assert result["order"] == ["123-1234567-1234567"] * 11
assert result["count"] == 11

result = amazon_exception(mock_imap_amazon_exception, ["[email protected]"])
assert result["count"] == 11
assert result["count"] == 12
assert (
"Amazon domains to be checked: ['amazon.com', 'amazon.ca', 'amazon.co.uk', 'amazon.in', 'amazon.de', 'amazon.it', 'amazon.com.au', 'amazon.pl', '[email protected]', '[email protected]', '[email protected]']"
"Amazon domains to be checked: ['amazon.com', 'amazon.ca', 'amazon.co.uk', 'amazon.in', 'amazon.de', 'amazon.it', 'amazon.com.au', 'amazon.pl', 'amazon.es', '[email protected]', '[email protected]', '[email protected]']"
in caplog.text
)

Expand Down

0 comments on commit ae43183

Please sign in to comment.