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,28 +29,24 @@ 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_STATUS_ID_KEY: 193,
|
||||||
CHARGER_CHARGING_POWER_KEY: 0,
|
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
|
||||||
CHARGER_STATUS_ID_KEY: 193,
|
CHARGER_CHARGING_SPEED_KEY: 0,
|
||||||
CHARGER_MAX_AVAILABLE_POWER_KEY: 25.0,
|
CHARGER_ADDED_RANGE_KEY: 150,
|
||||||
CHARGER_CHARGING_SPEED_KEY: 0,
|
CHARGER_ADDED_ENERGY_KEY: 44.697,
|
||||||
CHARGER_ADDED_RANGE_KEY: 150,
|
CHARGER_NAME_KEY: "WallboxName",
|
||||||
CHARGER_ADDED_ENERGY_KEY: 44.697,
|
CHARGER_DATA_KEY: {
|
||||||
CHARGER_NAME_KEY: "WallboxName",
|
CHARGER_MAX_CHARGING_CURRENT_KEY: 24,
|
||||||
CHARGER_DATA_KEY: {
|
CHARGER_ENERGY_PRICE_KEY: 0.4,
|
||||||
CHARGER_MAX_CHARGING_CURRENT_KEY: 24,
|
CHARGER_LOCKED_UNLOCKED_KEY: False,
|
||||||
CHARGER_ENERGY_PRICE_KEY: 0.4,
|
CHARGER_SERIAL_NUMBER_KEY: "20000",
|
||||||
CHARGER_LOCKED_UNLOCKED_KEY: False,
|
CHARGER_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E",
|
||||||
CHARGER_SERIAL_NUMBER_KEY: "20000",
|
CHARGER_SOFTWARE_KEY: {CHARGER_CURRENT_VERSION_KEY: "5.5.10"},
|
||||||
CHARGER_PART_NUMBER_KEY: "PLP1-0-2-4-9-002-E",
|
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
|
||||||
CHARGER_SOFTWARE_KEY: {CHARGER_CURRENT_VERSION_KEY: "5.5.10"},
|
},
|
||||||
CHARGER_CURRENCY_KEY: {"code": "EUR/kWh"},
|
}
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
test_response_bidir = {
|
test_response_bidir = {
|
||||||
CHARGER_CHARGING_POWER_KEY: 0,
|
CHARGER_CHARGING_POWER_KEY: 0,
|
||||||
@ -72,38 +68,30 @@ test_response_bidir = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
authorisation_response = json.loads(
|
authorisation_response = {
|
||||||
json.dumps(
|
"data": {
|
||||||
{
|
"attributes": {
|
||||||
"data": {
|
"token": "fakekeyhere",
|
||||||
"attributes": {
|
USER_ID: 12345,
|
||||||
"token": "fakekeyhere",
|
TTL: 145656758,
|
||||||
USER_ID: 12345,
|
ERROR: "false",
|
||||||
TTL: 145656758,
|
STATUS: 200,
|
||||||
ERROR: "false",
|
|
||||||
STATUS: 200,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
|
|
||||||
authorisation_response_unauthorised = json.loads(
|
authorisation_response_unauthorised = {
|
||||||
json.dumps(
|
"data": {
|
||||||
{
|
"attributes": {
|
||||||
"data": {
|
"token": "fakekeyhere",
|
||||||
"attributes": {
|
USER_ID: 12345,
|
||||||
"token": "fakekeyhere",
|
TTL: 145656758,
|
||||||
USER_ID: 12345,
|
ERROR: "false",
|
||||||
TTL: 145656758,
|
STATUS: 404,
|
||||||
ERROR: "false",
|
|
||||||
STATUS: 404,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
)
|
}
|
||||||
|
|
||||||
|
|
||||||
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