Update huisbaasje-client 0.1.0 to energyflip-client 0.2.0 (#79233)

This commit is contained in:
Dennis Schroer
2022-09-29 13:44:04 -04:00
committed by Paulus Schoutsen
parent 45a217238e
commit ef8c1130d6
9 changed files with 131 additions and 58 deletions
+89 -19
View File
@@ -1,11 +1,13 @@
"""Test the Huisbaasje config flow."""
from unittest.mock import patch
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.huisbaasje.config_flow import (
HuisbaasjeConnectionException,
HuisbaasjeException,
from energyflip import (
EnergyFlipConnectionException,
EnergyFlipException,
EnergyFlipUnauthenticatedException,
)
from homeassistant import config_entries, data_entry_flow
from homeassistant.components.huisbaasje.const import DOMAIN
from tests.common import MockConfigEntry
@@ -21,9 +23,11 @@ async def test_form(hass):
assert result["errors"] == {}
with patch(
"huisbaasje.Huisbaasje.authenticate", return_value=None
"energyflip.EnergyFlip.authenticate", return_value=None
) as mock_authenticate, patch(
"huisbaasje.Huisbaasje.get_user_id",
"energyflip.EnergyFlip.customer_overview", return_value=None
) as mock_customer_overview, patch(
"energyflip.EnergyFlip.get_user_id",
return_value="test-id",
) as mock_get_user_id, patch(
"homeassistant.components.huisbaasje.async_setup_entry",
@@ -46,6 +50,7 @@ async def test_form(hass):
"password": "test-password",
}
assert len(mock_authenticate.mock_calls) == 1
assert len(mock_customer_overview.mock_calls) == 1
assert len(mock_get_user_id.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1
@@ -57,8 +62,8 @@ async def test_form_invalid_auth(hass):
)
with patch(
"huisbaasje.Huisbaasje.authenticate",
side_effect=HuisbaasjeException,
"energyflip.EnergyFlip.authenticate",
side_effect=EnergyFlipException,
):
form_result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -72,15 +77,15 @@ async def test_form_invalid_auth(hass):
assert form_result["errors"] == {"base": "invalid_auth"}
async def test_form_cannot_connect(hass):
"""Test we handle cannot connect error."""
async def test_form_authenticate_cannot_connect(hass):
"""Test we handle cannot connect error in authenticate."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"huisbaasje.Huisbaasje.authenticate",
side_effect=HuisbaasjeConnectionException,
"energyflip.EnergyFlip.authenticate",
side_effect=EnergyFlipConnectionException,
):
form_result = await hass.config_entries.flow.async_configure(
result["flow_id"],
@@ -94,14 +99,80 @@ async def test_form_cannot_connect(hass):
assert form_result["errors"] == {"base": "cannot_connect"}
async def test_form_unknown_error(hass):
"""Test we handle an unknown error."""
async def test_form_authenticate_unknown_error(hass):
"""Test we handle an unknown error in authenticate."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"huisbaasje.Huisbaasje.authenticate",
"energyflip.EnergyFlip.authenticate",
side_effect=Exception,
):
form_result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
},
)
assert form_result["type"] == data_entry_flow.FlowResultType.FORM
assert form_result["errors"] == {"base": "unknown"}
async def test_form_customer_overview_cannot_connect(hass):
"""Test we handle cannot connect error in customer_overview."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch("energyflip.EnergyFlip.authenticate", return_value=None), patch(
"energyflip.EnergyFlip.customer_overview",
side_effect=EnergyFlipConnectionException,
):
form_result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
},
)
assert form_result["type"] == data_entry_flow.FlowResultType.FORM
assert form_result["errors"] == {"base": "cannot_connect"}
async def test_form_customer_overview_authentication_error(hass):
"""Test we handle an unknown error in customer_overview."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch("energyflip.EnergyFlip.authenticate", return_value=None), patch(
"energyflip.EnergyFlip.customer_overview",
side_effect=EnergyFlipUnauthenticatedException,
):
form_result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{
"username": "test-username",
"password": "test-password",
},
)
assert form_result["type"] == data_entry_flow.FlowResultType.FORM
assert form_result["errors"] == {"base": "invalid_auth"}
async def test_form_customer_overview_unknown_error(hass):
"""Test we handle an unknown error in customer_overview."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch("energyflip.EnergyFlip.authenticate", return_value=None), patch(
"energyflip.EnergyFlip.customer_overview",
side_effect=Exception,
):
form_result = await hass.config_entries.flow.async_configure(
@@ -133,10 +204,9 @@ async def test_form_entry_exists(hass):
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch("huisbaasje.Huisbaasje.authenticate", return_value=None), patch(
"huisbaasje.Huisbaasje.get_user_id",
return_value="test-id",
), patch(
with patch("energyflip.EnergyFlip.authenticate", return_value=None), patch(
"energyflip.EnergyFlip.customer_overview", return_value=None
), patch("energyflip.EnergyFlip.get_user_id", return_value="test-id",), patch(
"homeassistant.components.huisbaasje.async_setup_entry",
return_value=True,
):
+8 -8
View File
@@ -1,7 +1,7 @@
"""Test cases for the initialisation of the Huisbaasje integration."""
from unittest.mock import patch
from huisbaasje import HuisbaasjeException
from energyflip import EnergyFlipException
from homeassistant.components import huisbaasje
from homeassistant.config_entries import ConfigEntryState
@@ -24,11 +24,11 @@ async def test_setup(hass: HomeAssistant):
async def test_setup_entry(hass: HomeAssistant):
"""Test for successfully setting a config entry."""
with patch(
"huisbaasje.Huisbaasje.authenticate", return_value=None
"energyflip.EnergyFlip.authenticate", return_value=None
) as mock_authenticate, patch(
"huisbaasje.Huisbaasje.is_authenticated", return_value=True
"energyflip.EnergyFlip.is_authenticated", return_value=True
) as mock_is_authenticated, patch(
"huisbaasje.Huisbaasje.current_measurements",
"energyflip.EnergyFlip.current_measurements",
return_value=MOCK_CURRENT_MEASUREMENTS,
) as mock_current_measurements:
hass.config.components.add(huisbaasje.DOMAIN)
@@ -68,7 +68,7 @@ async def test_setup_entry(hass: HomeAssistant):
async def test_setup_entry_error(hass: HomeAssistant):
"""Test for successfully setting a config entry."""
with patch(
"huisbaasje.Huisbaasje.authenticate", side_effect=HuisbaasjeException
"energyflip.EnergyFlip.authenticate", side_effect=EnergyFlipException
) as mock_authenticate:
hass.config.components.add(huisbaasje.DOMAIN)
config_entry = MockConfigEntry(
@@ -103,11 +103,11 @@ async def test_setup_entry_error(hass: HomeAssistant):
async def test_unload_entry(hass: HomeAssistant):
"""Test for successfully unloading the config entry."""
with patch(
"huisbaasje.Huisbaasje.authenticate", return_value=None
"energyflip.EnergyFlip.authenticate", return_value=None
) as mock_authenticate, patch(
"huisbaasje.Huisbaasje.is_authenticated", return_value=True
"energyflip.EnergyFlip.is_authenticated", return_value=True
) as mock_is_authenticated, patch(
"huisbaasje.Huisbaasje.current_measurements",
"energyflip.EnergyFlip.current_measurements",
return_value=MOCK_CURRENT_MEASUREMENTS,
) as mock_current_measurements:
hass.config.components.add(huisbaasje.DOMAIN)
+6 -6
View File
@@ -29,11 +29,11 @@ from tests.common import MockConfigEntry
async def test_setup_entry(hass: HomeAssistant):
"""Test for successfully loading sensor states."""
with patch(
"huisbaasje.Huisbaasje.authenticate", return_value=None
"energyflip.EnergyFlip.authenticate", return_value=None
) as mock_authenticate, patch(
"huisbaasje.Huisbaasje.is_authenticated", return_value=True
"energyflip.EnergyFlip.is_authenticated", return_value=True
) as mock_is_authenticated, patch(
"huisbaasje.Huisbaasje.current_measurements",
"energyflip.EnergyFlip.current_measurements",
return_value=MOCK_CURRENT_MEASUREMENTS,
) as mock_current_measurements:
@@ -344,11 +344,11 @@ async def test_setup_entry(hass: HomeAssistant):
async def test_setup_entry_absent_measurement(hass: HomeAssistant):
"""Test for successfully loading sensor states when response does not contain all measurements."""
with patch(
"huisbaasje.Huisbaasje.authenticate", return_value=None
"energyflip.EnergyFlip.authenticate", return_value=None
) as mock_authenticate, patch(
"huisbaasje.Huisbaasje.is_authenticated", return_value=True
"energyflip.EnergyFlip.is_authenticated", return_value=True
) as mock_is_authenticated, patch(
"huisbaasje.Huisbaasje.current_measurements",
"energyflip.EnergyFlip.current_measurements",
return_value=MOCK_LIMITED_CURRENT_MEASUREMENTS,
) as mock_current_measurements: