Files
homeassistant-core/tests/components/ios/test_init.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.8 KiB
Python
Raw Normal View History

2018-09-12 20:17:52 +02:00
"""Tests for the iOS init file."""
2018-09-12 20:17:52 +02:00
from unittest.mock import patch
import pytest
from homeassistant.components import ios
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
2018-09-12 20:17:52 +02:00
2023-08-25 22:54:55 +02:00
from tests.common import mock_component
2018-09-12 20:17:52 +02:00
@pytest.fixture(autouse=True)
def mock_load_json():
"""Mock load_json."""
with patch("homeassistant.components.ios.load_json_object", return_value={}):
2018-09-12 20:17:52 +02:00
yield
@pytest.fixture(autouse=True)
def mock_dependencies(hass):
"""Mock dependencies loaded."""
mock_component(hass, "zeroconf")
mock_component(hass, "device_tracker")
async def test_creating_entry_sets_up_sensor(hass: HomeAssistant) -> None:
2018-09-12 20:17:52 +02:00
"""Test setting up iOS loads the sensor component."""
2019-02-01 15:45:44 -08:00
with patch(
"homeassistant.components.ios.sensor.async_setup_entry",
2023-08-25 22:54:55 +02:00
return_value=True,
2018-09-12 20:17:52 +02:00
) as mock_setup:
2020-04-17 11:25:31 +03:00
assert await async_setup_component(hass, ios.DOMAIN, {ios.DOMAIN: {}})
2018-09-12 20:17:52 +02:00
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
async def test_configuring_ios_creates_entry(hass: HomeAssistant) -> None:
2018-09-12 20:17:52 +02:00
"""Test that specifying config will create an entry."""
with patch(
2023-08-25 22:54:55 +02:00
"homeassistant.components.ios.async_setup_entry",
return_value=True,
2018-09-12 20:17:52 +02:00
) as mock_setup:
await async_setup_component(hass, ios.DOMAIN, {"ios": {"push": {}}})
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 1
async def test_not_configuring_ios_not_creates_entry(hass: HomeAssistant) -> None:
2018-09-12 20:17:52 +02:00
"""Test that no config will not create an entry."""
with patch(
2023-08-25 22:54:55 +02:00
"homeassistant.components.ios.async_setup_entry",
return_value=True,
2018-09-12 20:17:52 +02:00
) as mock_setup:
2020-04-17 11:25:31 +03:00
await async_setup_component(hass, ios.DOMAIN, {"foo": "bar"})
2018-09-12 20:17:52 +02:00
await hass.async_block_till_done()
assert len(mock_setup.mock_calls) == 0