mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Clean up webostv tests (#64833)
This commit is contained in:
parent
7112c5b52a
commit
6ed60d2b32
@ -33,13 +33,13 @@ CHANNEL_2 = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def setup_webostv(hass, unique_id="some-unique-id"):
|
async def setup_webostv(hass, unique_id=FAKE_UUID):
|
||||||
"""Initialize webostv and media_player for tests."""
|
"""Initialize webostv and media_player for tests."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
CONF_HOST: HOST,
|
CONF_HOST: HOST,
|
||||||
CONF_CLIENT_SECRET: "0123456789",
|
CONF_CLIENT_SECRET: CLIENT_KEY,
|
||||||
},
|
},
|
||||||
title=TV_NAME,
|
title=TV_NAME,
|
||||||
unique_id=unique_id,
|
unique_id=unique_id,
|
||||||
|
@ -6,7 +6,7 @@ import pytest
|
|||||||
from homeassistant.components.webostv.const import LIVE_TV_APP_ID
|
from homeassistant.components.webostv.const import LIVE_TV_APP_ID
|
||||||
from homeassistant.helpers import entity_registry
|
from homeassistant.helpers import entity_registry
|
||||||
|
|
||||||
from . import CHANNEL_1, CHANNEL_2, FAKE_UUID
|
from . import CHANNEL_1, CHANNEL_2, CLIENT_KEY, FAKE_UUID
|
||||||
|
|
||||||
from tests.common import async_mock_service
|
from tests.common import async_mock_service
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ def client_fixture():
|
|||||||
client.hello_info = {"deviceUUID": FAKE_UUID}
|
client.hello_info = {"deviceUUID": FAKE_UUID}
|
||||||
client.software_info = {"major_ver": "major", "minor_ver": "minor"}
|
client.software_info = {"major_ver": "major", "minor_ver": "minor"}
|
||||||
client.system_info = {"modelName": "TVFAKE"}
|
client.system_info = {"modelName": "TVFAKE"}
|
||||||
client.client_key = "0123456789"
|
client.client_key = CLIENT_KEY
|
||||||
client.apps = {
|
client.apps = {
|
||||||
LIVE_TV_APP_ID: {
|
LIVE_TV_APP_ID: {
|
||||||
"title": "Live TV",
|
"title": "Live TV",
|
||||||
@ -65,19 +65,19 @@ def client_entity_removed_fixture(hass):
|
|||||||
"homeassistant.components.webostv.WebOsClient", autospec=True
|
"homeassistant.components.webostv.WebOsClient", autospec=True
|
||||||
) as mock_client_class:
|
) as mock_client_class:
|
||||||
client = mock_client_class.return_value
|
client = mock_client_class.return_value
|
||||||
client.hello_info = {"deviceUUID": "some-fake-uuid"}
|
client.hello_info = {"deviceUUID": FAKE_UUID}
|
||||||
client.connected = False
|
client.connected = False
|
||||||
|
|
||||||
def mock_is_conneted():
|
def mock_is_connected():
|
||||||
return client.connected
|
return client.connected
|
||||||
|
|
||||||
client.is_connected = Mock(side_effect=mock_is_conneted)
|
client.is_connected = Mock(side_effect=mock_is_connected)
|
||||||
|
|
||||||
async def mock_conneted():
|
async def mock_connected():
|
||||||
ent_reg = entity_registry.async_get(hass)
|
ent_reg = entity_registry.async_get(hass)
|
||||||
ent_reg.async_remove("media_player.webostv_some_secret")
|
ent_reg.async_remove("media_player.webostv_some_secret")
|
||||||
client.connected = True
|
client.connected = True
|
||||||
|
|
||||||
client.connect = AsyncMock(side_effect=mock_conneted)
|
client.connect = AsyncMock(side_effect=mock_connected)
|
||||||
|
|
||||||
yield client
|
yield client
|
||||||
|
@ -24,23 +24,23 @@ from homeassistant.data_entry_flow import (
|
|||||||
RESULT_TYPE_FORM,
|
RESULT_TYPE_FORM,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import setup_webostv
|
from . import CLIENT_KEY, FAKE_UUID, HOST, TV_NAME, setup_webostv
|
||||||
|
|
||||||
MOCK_YAML_CONFIG = {
|
MOCK_YAML_CONFIG = {
|
||||||
CONF_HOST: "1.2.3.4",
|
CONF_HOST: HOST,
|
||||||
CONF_NAME: "fake",
|
CONF_NAME: TV_NAME,
|
||||||
CONF_ICON: "mdi:test",
|
CONF_ICON: "mdi:test",
|
||||||
CONF_CLIENT_SECRET: "some-secret",
|
CONF_CLIENT_SECRET: CLIENT_KEY,
|
||||||
CONF_UNIQUE_ID: "fake-uuid",
|
CONF_UNIQUE_ID: FAKE_UUID,
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo(
|
MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo(
|
||||||
ssdp_usn="mock_usn",
|
ssdp_usn="mock_usn",
|
||||||
ssdp_st="mock_st",
|
ssdp_st="mock_st",
|
||||||
ssdp_location="http://1.2.3.4",
|
ssdp_location=f"http://{HOST}",
|
||||||
upnp={
|
upnp={
|
||||||
ssdp.ATTR_UPNP_FRIENDLY_NAME: "LG Webostv",
|
ssdp.ATTR_UPNP_FRIENDLY_NAME: "LG Webostv",
|
||||||
ssdp.ATTR_UPNP_UDN: "uuid:some-fake-uuid",
|
ssdp.ATTR_UPNP_UDN: f"uuid:{FAKE_UUID}",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ async def test_import(hass, client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == "fake"
|
assert result["title"] == TV_NAME
|
||||||
assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST]
|
assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST]
|
||||||
assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET]
|
assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET]
|
||||||
assert result["result"].unique_id == MOCK_YAML_CONFIG[CONF_UNIQUE_ID]
|
assert result["result"].unique_id == MOCK_YAML_CONFIG[CONF_UNIQUE_ID]
|
||||||
@ -98,7 +98,7 @@ async def test_import_sources(hass, client, sources):
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == "fake"
|
assert result["title"] == TV_NAME
|
||||||
assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST]
|
assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST]
|
||||||
assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET]
|
assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET]
|
||||||
assert result["options"][CONF_SOURCES] == ["Live TV", "Input01", "Input02"]
|
assert result["options"][CONF_SOURCES] == ["Live TV", "Input01", "Input02"]
|
||||||
@ -146,7 +146,7 @@ async def test_form(hass, client):
|
|||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
|
||||||
assert result["title"] == "fake"
|
assert result["title"] == TV_NAME
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow(hass, client):
|
async def test_options_flow(hass, client):
|
||||||
@ -305,7 +305,7 @@ async def test_form_abort_uuid_configured(hass, client):
|
|||||||
entry = await setup_webostv(hass, MOCK_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN][5:])
|
entry = await setup_webostv(hass, MOCK_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN][5:])
|
||||||
assert client
|
assert client
|
||||||
assert entry.unique_id == MOCK_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN][5:]
|
assert entry.unique_id == MOCK_DISCOVERY_INFO[ssdp.ATTR_UPNP_UDN][5:]
|
||||||
assert entry.data[CONF_HOST] == "1.2.3.4"
|
assert entry.data[CONF_HOST] == HOST
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
@ -318,7 +318,7 @@ async def test_form_abort_uuid_configured(hass, client):
|
|||||||
|
|
||||||
user_config = {
|
user_config = {
|
||||||
CONF_HOST: "new_host",
|
CONF_HOST: "new_host",
|
||||||
CONF_NAME: "fake",
|
CONF_NAME: TV_NAME,
|
||||||
}
|
}
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
@ -11,17 +11,17 @@ from homeassistant.exceptions import HomeAssistantError
|
|||||||
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import ENTITY_ID, setup_webostv
|
from . import ENTITY_ID, FAKE_UUID, setup_webostv
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, async_get_device_automations
|
from tests.common import MockConfigEntry, async_get_device_automations
|
||||||
|
|
||||||
|
|
||||||
async def test_get_triggers(hass, client):
|
async def test_get_triggers(hass, client):
|
||||||
"""Test we get the expected triggers."""
|
"""Test we get the expected triggers."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
device_reg = get_dev_reg(hass)
|
device_reg = get_dev_reg(hass)
|
||||||
device = device_reg.async_get_device(identifiers={(DOMAIN, "fake-uuid")})
|
device = device_reg.async_get_device(identifiers={(DOMAIN, FAKE_UUID)})
|
||||||
|
|
||||||
turn_on_trigger = {
|
turn_on_trigger = {
|
||||||
"platform": "device",
|
"platform": "device",
|
||||||
@ -36,10 +36,10 @@ async def test_get_triggers(hass, client):
|
|||||||
|
|
||||||
async def test_if_fires_on_turn_on_request(hass, calls, client):
|
async def test_if_fires_on_turn_on_request(hass, calls, client):
|
||||||
"""Test for turn_on and turn_off triggers firing."""
|
"""Test for turn_on and turn_off triggers firing."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
device_reg = get_dev_reg(hass)
|
device_reg = get_dev_reg(hass)
|
||||||
device = device_reg.async_get_device(identifiers={(DOMAIN, "fake-uuid")})
|
device = device_reg.async_get_device(identifiers={(DOMAIN, FAKE_UUID)})
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -130,7 +130,7 @@ async def test_get_triggers_for_invalid_device_id(hass, caplog):
|
|||||||
|
|
||||||
async def test_failure_scenarios(hass, client):
|
async def test_failure_scenarios(hass, client):
|
||||||
"""Test failure scenarios."""
|
"""Test failure scenarios."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
# Test wrong trigger platform type
|
# Test wrong trigger platform type
|
||||||
with pytest.raises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
|
@ -17,7 +17,7 @@ MESSAGE = "one, two, testing, testing"
|
|||||||
|
|
||||||
async def test_notify(hass, client):
|
async def test_notify(hass, client):
|
||||||
"""Test sending a message."""
|
"""Test sending a message."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -38,7 +38,7 @@ async def test_notify(hass, client):
|
|||||||
|
|
||||||
async def test_notify_not_connected(hass, client, monkeypatch):
|
async def test_notify_not_connected(hass, client, monkeypatch):
|
||||||
"""Test sending a message when client is not connected."""
|
"""Test sending a message when client is not connected."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
|
||||||
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
||||||
@ -60,7 +60,7 @@ async def test_notify_not_connected(hass, client, monkeypatch):
|
|||||||
|
|
||||||
async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
||||||
"""Test notify icon not found error."""
|
"""Test notify icon not found error."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME)
|
||||||
|
|
||||||
monkeypatch.setattr(client, "send_message", Mock(side_effect=FileNotFoundError))
|
monkeypatch.setattr(client, "send_message", Mock(side_effect=FileNotFoundError))
|
||||||
@ -90,7 +90,7 @@ async def test_icon_not_found(hass, caplog, client, monkeypatch):
|
|||||||
)
|
)
|
||||||
async def test_connection_errors(hass, caplog, client, monkeypatch, side_effect, error):
|
async def test_connection_errors(hass, caplog, client, monkeypatch, side_effect, error):
|
||||||
"""Test connection errors scenarios."""
|
"""Test connection errors scenarios."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
assert hass.services.has_service("notify", TV_NAME)
|
assert hass.services.has_service("notify", TV_NAME)
|
||||||
|
|
||||||
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
monkeypatch.setattr(client, "is_connected", Mock(return_value=False))
|
||||||
|
@ -7,17 +7,17 @@ from homeassistant.const import SERVICE_RELOAD
|
|||||||
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
from homeassistant.helpers.device_registry import async_get as get_dev_reg
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import ENTITY_ID, setup_webostv
|
from . import ENTITY_ID, FAKE_UUID, setup_webostv
|
||||||
|
|
||||||
from tests.common import MockEntity, MockEntityPlatform
|
from tests.common import MockEntity, MockEntityPlatform
|
||||||
|
|
||||||
|
|
||||||
async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
|
async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
|
||||||
"""Test for turn_on triggers by device_id firing."""
|
"""Test for turn_on triggers by device_id firing."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
device_reg = get_dev_reg(hass)
|
device_reg = get_dev_reg(hass)
|
||||||
device = device_reg.async_get_device(identifiers={(DOMAIN, "fake-uuid")})
|
device = device_reg.async_get_device(identifiers={(DOMAIN, FAKE_UUID)})
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -71,7 +71,7 @@ async def test_webostv_turn_on_trigger_device_id(hass, calls, client):
|
|||||||
|
|
||||||
async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
|
async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
|
||||||
"""Test for turn_on triggers by entity_id firing."""
|
"""Test for turn_on triggers by entity_id firing."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -110,7 +110,7 @@ async def test_webostv_turn_on_trigger_entity_id(hass, calls, client):
|
|||||||
|
|
||||||
async def test_wrong_trigger_platform_type(hass, caplog, client):
|
async def test_wrong_trigger_platform_type(hass, caplog, client):
|
||||||
"""Test wrong trigger platform type."""
|
"""Test wrong trigger platform type."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
@ -142,7 +142,7 @@ async def test_wrong_trigger_platform_type(hass, caplog, client):
|
|||||||
|
|
||||||
async def test_trigger_invalid_entity_id(hass, caplog, client):
|
async def test_trigger_invalid_entity_id(hass, caplog, client):
|
||||||
"""Test turn on trigger using invalid entity_id."""
|
"""Test turn on trigger using invalid entity_id."""
|
||||||
await setup_webostv(hass, "fake-uuid")
|
await setup_webostv(hass)
|
||||||
|
|
||||||
platform = MockEntityPlatform(hass)
|
platform = MockEntityPlatform(hass)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user