Clean up IQVIA config flow tests (#64601)
This commit is contained in:
parent
aef8d9ee4d
commit
1f00ded33a
2 changed files with 50 additions and 27 deletions
40
tests/components/iqvia/conftest.py
Normal file
40
tests/components/iqvia/conftest.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
"""Define test fixtures for IQVIA."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.iqvia.const import CONF_ZIP_CODE, DOMAIN
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(name="config_entry")
|
||||
def config_entry_fixture(hass, config, unique_id):
|
||||
"""Define a config entry fixture."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id)
|
||||
entry.add_to_hass(hass)
|
||||
return entry
|
||||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_fixture(hass):
|
||||
"""Define a config entry data fixture."""
|
||||
return {
|
||||
CONF_ZIP_CODE: "12345",
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="setup_iqvia")
|
||||
async def setup_iqvia_fixture(hass, config):
|
||||
"""Define a fixture to set up IQVIA."""
|
||||
with patch("homeassistant.components.iqvia.PLATFORMS", []):
|
||||
assert await async_setup_component(hass, DOMAIN, config)
|
||||
await hass.async_block_till_done()
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="unique_id")
|
||||
def unique_id_fixture(hass):
|
||||
"""Define a config entry unique ID fixture."""
|
||||
return "12345"
|
|
@ -1,35 +1,23 @@
|
|||
"""Define tests for the IQVIA config flow."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.iqvia import CONF_ZIP_CODE, DOMAIN
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_duplicate_error(hass):
|
||||
async def test_duplicate_error(hass, config, config_entry):
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
conf = {CONF_ZIP_CODE: "12345"}
|
||||
|
||||
MockConfigEntry(domain=DOMAIN, unique_id="12345", data=conf).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_invalid_zip_code(hass):
|
||||
"""Test that an invalid ZIP code key throws an error."""
|
||||
conf = {CONF_ZIP_CODE: "abcde"}
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
DOMAIN, context={"source": SOURCE_USER}, data={CONF_ZIP_CODE: "bad"}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["errors"] == {CONF_ZIP_CODE: "invalid_zip_code"}
|
||||
|
||||
|
@ -39,20 +27,15 @@ async def test_show_form(hass):
|
|||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["step_id"] == "user"
|
||||
|
||||
|
||||
async def test_step_user(hass):
|
||||
async def test_step_user(hass, config, setup_iqvia):
|
||||
"""Test that the user step works (without MFA)."""
|
||||
conf = {CONF_ZIP_CODE: "12345"}
|
||||
|
||||
with patch("homeassistant.components.iqvia.async_setup_entry", return_value=True):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=conf
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "12345"
|
||||
assert result["data"] == {CONF_ZIP_CODE: "12345"}
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_USER}, data=config
|
||||
)
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["title"] == "12345"
|
||||
assert result["data"] == {CONF_ZIP_CODE: "12345"}
|
||||
|
|
Loading…
Add table
Reference in a new issue