core/tests/components/google/test_init.py

67 lines
2.2 KiB
Python
Raw Normal View History

"""The tests for the Google Calendar component."""
from unittest.mock import patch
import pytest
import homeassistant.components.google as google
from homeassistant.setup import async_setup_component
2019-07-31 19:25:30 +00:00
@pytest.fixture(name="google_setup")
def mock_google_setup(hass):
"""Mock the google set up functions."""
p_auth = patch(
2019-07-31 19:25:30 +00:00
"homeassistant.components.google.do_authentication", side_effect=google.do_setup
)
p_service = patch("homeassistant.components.google.GoogleCalendarService.get")
p_discovery = patch("homeassistant.components.google.discovery.load_platform")
p_load = patch("homeassistant.components.google.load_config", return_value={})
p_save = patch("homeassistant.components.google.update_config")
with p_auth, p_load, p_service, p_discovery, p_save:
yield
async def test_setup_component(hass, google_setup):
"""Test setup component."""
2019-07-31 19:25:30 +00:00
config = {"google": {"client_id": "id", "client_secret": "secret"}}
2019-07-31 19:25:30 +00:00
assert await async_setup_component(hass, "google", config)
async def test_get_calendar_info(hass, test_calendar):
"""Test getting the calendar info."""
calendar_info = await hass.async_add_executor_job(
2019-07-31 19:25:30 +00:00
google.get_calendar_info, hass, test_calendar
)
assert calendar_info == {
2019-07-31 19:25:30 +00:00
"cal_id": "qwertyuiopasdfghjklzxcvbnm@import.calendar.google.com",
"entities": [
{
"device_id": "we_are_we_are_a_test_calendar",
"name": "We are, we are, a... Test Calendar",
"track": True,
"ignore_availability": True,
}
],
}
2019-07-31 19:25:30 +00:00
async def test_found_calendar(hass, google_setup, mock_next_event, test_calendar):
"""Test when a calendar is found."""
config = {
2019-07-31 19:25:30 +00:00
"google": {
"client_id": "id",
"client_secret": "secret",
"track_new_calendar": True,
}
}
2019-07-31 19:25:30 +00:00
assert await async_setup_component(hass, "google", config)
assert hass.data[google.DATA_INDEX] == {}
await hass.services.async_call(
2019-07-31 19:25:30 +00:00
"google", google.SERVICE_FOUND_CALENDARS, test_calendar, blocking=True
)
2019-07-31 19:25:30 +00:00
assert hass.data[google.DATA_INDEX].get(test_calendar["id"]) is not None