hass-core/tests/components/smarttub/conftest.py
Matt Zimmerman da51e23514
Address late smarttub review (#46703)
* _config -> config

* remove unused string

* remove entity tests

* replace unit tests with integration tests using the core

* refactor polling to use asyncio.gather

* remove redundant component init

* remove gather in favor of simple loop

* use async_fire_time_changed instead of async_update_entity

* use hass.config_entries.async_setup instead of calling smarttub.async_setup_entry directly

* replace stray smarttub.async_setup_entry call

* async_unload_entry -> hass.config_entries.async_unload

* remove broken test
2021-02-19 01:18:02 +01:00

73 lines
1.8 KiB
Python

"""Common fixtures for smarttub tests."""
from unittest.mock import create_autospec, patch
import pytest
import smarttub
from homeassistant.components.smarttub.const import DOMAIN
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry
@pytest.fixture
def config_data():
"""Provide configuration data for tests."""
return {CONF_EMAIL: "test-email", CONF_PASSWORD: "test-password"}
@pytest.fixture
def config_entry(config_data):
"""Create a mock config entry."""
return MockConfigEntry(
domain=DOMAIN,
data=config_data,
options={},
)
@pytest.fixture
async def setup_component(hass):
"""Set up the component."""
assert await async_setup_component(hass, DOMAIN, {}) is True
@pytest.fixture(name="spa")
def mock_spa():
"""Mock a SmartTub.Spa."""
mock_spa = create_autospec(smarttub.Spa, instance=True)
mock_spa.id = "mockspa1"
mock_spa.brand = "mockbrand1"
mock_spa.model = "mockmodel1"
mock_spa.get_status.return_value = {
"setTemperature": 39,
"water": {"temperature": 38},
"heater": "ON",
}
return mock_spa
@pytest.fixture(name="account")
def mock_account(spa):
"""Mock a SmartTub.Account."""
mock_account = create_autospec(smarttub.Account, instance=True)
mock_account.id = "mockaccount1"
mock_account.get_spas.return_value = [spa]
return mock_account
@pytest.fixture(name="smarttub_api")
def mock_api(account, spa):
"""Mock the SmartTub API."""
with patch(
"homeassistant.components.smarttub.controller.SmartTub",
autospec=True,
) as api_class_mock:
api_mock = api_class_mock.return_value
api_mock.get_account.return_value = account
yield api_mock