mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 10:47:10 +00:00
Wallbox Improve Testing (#102519)
This commit is contained in:
parent
51f989c57a
commit
06a2664a07
@ -29,9 +29,7 @@ from .const import ERROR, STATUS, TTL, USER_ID
|
|||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
test_response = json.loads(
|
test_response = {
|
||||||
json.dumps(
|
|
||||||
{
|
|
||||||
CHARGER_CHARGING_POWER_KEY: 0,
|
CHARGER_CHARGING_POWER_KEY: 0,
|
||||||
CHARGER_STATUS_ID_KEY: 193,
|
CHARGER_STATUS_ID_KEY: 193,
|
||||||
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
|
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
|
||||||
@ -49,8 +47,6 @@ test_response = json.loads(
|
|||||||
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
|
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
test_response_bidir = {
|
test_response_bidir = {
|
||||||
CHARGER_CHARGING_POWER_KEY: 0,
|
CHARGER_CHARGING_POWER_KEY: 0,
|
||||||
@ -72,9 +68,7 @@ test_response_bidir = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
authorisation_response = json.loads(
|
authorisation_response = {
|
||||||
json.dumps(
|
|
||||||
{
|
|
||||||
"data": {
|
"data": {
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"token": "fakekeyhere",
|
"token": "fakekeyhere",
|
||||||
@ -85,13 +79,9 @@ authorisation_response = json.loads(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
authorisation_response_unauthorised = json.loads(
|
authorisation_response_unauthorised = {
|
||||||
json.dumps(
|
|
||||||
{
|
|
||||||
"data": {
|
"data": {
|
||||||
"attributes": {
|
"attributes": {
|
||||||
"token": "fakekeyhere",
|
"token": "fakekeyhere",
|
||||||
@ -102,8 +92,6 @@ authorisation_response_unauthorised = json.loads(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None:
|
||||||
|
@ -45,6 +45,34 @@ async def test_wallbox_unload_entry_connection_error(
|
|||||||
assert entry.state == ConfigEntryState.NOT_LOADED
|
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
|
async def test_wallbox_refresh_failed_connection_error_auth(
|
||||||
|
hass: HomeAssistant, entry: MockConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test Wallbox setup with connection error."""
|
||||||
|
|
||||||
|
await setup_integration(hass, entry)
|
||||||
|
assert entry.state == ConfigEntryState.LOADED
|
||||||
|
|
||||||
|
with requests_mock.Mocker() as mock_request:
|
||||||
|
mock_request.get(
|
||||||
|
"https://user-api.wall-box.com/users/signin",
|
||||||
|
json=authorisation_response,
|
||||||
|
status_code=404,
|
||||||
|
)
|
||||||
|
mock_request.get(
|
||||||
|
"https://api.wall-box.com/chargers/status/12345",
|
||||||
|
json=test_response,
|
||||||
|
status_code=200,
|
||||||
|
)
|
||||||
|
|
||||||
|
wallbox = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
|
await wallbox.async_refresh()
|
||||||
|
|
||||||
|
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||||
|
assert entry.state == ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_wallbox_refresh_failed_invalid_auth(
|
async def test_wallbox_refresh_failed_invalid_auth(
|
||||||
hass: HomeAssistant, entry: MockConfigEntry
|
hass: HomeAssistant, entry: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user