Add tests for Roku (#34380)

This commit is contained in:
Chris Talkington authored and GitHub committed 2020-04-18 17:23:55 -05:00
1 parent 3b12fd22a4
commit b3eba49a2f
13 files changed
+520 -105

No files matched your search

+34 -24
View File
@@ -1,49 +1,59 @@
"""Tests for the Roku component."""
from requests_mock import Mocker
from homeassistant.components.roku.const import DOMAIN
from homeassistant.const import CONF_HOST
from homeassistant.helpers.typing import HomeAssistantType
from tests.common import MockConfigEntry
from tests.common import MockConfigEntry, load_fixture
HOST = "1.2.3.4"
HOST = "192.168.1.160"
NAME = "Roku 3"
SSDP_LOCATION = "http://1.2.3.4/"
SSDP_LOCATION = "http://192.168.1.160/"
UPNP_FRIENDLY_NAME = "My Roku 3"
UPNP_SERIAL = "1GU48T017973"
class MockDeviceInfo:
"""Mock DeviceInfo for Roku."""
def mock_connection(
requests_mocker: Mocker, device: str = "roku3", app: str = "roku", host: str = HOST,
) -> None:
"""Mock the Roku connection."""
roku_url = f"http://{host}:8060"
model_name = NAME
model_num = "4200X"
software_version = "7.5.0.09021"
serial_num = UPNP_SERIAL
user_device_name = UPNP_FRIENDLY_NAME
roku_type = "Box"
requests_mocker.get(
f"{roku_url}/query/device-info",
text=load_fixture(f"roku/{device}-device-info.xml"),
)
def __repr__(self):
"""Return the object representation of DeviceInfo."""
return "<DeviceInfo: {}-{}, SW v{}, Ser# {} ({})>".format(
self.model_name,
self.model_num,
self.software_version,
self.serial_num,
self.roku_type,
)
apps_fixture = "roku/apps.xml"
if device == "rokutv":
apps_fixture = "roku/apps-tv.xml"
requests_mocker.get(
f"{roku_url}/query/apps", text=load_fixture(apps_fixture),
)
requests_mocker.get(
f"{roku_url}/query/active-app", text=load_fixture(f"roku/active-app-{app}.xml"),
)
async def setup_integration(
hass: HomeAssistantType, skip_entry_setup: bool = False
hass: HomeAssistantType,
requests_mocker: Mocker,
device: str = "roku3",
app: str = "roku",
host: str = HOST,
unique_id: str = UPNP_SERIAL,
skip_entry_setup: bool = False,
) -> MockConfigEntry:
"""Set up the Roku integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN, unique_id=UPNP_SERIAL, data={CONF_HOST: HOST}
)
entry = MockConfigEntry(domain=DOMAIN, unique_id=unique_id, data={CONF_HOST: host})
entry.add_to_hass(hass)
if not skip_entry_setup:
mock_connection(requests_mocker, device, app=app, host=host)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()