Renovate OpenUV config flow tests (#85150)

This commit is contained in:
Aaron Bach 2023-01-06 02:51:46 -07:00 committed by GitHub
parent 9ed629d838
commit 39b110b9b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 98 deletions

View file

@ -1,6 +1,6 @@
"""Define test fixtures for OpenUV."""
import json
from unittest.mock import patch
from unittest.mock import AsyncMock, Mock, patch
import pytest
@ -11,10 +11,23 @@ from homeassistant.const import (
CONF_LATITUDE,
CONF_LONGITUDE,
)
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry, load_fixture
TEST_API_KEY = "abcde12345"
TEST_ELEVATION = 0
TEST_LATITUDE = 51.528308
TEST_LONGITUDE = -0.3817765
@pytest.fixture(name="client")
def client_fixture(data_protection_window, data_uv_index):
"""Define a mock Client object."""
return Mock(
uv_index=AsyncMock(return_value=data_uv_index),
uv_protection_window=AsyncMock(return_value=data_protection_window),
)
@pytest.fixture(name="config_entry")
def config_entry_fixture(hass, config):
@ -30,13 +43,13 @@ def config_entry_fixture(hass, config):
@pytest.fixture(name="config")
def config_fixture(hass):
def config_fixture():
"""Define a config entry data fixture."""
return {
CONF_API_KEY: "abcde12345",
CONF_ELEVATION: 0,
CONF_LATITUDE: 51.528308,
CONF_LONGITUDE: -0.3817765,
CONF_API_KEY: TEST_API_KEY,
CONF_ELEVATION: TEST_ELEVATION,
CONF_LATITUDE: TEST_LATITUDE,
CONF_LONGITUDE: TEST_LONGITUDE,
}
@ -52,17 +65,18 @@ def data_uv_index_fixture():
return json.loads(load_fixture("uv_index_data.json", "openuv"))
@pytest.fixture(name="setup_openuv")
async def setup_openuv_fixture(hass, config, data_protection_window, data_uv_index):
"""Define a fixture to set up OpenUV."""
@pytest.fixture(name="mock_pyopenuv")
async def mock_pyopenuv_fixture(client):
"""Define a fixture to patch pyopenuv."""
with patch(
"homeassistant.components.openuv.Client.uv_index", return_value=data_uv_index
), patch(
"homeassistant.components.openuv.Client.uv_protection_window",
return_value=data_protection_window,
), patch(
"homeassistant.components.openuv.PLATFORMS", []
):
assert await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
"homeassistant.components.openuv.config_flow.Client", return_value=client
), patch("homeassistant.components.openuv.Client", return_value=client):
yield
@pytest.fixture(name="setup_config_entry")
async def setup_config_entry_fixture(hass, config_entry, mock_pyopenuv):
"""Define a fixture to set up openuv."""
assert await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
yield