core/tests/components/seventeentrack/conftest.py

153 lines
3.9 KiB
Python
Raw Normal View History

"""Configuration for 17Track tests."""
from collections.abc import Generator
from unittest.mock import AsyncMock, patch
from py17track.package import Package
import pytest
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
from homeassistant.components.seventeentrack.const import (
CONF_SHOW_ARCHIVED,
CONF_SHOW_DELIVERED,
DEFAULT_SHOW_ARCHIVED,
DEFAULT_SHOW_DELIVERED,
)
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
from tests.common import MockConfigEntry
DEFAULT_SUMMARY = {
"Not Found": 0,
"In Transit": 0,
"Expired": 0,
"Ready to be Picked Up": 0,
"Undelivered": 0,
"Delivered": 0,
"Returned": 0,
}
DEFAULT_SUMMARY_LENGTH = len(DEFAULT_SUMMARY)
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
ACCOUNT_ID = "1234"
NEW_SUMMARY_DATA = {
"Not Found": 1,
"In Transit": 1,
"Expired": 1,
"Ready to be Picked Up": 1,
"Undelivered": 1,
"Delivered": 1,
"Returned": 1,
}
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
VALID_CONFIG = {
CONF_USERNAME: "test",
CONF_PASSWORD: "test",
}
INVALID_CONFIG = {"notusername": "seventeentrack", "notpassword": "test"}
VALID_OPTIONS = {
CONF_SHOW_ARCHIVED: True,
CONF_SHOW_DELIVERED: True,
}
NO_DELIVERED_OPTIONS = {
CONF_SHOW_ARCHIVED: False,
CONF_SHOW_DELIVERED: False,
}
VALID_PLATFORM_CONFIG_FULL = {
"sensor": {
"platform": "seventeentrack",
CONF_USERNAME: "test",
CONF_PASSWORD: "test",
CONF_SHOW_ARCHIVED: True,
CONF_SHOW_DELIVERED: True,
}
}
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
"""Override async_setup_entry."""
with patch(
"homeassistant.components.seventeentrack.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
domain="seventeentrack",
data=VALID_CONFIG,
options=VALID_OPTIONS,
unique_id=ACCOUNT_ID,
)
@pytest.fixture
def mock_config_entry_with_default_options() -> MockConfigEntry:
"""Return the default mocked config entry."""
return MockConfigEntry(
domain="seventeentrack",
data=VALID_CONFIG,
options={
CONF_SHOW_ARCHIVED: DEFAULT_SHOW_ARCHIVED,
CONF_SHOW_DELIVERED: DEFAULT_SHOW_DELIVERED,
},
unique_id=ACCOUNT_ID,
)
@pytest.fixture
def mock_seventeentrack():
"""Build a fixture for the 17Track API."""
mock_seventeentrack_api = AsyncMock()
with (
patch(
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
"homeassistant.components.seventeentrack.SeventeenTrackClient",
return_value=mock_seventeentrack_api,
),
patch(
"homeassistant.components.seventeentrack.config_flow.SeventeenTrackClient",
return_value=mock_seventeentrack_api,
) as mock_seventeentrack_api,
):
Add ConfigFlow for seventeentrack integration (#111196) * Add config flow to 17Track * Import config from configuration.yaml * 1. move import to async_setup_platform 2. add USERNAME (email) in title for uniqueness * Add options flow * Add tests * Add CONF_SHOW_ARCHIVED and CONF_SHOW_DELIVERED to data from options * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/manifest.json Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/__init__.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * 1. Added repair issues 2. _async_validate_input inlined 3. added unique id 4. take default scan interval * fix * 1. move async_create_issue to async_setup_platform 2. fix tests 3. black + pylint * combine USER_SCHEMA and OPTIONS_SCHEMA * small fix * remove async_setup * fix tests and add 100% coverage * 1. remove CONFIG_SCHEMA 2. remove error log 3. add issue with more description when import issues happen 4. some linting * Update homeassistant/components/seventeentrack/config_flow.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * use freezer use AsyncMock fix tests * add test_flow_fails parametrize tests where needed test_import_flow_already_configured - where a unique id already configured (abort flow) * lint * fix rebase issues * some more fix * 17Track revert tests and put them in a different PR * adapt tests to MockConfigEntry * Update tests/components/seventeentrack/test_sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/seventeentrack/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/__init__.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. create fixture for config and another with options 2. set options with default values 3. remove CONFIG_SCHEMA * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update tests/components/seventeentrack/conftest.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * 1. get options from import data and default if not present 2. rename mock_config_entry_no_options -> mock_config_entry_with_default_options * move ACCOUNT_ID to mock_seventeentrack_api.return_value.profile.account_id * Apply suggestions from code review * Update tests/components/seventeentrack/test_config_flow.py --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
2024-03-11 11:47:39 +00:00
mock_seventeentrack_api.return_value.profile.account_id = ACCOUNT_ID
mock_seventeentrack_api.return_value.profile.login.return_value = True
mock_seventeentrack_api.return_value.profile.packages.return_value = []
mock_seventeentrack_api.return_value.profile.summary.return_value = (
DEFAULT_SUMMARY
)
yield mock_seventeentrack_api
def get_package(
tracking_number: str = "456",
destination_country: int = 206,
2024-04-14 05:26:58 +00:00
friendly_name: str | None = "friendly name 1",
info_text: str = "info text 1",
location: str = "location 1",
timestamp: str = "2020-08-10 10:32",
origin_country: int = 206,
package_type: int = 2,
status: int = 0,
tz: str = "UTC",
):
"""Build a Package of the 17Track API."""
return Package(
tracking_number=tracking_number,
destination_country=destination_country,
friendly_name=friendly_name,
info_text=info_text,
location=location,
timestamp=timestamp,
origin_country=origin_country,
package_type=package_type,
status=status,
tz=tz,
)