mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +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
|
||||
|
||||
test_response = json.loads(
|
||||
json.dumps(
|
||||
{
|
||||
test_response = {
|
||||
CHARGER_CHARGING_POWER_KEY: 0,
|
||||
CHARGER_STATUS_ID_KEY: 193,
|
||||
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
|
||||
@ -49,8 +47,6 @@ test_response = json.loads(
|
||||
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
|
||||
},
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
test_response_bidir = {
|
||||
CHARGER_CHARGING_POWER_KEY: 0,
|
||||
@ -72,9 +68,7 @@ test_response_bidir = {
|
||||
}
|
||||
|
||||
|
||||
authorisation_response = json.loads(
|
||||
json.dumps(
|
||||
{
|
||||
authorisation_response = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"token": "fakekeyhere",
|
||||
@ -85,13 +79,9 @@ authorisation_response = json.loads(
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
authorisation_response_unauthorised = json.loads(
|
||||
json.dumps(
|
||||
{
|
||||
authorisation_response_unauthorised = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"token": "fakekeyhere",
|
||||
@ -102,8 +92,6 @@ authorisation_response_unauthorised = json.loads(
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user