diff --git a/tests/components/webostv/__init__.py b/tests/components/webostv/__init__.py index 08855c0e273..d6e2505b96c 100644 --- a/tests/components/webostv/__init__.py +++ b/tests/components/webostv/__init__.py @@ -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.""" entry = MockConfigEntry( domain=DOMAIN, data={ CONF_HOST: HOST, - CONF_CLIENT_SECRET: "0123456789", + CONF_CLIENT_SECRET: CLIENT_KEY, }, title=TV_NAME, unique_id=unique_id, diff --git a/tests/components/webostv/conftest.py b/tests/components/webostv/conftest.py index a4d6b6d8e21..23c8687018c 100644 --- a/tests/components/webostv/conftest.py +++ b/tests/components/webostv/conftest.py @@ -6,7 +6,7 @@ import pytest from homeassistant.components.webostv.const import LIVE_TV_APP_ID 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 @@ -27,7 +27,7 @@ def client_fixture(): client.hello_info = {"deviceUUID": FAKE_UUID} client.software_info = {"major_ver": "major", "minor_ver": "minor"} client.system_info = {"modelName": "TVFAKE"} - client.client_key = "0123456789" + client.client_key = CLIENT_KEY client.apps = { LIVE_TV_APP_ID: { "title": "Live TV", @@ -65,19 +65,19 @@ def client_entity_removed_fixture(hass): "homeassistant.components.webostv.WebOsClient", autospec=True ) as mock_client_class: client = mock_client_class.return_value - client.hello_info = {"deviceUUID": "some-fake-uuid"} + client.hello_info = {"deviceUUID": FAKE_UUID} client.connected = False - def mock_is_conneted(): + def mock_is_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.async_remove("media_player.webostv_some_secret") client.connected = True - client.connect = AsyncMock(side_effect=mock_conneted) + client.connect = AsyncMock(side_effect=mock_connected) yield client diff --git a/tests/components/webostv/test_config_flow.py b/tests/components/webostv/test_config_flow.py index 89eb9768222..34e6d96bfdd 100644 --- a/tests/components/webostv/test_config_flow.py +++ b/tests/components/webostv/test_config_flow.py @@ -24,23 +24,23 @@ from homeassistant.data_entry_flow import ( RESULT_TYPE_FORM, ) -from . import setup_webostv +from . import CLIENT_KEY, FAKE_UUID, HOST, TV_NAME, setup_webostv MOCK_YAML_CONFIG = { - CONF_HOST: "1.2.3.4", - CONF_NAME: "fake", + CONF_HOST: HOST, + CONF_NAME: TV_NAME, CONF_ICON: "mdi:test", - CONF_CLIENT_SECRET: "some-secret", - CONF_UNIQUE_ID: "fake-uuid", + CONF_CLIENT_SECRET: CLIENT_KEY, + CONF_UNIQUE_ID: FAKE_UUID, } MOCK_DISCOVERY_INFO = ssdp.SsdpServiceInfo( ssdp_usn="mock_usn", ssdp_st="mock_st", - ssdp_location="http://1.2.3.4", + ssdp_location=f"http://{HOST}", upnp={ 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["title"] == "fake" + assert result["title"] == TV_NAME assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST] assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET] 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["title"] == "fake" + assert result["title"] == TV_NAME assert result["data"][CONF_HOST] == MOCK_YAML_CONFIG[CONF_HOST] assert result["data"][CONF_CLIENT_SECRET] == MOCK_YAML_CONFIG[CONF_CLIENT_SECRET] 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() assert result["type"] == RESULT_TYPE_CREATE_ENTRY - assert result["title"] == "fake" + assert result["title"] == TV_NAME 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:]) assert client 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( DOMAIN, @@ -318,7 +318,7 @@ async def test_form_abort_uuid_configured(hass, client): user_config = { CONF_HOST: "new_host", - CONF_NAME: "fake", + CONF_NAME: TV_NAME, } result = await hass.config_entries.flow.async_init( diff --git a/tests/components/webostv/test_device_trigger.py b/tests/components/webostv/test_device_trigger.py index 07106e42477..ef7c86327a8 100644 --- a/tests/components/webostv/test_device_trigger.py +++ b/tests/components/webostv/test_device_trigger.py @@ -11,17 +11,17 @@ from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.device_registry import async_get as get_dev_reg 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 async def test_get_triggers(hass, client): """Test we get the expected triggers.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(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 = { "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): """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 = device_reg.async_get_device(identifiers={(DOMAIN, "fake-uuid")}) + device = device_reg.async_get_device(identifiers={(DOMAIN, FAKE_UUID)}) assert await async_setup_component( hass, @@ -130,7 +130,7 @@ async def test_get_triggers_for_invalid_device_id(hass, caplog): async def test_failure_scenarios(hass, client): """Test failure scenarios.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) # Test wrong trigger platform type with pytest.raises(HomeAssistantError): diff --git a/tests/components/webostv/test_notify.py b/tests/components/webostv/test_notify.py index 08dfa4a9a06..315ae6ac919 100644 --- a/tests/components/webostv/test_notify.py +++ b/tests/components/webostv/test_notify.py @@ -17,7 +17,7 @@ MESSAGE = "one, two, testing, testing" async def test_notify(hass, client): """Test sending a message.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) assert hass.services.has_service(NOTIFY_DOMAIN, TV_NAME) await hass.services.async_call( @@ -38,7 +38,7 @@ async def test_notify(hass, client): async def test_notify_not_connected(hass, client, monkeypatch): """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) 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): """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) 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): """Test connection errors scenarios.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) assert hass.services.has_service("notify", TV_NAME) monkeypatch.setattr(client, "is_connected", Mock(return_value=False)) diff --git a/tests/components/webostv/test_trigger.py b/tests/components/webostv/test_trigger.py index af4778d0fdc..f2fabe58ede 100644 --- a/tests/components/webostv/test_trigger.py +++ b/tests/components/webostv/test_trigger.py @@ -7,17 +7,17 @@ from homeassistant.const import SERVICE_RELOAD from homeassistant.helpers.device_registry import async_get as get_dev_reg 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 async def test_webostv_turn_on_trigger_device_id(hass, calls, client): """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 = device_reg.async_get_device(identifiers={(DOMAIN, "fake-uuid")}) + device = device_reg.async_get_device(identifiers={(DOMAIN, FAKE_UUID)}) assert await async_setup_component( 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): """Test for turn_on triggers by entity_id firing.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) assert await async_setup_component( 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): """Test wrong trigger platform type.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) await async_setup_component( 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): """Test turn on trigger using invalid entity_id.""" - await setup_webostv(hass, "fake-uuid") + await setup_webostv(hass) platform = MockEntityPlatform(hass)