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