Clean up test for Wallbox integration (#125433)
feat: Update API requests in wallbox integration testspull/125467/head
parent
066503b838
commit
6e38cf878e
|
@ -1,7 +1,6 @@
|
|||
"""Tests for the Wallbox integration."""
|
||||
|
||||
from http import HTTPStatus
|
||||
import json
|
||||
|
||||
import requests_mock
|
||||
|
||||
|
@ -121,7 +120,7 @@ async def setup_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
|
||||
|
@ -144,7 +143,7 @@ async def setup_integration_bidir(hass: HomeAssistant, entry: MockConfigEntry) -
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=HTTPStatus.OK,
|
||||
)
|
||||
|
||||
|
@ -169,7 +168,7 @@ async def setup_integration_connection_error(
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=HTTPStatus.FORBIDDEN,
|
||||
)
|
||||
|
||||
|
|
|
@ -186,7 +186,15 @@ async def test_form_reauth_invalid(hass: HomeAssistant, entry: MockConfigEntry)
|
|||
with requests_mock.Mocker() as mock_request:
|
||||
mock_request.get(
|
||||
"https://user-api.wall-box.com/users/signin",
|
||||
text='{"jwt":"fakekeyhere","refresh_token": "refresh_fakekeyhere","user_id":12345,"ttl":145656758,"refresh_token_ttl":145756758,"error":false,"status":200}',
|
||||
json={
|
||||
"jwt": "fakekeyhere",
|
||||
"refresh_token": "refresh_fakekeyhere",
|
||||
"user_id": 12345,
|
||||
"ttl": 145656758,
|
||||
"refresh_token_ttl": 145756758,
|
||||
"error": False,
|
||||
"status": 200,
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
mock_request.get(
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Test Wallbox Init Component."""
|
||||
|
||||
import json
|
||||
|
||||
import requests_mock
|
||||
|
||||
from homeassistant.components.wallbox.const import (
|
||||
|
@ -90,7 +88,7 @@ async def test_wallbox_refresh_failed_invalid_auth(
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=403,
|
||||
)
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Test Wallbox Lock component."""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
|
@ -38,7 +36,7 @@ async def test_wallbox_lock_class(hass: HomeAssistant, entry: MockConfigEntry) -
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_LOCKED_UNLOCKED_KEY: False})),
|
||||
json={CHARGER_LOCKED_UNLOCKED_KEY: False},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
@ -60,8 +58,6 @@ async def test_wallbox_lock_class(hass: HomeAssistant, entry: MockConfigEntry) -
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_lock_class_connection_error(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -78,7 +74,7 @@ async def test_wallbox_lock_class_connection_error(
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_LOCKED_UNLOCKED_KEY: False})),
|
||||
json={CHARGER_LOCKED_UNLOCKED_KEY: False},
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
|
@ -101,8 +97,6 @@ async def test_wallbox_lock_class_connection_error(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_lock_class_authentication_error(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -115,8 +109,6 @@ async def test_wallbox_lock_class_authentication_error(
|
|||
|
||||
assert state is None
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_lock_class_platform_not_ready(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -128,5 +120,3 @@ async def test_wallbox_lock_class_platform_not_ready(
|
|||
state = hass.states.get(MOCK_LOCK_ENTITY_ID)
|
||||
|
||||
assert state is None
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Test Wallbox Switch component."""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
|
@ -47,7 +45,7 @@ async def test_wallbox_number_class(
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=200,
|
||||
)
|
||||
state = hass.states.get(MOCK_NUMBER_ENTITY_ID)
|
||||
|
@ -63,7 +61,6 @@ async def test_wallbox_number_class(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_bidir(
|
||||
|
@ -76,7 +73,6 @@ async def test_wallbox_number_class_bidir(
|
|||
state = hass.states.get(MOCK_NUMBER_ENTITY_ID)
|
||||
assert state.attributes["min"] == -25
|
||||
assert state.attributes["max"] == 25
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_energy_class(
|
||||
|
@ -95,7 +91,7 @@ async def test_wallbox_number_energy_class(
|
|||
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/chargers/config/12345",
|
||||
json=json.loads(json.dumps({CHARGER_ENERGY_PRICE_KEY: 1.1})),
|
||||
json={CHARGER_ENERGY_PRICE_KEY: 1.1},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
@ -108,7 +104,6 @@ async def test_wallbox_number_energy_class(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_connection_error(
|
||||
|
@ -126,7 +121,7 @@ async def test_wallbox_number_class_connection_error(
|
|||
)
|
||||
mock_request.put(
|
||||
"https://api.wall-box.com/v2/charger/12345",
|
||||
json=json.loads(json.dumps({CHARGER_MAX_CHARGING_CURRENT_KEY: 20})),
|
||||
json={CHARGER_MAX_CHARGING_CURRENT_KEY: 20},
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
|
@ -140,7 +135,6 @@ async def test_wallbox_number_class_connection_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_energy_price_connection_error(
|
||||
|
@ -158,7 +152,7 @@ async def test_wallbox_number_class_energy_price_connection_error(
|
|||
)
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/chargers/config/12345",
|
||||
json=json.loads(json.dumps({CHARGER_ENERGY_PRICE_KEY: 1.1})),
|
||||
json={CHARGER_ENERGY_PRICE_KEY: 1.1},
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
|
@ -172,7 +166,6 @@ async def test_wallbox_number_class_energy_price_connection_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_energy_price_auth_error(
|
||||
|
@ -190,7 +183,7 @@ async def test_wallbox_number_class_energy_price_auth_error(
|
|||
)
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/chargers/config/12345",
|
||||
json=json.loads(json.dumps({CHARGER_ENERGY_PRICE_KEY: 1.1})),
|
||||
json={CHARGER_ENERGY_PRICE_KEY: 1.1},
|
||||
status_code=403,
|
||||
)
|
||||
|
||||
|
@ -204,7 +197,6 @@ async def test_wallbox_number_class_energy_price_auth_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_platform_not_ready(
|
||||
|
@ -218,8 +210,6 @@ async def test_wallbox_number_class_platform_not_ready(
|
|||
|
||||
assert state is None
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_icp_energy(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -250,7 +240,6 @@ async def test_wallbox_number_class_icp_energy(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_icp_energy_auth_error(
|
||||
|
@ -282,7 +271,6 @@ async def test_wallbox_number_class_icp_energy_auth_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_number_class_icp_energy_connection_error(
|
||||
|
@ -314,4 +302,3 @@ async def test_wallbox_number_class_icp_energy_connection_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
|
|
@ -30,5 +30,3 @@ async def test_wallbox_sensor_class(
|
|||
# Test round with precision '0' works
|
||||
state = hass.states.get(MOCK_SENSOR_MAX_AVAILABLE_POWER)
|
||||
assert state.state == "25.0"
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
"""Test Wallbox Lock component."""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import requests_mock
|
||||
|
||||
|
@ -36,7 +34,7 @@ async def test_wallbox_switch_class(
|
|||
)
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/v3/chargers/12345/remote-action",
|
||||
json=json.loads(json.dumps({CHARGER_STATUS_ID_KEY: 193})),
|
||||
json={CHARGER_STATUS_ID_KEY: 193},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
@ -58,8 +56,6 @@ async def test_wallbox_switch_class(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_switch_class_connection_error(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -76,7 +72,7 @@ async def test_wallbox_switch_class_connection_error(
|
|||
)
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/v3/chargers/12345/remote-action",
|
||||
json=json.loads(json.dumps({CHARGER_STATUS_ID_KEY: 193})),
|
||||
json={CHARGER_STATUS_ID_KEY: 193},
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
|
@ -99,8 +95,6 @@ async def test_wallbox_switch_class_connection_error(
|
|||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
||||
|
||||
async def test_wallbox_switch_class_authentication_error(
|
||||
hass: HomeAssistant, entry: MockConfigEntry
|
||||
|
@ -117,7 +111,7 @@ async def test_wallbox_switch_class_authentication_error(
|
|||
)
|
||||
mock_request.post(
|
||||
"https://api.wall-box.com/v3/chargers/12345/remote-action",
|
||||
json=json.loads(json.dumps({CHARGER_STATUS_ID_KEY: 193})),
|
||||
json={CHARGER_STATUS_ID_KEY: 193},
|
||||
status_code=403,
|
||||
)
|
||||
|
||||
|
@ -139,5 +133,3 @@ async def test_wallbox_switch_class_authentication_error(
|
|||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
await hass.config_entries.async_unload(entry.entry_id)
|
||||
|
|
Loading…
Reference in New Issue