hass-core/tests/components/aquacell/conftest.py
Jordi 7219a4fa98
Add Aquacell integration (#117117)
* Initial commit

* Support changed API
Change sensor entity descriptions

* Fix sensor not handling coordinator update

* Implement re-authentication flow and handle token expiry

* Bump aioaquacell

* Bump aioaquacell

* Cleanup and initial tests

* Fixes for config flow tests

* Cleanup

* Fixes

* Formatted

* Use config entry runtime
Use icon translations
Removed reauth
Removed last updated sensor
Changed lid in place to binary sensor
Cleanup

* Remove reauth strings

* Removed binary_sensor platform
Fixed sensors not updating properly

* Remove reauth tests
Bump aioaquacell

* Moved softener property to entity class
Inlined validate_input method
Renaming of entities
Do a single async_add_entities call to add all entities
Reduced code in try blocks

* Made tests parameterized and use test fixture for api
Cleaned up unused code
Removed traces of reauth

* Add check if refresh token is expired
Add tests

* Add missing unique_id to config entry mock
Inlined _update_config_entry_refresh_token method
Fix incorrect test method name and comment

* Add snapshot test
Changed WiFi level to WiFi strength

* Bump aioaquacell to 0.1.7

* Move test_coordinator tests to test_init
Add test for duplicate config entry
2024-06-06 22:33:58 +02:00

77 lines
2.2 KiB
Python

"""Common fixtures for the Aquacell tests."""
from collections.abc import Generator
from datetime import datetime
from unittest.mock import AsyncMock, patch
from aioaquacell import AquacellApi, Softener
import pytest
from homeassistant.components.aquacell.const import (
CONF_REFRESH_TOKEN_CREATION_TIME,
DOMAIN,
)
from homeassistant.const import CONF_EMAIL
from tests.common import MockConfigEntry, load_json_array_fixture
from tests.components.aquacell import TEST_CONFIG_ENTRY
@pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock, None, None]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.aquacell.async_setup_entry", return_value=True
) as mock_setup_entry:
yield mock_setup_entry
@pytest.fixture
def mock_aquacell_api() -> Generator[AsyncMock, None, None]:
"""Build a fixture for the Aquacell API that authenticates successfully and returns a single softener."""
with (
patch(
"homeassistant.components.aquacell.AquacellApi",
autospec=True,
) as mock_client,
patch(
"homeassistant.components.aquacell.config_flow.AquacellApi",
new=mock_client,
),
):
mock_aquacell_api: AquacellApi = mock_client.return_value
mock_aquacell_api.authenticate.return_value = "refresh-token"
softeners_dict = load_json_array_fixture(
"aquacell/get_all_softeners_one_softener.json"
)
softeners = [Softener(softener) for softener in softeners_dict]
mock_aquacell_api.get_all_softeners.return_value = softeners
yield mock_aquacell_api
@pytest.fixture
def mock_config_entry_expired() -> MockConfigEntry:
"""Mock a config entry."""
return MockConfigEntry(
domain=DOMAIN,
title="Aquacell",
unique_id=TEST_CONFIG_ENTRY[CONF_EMAIL],
data=TEST_CONFIG_ENTRY,
)
@pytest.fixture
def mock_config_entry() -> MockConfigEntry:
"""Mock a config entry."""
return MockConfigEntry(
domain=DOMAIN,
title="Aquacell",
unique_id=TEST_CONFIG_ENTRY[CONF_EMAIL],
data={
**TEST_CONFIG_ENTRY,
CONF_REFRESH_TOKEN_CREATION_TIME: datetime.now().timestamp(),
},
)