mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Update REST api mocking in SamsungTV (#68172)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
5eee600fa8
commit
de130d3b28
@ -731,11 +731,9 @@ async def test_ssdp_encrypted_websocket_not_supported(
|
||||
assert result["reason"] == RESULT_NOT_SUPPORTED
|
||||
|
||||
|
||||
async def test_ssdp_websocket_cannot_connect(
|
||||
hass: HomeAssistant, rest_api: Mock
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("rest_api_failing")
|
||||
async def test_ssdp_websocket_cannot_connect(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from discovery and we cannot connect."""
|
||||
rest_api.rest_device_info.return_value = None
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.Remote",
|
||||
side_effect=OSError("Boom"),
|
||||
@ -901,10 +899,9 @@ async def test_import_legacy(hass: HomeAssistant) -> None:
|
||||
assert entries[0].data[CONF_PORT] == LEGACY_PORT
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews")
|
||||
async def test_import_legacy_without_name(hass: HomeAssistant, rest_api: Mock) -> None:
|
||||
@pytest.mark.usefixtures("remote", "remotews", "rest_api_failing")
|
||||
async def test_import_legacy_without_name(hass: HomeAssistant) -> None:
|
||||
"""Test importing from yaml without a name."""
|
||||
rest_api.rest_device_info.return_value = None
|
||||
with patch(
|
||||
"homeassistant.components.samsungtv.bridge.SamsungTVEncryptedWSAsyncRemote.start_listening",
|
||||
side_effect=WebSocketProtocolError("Boom"),
|
||||
@ -1110,10 +1107,9 @@ async def test_zeroconf_ignores_soundbar(hass: HomeAssistant, rest_api: Mock) ->
|
||||
assert result["reason"] == "not_supported"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "remoteencws")
|
||||
async def test_zeroconf_no_device_info(hass: HomeAssistant, rest_api: Mock) -> None:
|
||||
@pytest.mark.usefixtures("remote", "remotews", "remoteencws", "rest_api_failing")
|
||||
async def test_zeroconf_no_device_info(hass: HomeAssistant) -> None:
|
||||
"""Test starting a flow from zeroconf where device_info returns None."""
|
||||
rest_api.rest_device_info.return_value = None
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||
|
@ -1,5 +1,4 @@
|
||||
"""Tests for the Samsung TV Integration."""
|
||||
from copy import deepcopy
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
@ -32,6 +31,7 @@ from .const import (
|
||||
MOCK_ENTRYDATA_WS,
|
||||
MOCK_SSDP_DATA_MAIN_TV_AGENT_ST,
|
||||
MOCK_SSDP_DATA_RENDERING_CONTROL_ST,
|
||||
SAMPLE_DEVICE_INFO_UE48JU6400,
|
||||
)
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
@ -68,12 +68,7 @@ REMOTE_CALL = {
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="autouse_rest_api", autouse=True)
|
||||
def autouse_rest_api(rest_api) -> Mock:
|
||||
"""Enable auto use of the rest api fixture for these tests."""
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing")
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
||||
async def test_setup(hass: HomeAssistant) -> None:
|
||||
"""Test Samsung TV integration is setup."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
@ -115,7 +110,7 @@ async def test_setup_from_yaml_without_port_device_offline(hass: HomeAssistant)
|
||||
assert config_entries_domain[0].state == ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing")
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
||||
async def test_setup_from_yaml_without_port_device_online(hass: HomeAssistant) -> None:
|
||||
"""Test import from yaml when the device is online."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
@ -144,7 +139,7 @@ async def test_setup_duplicate_config(
|
||||
assert "duplicate host entries found" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "remoteencws_failing")
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
||||
async def test_setup_duplicate_entries(hass: HomeAssistant) -> None:
|
||||
"""Test duplicate setup of platform."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
@ -160,9 +155,7 @@ async def test_setup_h_j_model(
|
||||
hass: HomeAssistant, rest_api: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test Samsung TV integration is setup."""
|
||||
device_info = deepcopy(rest_api.rest_device_info.return_value)
|
||||
device_info["device"]["modelName"] = "UE48JU6400"
|
||||
rest_api.rest_device_info.return_value = device_info
|
||||
rest_api.rest_device_info.return_value = SAMPLE_DEVICE_INFO_UE48JU6400
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get(ENTITY_ID)
|
||||
@ -170,7 +163,7 @@ async def test_setup_h_j_model(
|
||||
assert "H and J series use an encrypted protocol" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remote", "remotews", "remoteencws_failing")
|
||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
||||
async def test_setup_updates_from_ssdp(hass: HomeAssistant) -> None:
|
||||
"""Test setting up the entry fetches data from ssdp cache."""
|
||||
entry = MockConfigEntry(domain="samsungtv", data=MOCK_ENTRYDATA_WS)
|
||||
|
@ -88,6 +88,7 @@ from . import (
|
||||
from .const import (
|
||||
MOCK_ENTRYDATA_ENCRYPTED_WS,
|
||||
SAMPLE_DEVICE_INFO_FRAME,
|
||||
SAMPLE_DEVICE_INFO_WIFI,
|
||||
SAMPLE_EVENT_ED_INSTALLED_APP,
|
||||
)
|
||||
|
||||
@ -153,11 +154,6 @@ MOCK_CONFIG_NOTURNON = {
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(name="autouse_rest_api", autouse=True)
|
||||
def autouse_rest_api(rest_api) -> Mock:
|
||||
"""Enable auto use of the rest api fixture for these tests."""
|
||||
|
||||
|
||||
@pytest.fixture(name="delay")
|
||||
def delay_fixture():
|
||||
"""Patch the delay script function."""
|
||||
@ -187,7 +183,7 @@ async def test_setup_without_turnon(hass: HomeAssistant) -> None:
|
||||
assert hass.states.get(ENTITY_ID_NOTURNON)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews")
|
||||
@pytest.mark.usefixtures("remotews", "rest_api")
|
||||
async def test_setup_websocket(hass: HomeAssistant) -> None:
|
||||
"""Test setup of platform."""
|
||||
with patch(
|
||||
@ -212,6 +208,7 @@ async def test_setup_websocket(hass: HomeAssistant) -> None:
|
||||
assert config_entries[0].data[CONF_MAC] == "aa:bb:ww:ii:ff:ii"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_setup_websocket_2(hass: HomeAssistant, mock_now: datetime) -> None:
|
||||
"""Test setup of platform from config entry."""
|
||||
entity_id = f"{DOMAIN}.fake"
|
||||
@ -250,6 +247,7 @@ async def test_setup_websocket_2(hass: HomeAssistant, mock_now: datetime) -> Non
|
||||
remote_class.assert_called_once_with(**MOCK_CALLS_WS)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_setup_encrypted_websocket(
|
||||
hass: HomeAssistant, mock_now: datetime
|
||||
) -> None:
|
||||
@ -351,7 +349,7 @@ async def test_update_off_ws_with_power_state(
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# First update uses start_listening once, and initialises device_info
|
||||
device_info = deepcopy(rest_api.rest_device_info.return_value)
|
||||
device_info = deepcopy(SAMPLE_DEVICE_INFO_WIFI)
|
||||
device_info["device"]["PowerState"] = "on"
|
||||
rest_api.rest_device_info.return_value = device_info
|
||||
next_update = mock_now + timedelta(minutes=1)
|
||||
@ -447,6 +445,7 @@ async def test_update_access_denied(hass: HomeAssistant, mock_now: datetime) ->
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_update_ws_connection_failure(
|
||||
hass: HomeAssistant,
|
||||
mock_now: datetime,
|
||||
@ -476,6 +475,7 @@ async def test_update_ws_connection_failure(
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_update_ws_connection_closed(
|
||||
hass: HomeAssistant, mock_now: datetime, remotews: Mock
|
||||
) -> None:
|
||||
@ -494,6 +494,7 @@ async def test_update_ws_connection_closed(
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_update_ws_unauthorized_error(
|
||||
hass: HomeAssistant, mock_now: datetime, remotews: Mock
|
||||
) -> None:
|
||||
@ -627,6 +628,7 @@ async def test_send_key_unhandled_response(hass: HomeAssistant, remote: Mock) ->
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_send_key_websocketexception(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
"""Testing unhandled response exception."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIGWS)
|
||||
@ -638,6 +640,7 @@ async def test_send_key_websocketexception(hass: HomeAssistant, remotews: Mock)
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_send_key_websocketexception_encrypted(
|
||||
hass: HomeAssistant, remoteencws: Mock
|
||||
) -> None:
|
||||
@ -651,6 +654,7 @@ async def test_send_key_websocketexception_encrypted(
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_send_key_os_error_ws(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
"""Testing unhandled response exception."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIGWS)
|
||||
@ -662,6 +666,7 @@ async def test_send_key_os_error_ws(hass: HomeAssistant, remotews: Mock) -> None
|
||||
assert state.state == STATE_ON
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_send_key_os_error_ws_encrypted(
|
||||
hass: HomeAssistant, remoteencws: Mock
|
||||
) -> None:
|
||||
@ -767,6 +772,7 @@ async def test_device_class(hass: HomeAssistant) -> None:
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] is MediaPlayerDeviceClass.TV.value
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_turn_off_websocket(
|
||||
hass: HomeAssistant, remotews: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -924,6 +930,7 @@ async def test_turn_off_os_error(
|
||||
assert "Could not establish connection" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_turn_off_ws_os_error(
|
||||
hass: HomeAssistant, remotews: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -937,6 +944,7 @@ async def test_turn_off_ws_os_error(
|
||||
assert "Error closing connection" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_turn_off_encryptedws_os_error(
|
||||
hass: HomeAssistant, remoteencws: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -1072,7 +1080,7 @@ async def test_turn_on_with_turnon(hass: HomeAssistant, delay: Mock) -> None:
|
||||
assert delay.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews")
|
||||
@pytest.mark.usefixtures("remotews", "rest_api")
|
||||
async def test_turn_on_wol(hass: HomeAssistant) -> None:
|
||||
"""Test turn on."""
|
||||
entry = MockConfigEntry(
|
||||
@ -1229,6 +1237,7 @@ async def test_select_source_invalid_source(hass: HomeAssistant) -> None:
|
||||
assert remote.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_play_media_app(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
"""Test for play_media."""
|
||||
await setup_samsungtv(hass, MOCK_CONFIGWS)
|
||||
@ -1251,6 +1260,7 @@ async def test_play_media_app(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
assert commands[0].params["data"]["appId"] == "3201608010191"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_select_source_app(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
"""Test for select_source."""
|
||||
remotews.app_list_data = SAMPLE_EVENT_ED_INSTALLED_APP
|
||||
@ -1270,6 +1280,7 @@ async def test_select_source_app(hass: HomeAssistant, remotews: Mock) -> None:
|
||||
assert commands[0].params["data"]["appId"] == "3201608010191"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("rest_api")
|
||||
async def test_websocket_unsupported_remote_control(
|
||||
hass: HomeAssistant, remotews: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -1318,7 +1329,7 @@ async def test_websocket_unsupported_remote_control(
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews")
|
||||
@pytest.mark.usefixtures("remotews", "rest_api")
|
||||
async def test_volume_control_upnp(
|
||||
hass: HomeAssistant, upnp_device: Mock, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -1362,7 +1373,7 @@ async def test_volume_control_upnp(
|
||||
assert "Unable to set volume level on" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews")
|
||||
@pytest.mark.usefixtures("remotews", "rest_api")
|
||||
async def test_upnp_not_available(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
@ -1379,7 +1390,7 @@ async def test_upnp_not_available(
|
||||
assert "Upnp services are not available" in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("remotews", "upnp_device")
|
||||
@pytest.mark.usefixtures("remotews", "upnp_device", "rest_api")
|
||||
async def test_upnp_missing_service(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user