mirror of
https://github.com/home-assistant/core.git
synced 2025-04-19 14:57:52 +00:00
Test remember the milk configurator (#139122)
This commit is contained in:
parent
0b961d98f5
commit
4f5c7353f8
@ -13,8 +13,16 @@ from .const import TOKEN
|
||||
@pytest.fixture(name="client")
|
||||
def client_fixture() -> Generator[MagicMock]:
|
||||
"""Create a mock client."""
|
||||
with patch("homeassistant.components.remember_the_milk.entity.Rtm") as client_class:
|
||||
client = client_class.return_value
|
||||
client = MagicMock()
|
||||
with (
|
||||
patch(
|
||||
"homeassistant.components.remember_the_milk.entity.Rtm"
|
||||
) as entity_client_class,
|
||||
patch("homeassistant.components.remember_the_milk.Rtm") as client_class,
|
||||
):
|
||||
entity_client_class.return_value = client
|
||||
client_class.return_value = client
|
||||
client.token = TOKEN
|
||||
client.token_valid.return_value = True
|
||||
timelines = MagicMock()
|
||||
timelines.timeline.value = "1234"
|
||||
|
@ -3,6 +3,11 @@
|
||||
import json
|
||||
|
||||
PROFILE = "myprofile"
|
||||
CONFIG = {
|
||||
"name": f"{PROFILE}",
|
||||
"api_key": "test-api-key",
|
||||
"shared_secret": "test-shared-secret",
|
||||
}
|
||||
TOKEN = "mytoken"
|
||||
JSON_STRING = json.dumps(
|
||||
{
|
||||
|
@ -10,13 +10,7 @@ from homeassistant.components.remember_the_milk import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .const import PROFILE
|
||||
|
||||
CONFIG = {
|
||||
"name": f"{PROFILE}",
|
||||
"api_key": "test-api-key",
|
||||
"shared_secret": "test-shared-secret",
|
||||
}
|
||||
from .const import CONFIG, PROFILE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
65
tests/components/remember_the_milk/test_init.py
Normal file
65
tests/components/remember_the_milk/test_init.py
Normal file
@ -0,0 +1,65 @@
|
||||
"""Test the Remember The Milk integration."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.remember_the_milk import DOMAIN
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .const import CONFIG, PROFILE, TOKEN
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def configure_id() -> Generator[str]:
|
||||
"""Fixture to return a configure_id."""
|
||||
mock_id = "1-1"
|
||||
with patch(
|
||||
"homeassistant.components.configurator.Configurator._generate_unique_id"
|
||||
) as generate_id:
|
||||
generate_id.return_value = mock_id
|
||||
yield mock_id
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("token", "rtm_entity_exists", "configurator_end_state"),
|
||||
[(TOKEN, True, "configured"), (None, False, "configure")],
|
||||
)
|
||||
async def test_configurator(
|
||||
hass: HomeAssistant,
|
||||
client: MagicMock,
|
||||
storage: MagicMock,
|
||||
configure_id: str,
|
||||
token: str | None,
|
||||
rtm_entity_exists: bool,
|
||||
configurator_end_state: str,
|
||||
) -> None:
|
||||
"""Test configurator."""
|
||||
storage.get_token.return_value = None
|
||||
client.authenticate_desktop.return_value = ("test-url", "test-frob")
|
||||
client.token = token
|
||||
rtm_entity_id = f"{DOMAIN}.{PROFILE}"
|
||||
configure_entity_id = f"configurator.{DOMAIN}_{PROFILE}"
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: CONFIG})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(rtm_entity_id) is None
|
||||
state = hass.states.get(configure_entity_id)
|
||||
assert state
|
||||
assert state.state == "configure"
|
||||
|
||||
await hass.services.async_call(
|
||||
"configurator",
|
||||
"configure",
|
||||
{"configure_id": configure_id},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert bool(hass.states.get(rtm_entity_id)) == rtm_entity_exists
|
||||
state = hass.states.get(configure_entity_id)
|
||||
assert state
|
||||
assert state.state == configurator_end_state
|
Loading…
x
Reference in New Issue
Block a user