mirror of
https://github.com/home-assistant/core.git
synced 2025-07-31 17:18:23 +00:00
Adjust tessie tests
This commit is contained in:
parent
8e2011a100
commit
8a7123b880
@ -32,21 +32,41 @@ TEST_REQUEST_INFO = RequestInfo(
|
||||
url=TESSIE_URL, method="GET", headers={}, real_url=TESSIE_URL
|
||||
)
|
||||
|
||||
ERROR_AUTH = ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.UNAUTHORIZED
|
||||
)
|
||||
ERROR_TIMEOUT = ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.REQUEST_TIMEOUT
|
||||
)
|
||||
ERROR_UNKNOWN = ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.BAD_REQUEST
|
||||
)
|
||||
ERROR_VIRTUAL_KEY = ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO,
|
||||
history=None,
|
||||
status=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
ERROR_CONNECTION = ClientConnectionError()
|
||||
|
||||
def error_auth() -> ClientResponseError:
|
||||
"""Return an error."""
|
||||
return ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.UNAUTHORIZED
|
||||
)
|
||||
|
||||
|
||||
def error_timeout() -> ClientResponseError:
|
||||
"""Return an error."""
|
||||
return ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.REQUEST_TIMEOUT
|
||||
)
|
||||
|
||||
|
||||
def error_unknown() -> ClientResponseError:
|
||||
"""Return an error."""
|
||||
return ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO, history=None, status=HTTPStatus.BAD_REQUEST
|
||||
)
|
||||
|
||||
|
||||
def error_virtual_key() -> ClientResponseError:
|
||||
"""Return an error."""
|
||||
return ClientResponseError(
|
||||
request_info=TEST_REQUEST_INFO,
|
||||
history=None,
|
||||
status=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
|
||||
def error_connection() -> ClientResponseError:
|
||||
"""Return an error."""
|
||||
return ClientConnectionError()
|
||||
|
||||
|
||||
# Fleet API library
|
||||
PRODUCTS = load_json_object_fixture("products.json", DOMAIN)
|
||||
|
@ -22,7 +22,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import ERROR_UNKNOWN, TEST_RESPONSE, assert_entities, setup_platform
|
||||
from .common import TEST_RESPONSE, assert_entities, error_unknown, setup_platform
|
||||
|
||||
|
||||
async def test_climate(
|
||||
@ -115,10 +115,11 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
entity_id = "climate.test_climate"
|
||||
|
||||
# Test setting climate on with unknown error
|
||||
exc = error_unknown()
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tessie.climate.stop_climate",
|
||||
side_effect=ERROR_UNKNOWN,
|
||||
side_effect=exc,
|
||||
) as mock_set,
|
||||
pytest.raises(HomeAssistantError) as error,
|
||||
):
|
||||
@ -129,4 +130,4 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
mock_set.assert_called_once()
|
||||
assert error.value.__cause__ == ERROR_UNKNOWN
|
||||
assert error.value.__cause__ == exc
|
||||
|
@ -11,11 +11,11 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .common import (
|
||||
ERROR_AUTH,
|
||||
ERROR_CONNECTION,
|
||||
ERROR_UNKNOWN,
|
||||
TEST_CONFIG,
|
||||
TEST_STATE_OF_ALL_VEHICLES,
|
||||
error_auth,
|
||||
error_connection,
|
||||
error_unknown,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -97,9 +97,9 @@ async def test_abort(
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error"),
|
||||
[
|
||||
(ERROR_AUTH, {CONF_ACCESS_TOKEN: "invalid_access_token"}),
|
||||
(ERROR_UNKNOWN, {"base": "unknown"}),
|
||||
(ERROR_CONNECTION, {"base": "cannot_connect"}),
|
||||
(error_auth(), {CONF_ACCESS_TOKEN: "invalid_access_token"}),
|
||||
(error_unknown(), {"base": "unknown"}),
|
||||
(error_connection(), {"base": "cannot_connect"}),
|
||||
],
|
||||
)
|
||||
async def test_form_errors(
|
||||
@ -165,9 +165,9 @@ async def test_reauth(
|
||||
@pytest.mark.parametrize(
|
||||
("side_effect", "error"),
|
||||
[
|
||||
(ERROR_AUTH, {CONF_ACCESS_TOKEN: "invalid_access_token"}),
|
||||
(ERROR_UNKNOWN, {"base": "unknown"}),
|
||||
(ERROR_CONNECTION, {"base": "cannot_connect"}),
|
||||
(error_auth(), {CONF_ACCESS_TOKEN: "invalid_access_token"}),
|
||||
(error_unknown(), {"base": "unknown"}),
|
||||
(error_connection(), {"base": "cannot_connect"}),
|
||||
],
|
||||
)
|
||||
async def test_reauth_errors(
|
||||
|
@ -15,10 +15,10 @@ from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import (
|
||||
ERROR_AUTH,
|
||||
ERROR_CONNECTION,
|
||||
ERROR_UNKNOWN,
|
||||
TEST_VEHICLE_STATUS_ASLEEP,
|
||||
error_auth,
|
||||
error_connection,
|
||||
error_unknown,
|
||||
setup_platform,
|
||||
)
|
||||
|
||||
@ -62,7 +62,7 @@ async def test_coordinator_clienterror(
|
||||
) -> None:
|
||||
"""Tests that the coordinator handles client errors."""
|
||||
|
||||
mock_get_status.side_effect = ERROR_UNKNOWN
|
||||
mock_get_status.side_effect = error_unknown()
|
||||
await setup_platform(hass, [Platform.BINARY_SENSOR])
|
||||
|
||||
freezer.tick(WAIT)
|
||||
@ -77,7 +77,7 @@ async def test_coordinator_auth(
|
||||
) -> None:
|
||||
"""Tests that the coordinator handles auth errors."""
|
||||
|
||||
mock_get_status.side_effect = ERROR_AUTH
|
||||
mock_get_status.side_effect = error_auth()
|
||||
await setup_platform(hass, [Platform.BINARY_SENSOR])
|
||||
|
||||
freezer.tick(WAIT)
|
||||
@ -91,7 +91,7 @@ async def test_coordinator_connection(
|
||||
) -> None:
|
||||
"""Tests that the coordinator handles connection errors."""
|
||||
|
||||
mock_get_status.side_effect = ERROR_CONNECTION
|
||||
mock_get_status.side_effect = error_connection()
|
||||
await setup_platform(hass, [Platform.BINARY_SENSOR])
|
||||
freezer.tick(WAIT)
|
||||
async_fire_time_changed(hass)
|
||||
|
@ -17,10 +17,10 @@ from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import (
|
||||
ERROR_UNKNOWN,
|
||||
TEST_RESPONSE,
|
||||
TEST_RESPONSE_ERROR,
|
||||
assert_entities,
|
||||
error_unknown,
|
||||
setup_platform,
|
||||
)
|
||||
|
||||
@ -81,10 +81,11 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
entity_id = "cover.test_charge_port_door"
|
||||
|
||||
# Test setting cover open with unknown error
|
||||
exc = error_unknown()
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tessie.cover.open_unlock_charge_port",
|
||||
side_effect=ERROR_UNKNOWN,
|
||||
side_effect=exc,
|
||||
) as mock_set,
|
||||
pytest.raises(HomeAssistantError) as error,
|
||||
):
|
||||
@ -95,7 +96,7 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
mock_set.assert_called_once()
|
||||
assert error.value.__cause__ == ERROR_UNKNOWN
|
||||
assert error.value.__cause__ == exc
|
||||
|
||||
# Test setting cover open with unknown error
|
||||
with (
|
||||
|
@ -7,7 +7,7 @@ from tesla_fleet_api.exceptions import TeslaFleetError
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .common import ERROR_AUTH, ERROR_CONNECTION, ERROR_UNKNOWN, setup_platform
|
||||
from .common import error_auth, error_connection, error_unknown, setup_platform
|
||||
|
||||
|
||||
async def test_load_unload(hass: HomeAssistant) -> None:
|
||||
@ -25,7 +25,7 @@ async def test_auth_failure(
|
||||
) -> None:
|
||||
"""Test init with an authentication error."""
|
||||
|
||||
mock_get_state_of_all_vehicles.side_effect = ERROR_AUTH
|
||||
mock_get_state_of_all_vehicles.side_effect = error_auth()
|
||||
entry = await setup_platform(hass)
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
@ -35,7 +35,7 @@ async def test_unknown_failure(
|
||||
) -> None:
|
||||
"""Test init with an client response error."""
|
||||
|
||||
mock_get_state_of_all_vehicles.side_effect = ERROR_UNKNOWN
|
||||
mock_get_state_of_all_vehicles.side_effect = error_unknown()
|
||||
entry = await setup_platform(hass)
|
||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
||||
|
||||
@ -45,7 +45,7 @@ async def test_connection_failure(
|
||||
) -> None:
|
||||
"""Test init with a network connection error."""
|
||||
|
||||
mock_get_state_of_all_vehicles.side_effect = ERROR_CONNECTION
|
||||
mock_get_state_of_all_vehicles.side_effect = error_connection()
|
||||
entry = await setup_platform(hass)
|
||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
@ -20,7 +20,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .common import ERROR_UNKNOWN, TEST_RESPONSE, assert_entities, setup_platform
|
||||
from .common import TEST_RESPONSE, assert_entities, error_unknown, setup_platform
|
||||
|
||||
|
||||
async def test_select(
|
||||
@ -107,10 +107,11 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
await setup_platform(hass, [Platform.SELECT])
|
||||
|
||||
# Test changing vehicle select with unknown error
|
||||
exc = error_unknown()
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.tessie.select.set_seat_heat",
|
||||
side_effect=ERROR_UNKNOWN,
|
||||
side_effect=exc,
|
||||
) as mock_set,
|
||||
pytest.raises(HomeAssistantError) as error,
|
||||
):
|
||||
@ -124,7 +125,7 @@ async def test_errors(hass: HomeAssistant) -> None:
|
||||
blocking=True,
|
||||
)
|
||||
mock_set.assert_called_once()
|
||||
assert error.value.__cause__ == ERROR_UNKNOWN
|
||||
assert error.value.__cause__ == exc
|
||||
|
||||
# Test changing energy select with unknown error
|
||||
with (
|
||||
|
Loading…
x
Reference in New Issue
Block a user