Add tests for Roku (#34380)

This commit is contained in:
Chris Talkington 2020-04-18 17:23:55 -05:00 committed by GitHub
parent 3b12fd22a4
commit b3eba49a2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 520 additions and 105 deletions

View file

@ -3,6 +3,7 @@ from socket import gaierror as SocketGIAError
from asynctest import patch
from requests.exceptions import RequestException
from requests_mock import Mocker
from roku import RokuException
from homeassistant.components.roku.const import DOMAIN
@ -13,50 +14,56 @@ from homeassistant.config_entries import (
)
from homeassistant.helpers.typing import HomeAssistantType
from tests.components.roku import MockDeviceInfo, setup_integration
from tests.components.roku import setup_integration
async def test_config_entry_not_ready(hass: HomeAssistantType) -> None:
async def test_config_entry_not_ready(
hass: HomeAssistantType, requests_mock: Mocker
) -> None:
"""Test the Roku configuration entry not ready."""
with patch(
"homeassistant.components.roku.Roku._call", side_effect=RokuException,
):
entry = await setup_integration(hass)
entry = await setup_integration(hass, requests_mock)
assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_config_entry_not_ready_request(hass: HomeAssistantType) -> None:
async def test_config_entry_not_ready_request(
hass: HomeAssistantType, requests_mock: Mocker
) -> None:
"""Test the Roku configuration entry not ready."""
with patch(
"homeassistant.components.roku.Roku._call", side_effect=RequestException,
):
entry = await setup_integration(hass)
entry = await setup_integration(hass, requests_mock)
assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_config_entry_not_ready_socket(hass: HomeAssistantType) -> None:
async def test_config_entry_not_ready_socket(
hass: HomeAssistantType, requests_mock: Mocker
) -> None:
"""Test the Roku configuration entry not ready."""
with patch(
"homeassistant.components.roku.Roku._call", side_effect=SocketGIAError,
):
entry = await setup_integration(hass)
entry = await setup_integration(hass, requests_mock)
assert entry.state == ENTRY_STATE_SETUP_RETRY
async def test_unload_config_entry(hass: HomeAssistantType) -> None:
async def test_unload_config_entry(
hass: HomeAssistantType, requests_mock: Mocker
) -> None:
"""Test the Roku configuration entry unloading."""
with patch(
"homeassistant.components.roku.Roku.device_info", return_value=MockDeviceInfo,
), patch(
"homeassistant.components.roku.media_player.async_setup_entry",
return_value=True,
), patch(
"homeassistant.components.roku.remote.async_setup_entry", return_value=True,
):
entry = await setup_integration(hass)
entry = await setup_integration(hass, requests_mock)
assert hass.data[DOMAIN][entry.entry_id]
assert entry.state == ENTRY_STATE_LOADED