mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 19:57:07 +00:00
Add first unit test to config flow for Plum Lightpad (#37183)
* add first unit test to config flow for Plum Lightpad * add first unit test to config flow for Plum Lightpad (add changed requirements_test_all.txt) * add first unit test to config flow for Plum Lightpad * add first unit test to config flow for Plum Lightpad (bring coverage to 100%) * add first unit test to config flow for Plum Lightpad * add first unit test to config flow for Plum Lightpad (updated patch path as suggested) * add first unit test to config flow for Plum Lightpad (add unit test for abort)
This commit is contained in:
parent
b96ce9c210
commit
7ef33a7219
@ -620,7 +620,8 @@ omit =
|
||||
homeassistant/components/plugwise/climate.py
|
||||
homeassistant/components/plugwise/sensor.py
|
||||
homeassistant/components/plugwise/switch.py
|
||||
homeassistant/components/plum_lightpad/*
|
||||
homeassistant/components/plum_lightpad/__init__.py
|
||||
homeassistant/components/plum_lightpad/light.py
|
||||
homeassistant/components/pocketcasts/sensor.py
|
||||
homeassistant/components/point/*
|
||||
homeassistant/components/prezzibenzina/sensor.py
|
||||
|
@ -489,6 +489,9 @@ plexauth==0.0.5
|
||||
# homeassistant.components.plex
|
||||
plexwebsocket==0.0.11
|
||||
|
||||
# homeassistant.components.plum_lightpad
|
||||
plumlightpad==0.0.11
|
||||
|
||||
# homeassistant.components.mhz19
|
||||
# homeassistant.components.serial_pm
|
||||
pmsensor==0.4
|
||||
|
1
tests/components/plum_lightpad/__init__.py
Normal file
1
tests/components/plum_lightpad/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Tests for the Plum Lightpad integration."""
|
117
tests/components/plum_lightpad/test_config_flow.py
Normal file
117
tests/components/plum_lightpad/test_config_flow.py
Normal file
@ -0,0 +1,117 @@
|
||||
"""Test the Plum Lightpad config flow."""
|
||||
from requests.exceptions import ConnectTimeout
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.plum_lightpad.const import DOMAIN
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_form(hass):
|
||||
"""Test we get the form."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] == "form"
|
||||
assert result["errors"] == {}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": "test-plum-username", "password": "test-plum-password"},
|
||||
)
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "test-plum-username"
|
||||
assert result2["data"] == {
|
||||
"username": "test-plum-username",
|
||||
"password": "test-plum-password",
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_cannot_connect(hass):
|
||||
"""Test we handle invalid auth."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData",
|
||||
side_effect=ConnectTimeout,
|
||||
):
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": "test-plum-username", "password": "test-plum-password"},
|
||||
)
|
||||
|
||||
assert result2["type"] == "form"
|
||||
assert result2["errors"] == {"base": "cannot_connect"}
|
||||
|
||||
|
||||
async def test_form_one_entry_per_email_allowed(hass):
|
||||
"""Test that only one entry allowed per Plum cloud email address."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="test-plum-username",
|
||||
data={"username": "test-plum-username", "password": "test-plum-password"},
|
||||
).add_to_hass(hass)
|
||||
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch("homeassistant.components.plum_lightpad.async_setup") as mock_setup, patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry"
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": "test-plum-username", "password": "test-plum-password"},
|
||||
)
|
||||
|
||||
assert result2["type"] == "abort"
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 0
|
||||
assert len(mock_setup_entry.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_import(hass):
|
||||
"""Test configuring the flow using configuration.yaml."""
|
||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
|
||||
), patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup", return_value=True
|
||||
) as mock_setup, patch(
|
||||
"homeassistant.components.plum_lightpad.async_setup_entry", return_value=True,
|
||||
) as mock_setup_entry:
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={"username": "test-plum-username", "password": "test-plum-password"},
|
||||
)
|
||||
assert result["type"] == "create_entry"
|
||||
assert result["title"] == "test-plum-username"
|
||||
assert result["data"] == {
|
||||
"username": "test-plum-username",
|
||||
"password": "test-plum-password",
|
||||
}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
Loading…
x
Reference in New Issue
Block a user