2016-11-19 06:29:20 +00:00
|
|
|
"""The tests for the Google Calendar component."""
|
2016-11-23 02:19:32 +00:00
|
|
|
from unittest.mock import patch
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
import pytest
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
import homeassistant.components.google as google
|
|
|
|
from homeassistant.setup import async_setup_component
|
2016-11-19 06:29:20 +00:00
|
|
|
|
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
@pytest.fixture(name='google_setup')
|
|
|
|
def mock_google_setup(hass):
|
|
|
|
"""Mock the google set up functions."""
|
|
|
|
p_auth = patch(
|
|
|
|
'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')
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
with p_auth, p_load, p_service, p_discovery, p_save:
|
|
|
|
yield
|
2016-11-19 06:29:20 +00:00
|
|
|
|
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
async def test_setup_component(hass, google_setup):
|
|
|
|
"""Test setup component."""
|
|
|
|
config = {
|
|
|
|
'google': {
|
|
|
|
'client_id': 'id',
|
|
|
|
'client_secret': 'secret',
|
2016-11-19 06:29:20 +00:00
|
|
|
}
|
2019-05-05 16:38:55 +00:00
|
|
|
}
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
assert await async_setup_component(hass, 'google', config)
|
2016-11-19 06:29:20 +00:00
|
|
|
|
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
async def test_get_calendar_info(hass, test_calendar):
|
|
|
|
"""Test getting the calendar info."""
|
|
|
|
calendar_info = await hass.async_add_executor_job(
|
|
|
|
google.get_calendar_info, hass, test_calendar)
|
|
|
|
assert calendar_info == {
|
|
|
|
'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,
|
|
|
|
}]
|
|
|
|
}
|
2016-11-19 06:29:20 +00:00
|
|
|
|
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
async def test_found_calendar(
|
|
|
|
hass, google_setup, mock_next_event, test_calendar):
|
|
|
|
"""Test when a calendar is found."""
|
|
|
|
config = {
|
|
|
|
'google': {
|
|
|
|
'client_id': 'id',
|
|
|
|
'client_secret': 'secret',
|
|
|
|
'track_new_calendar': True,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert await async_setup_component(hass, 'google', config)
|
|
|
|
assert hass.data[google.DATA_INDEX] == {}
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
await hass.services.async_call(
|
|
|
|
'google', google.SERVICE_FOUND_CALENDARS, test_calendar, blocking=True)
|
2016-11-19 06:29:20 +00:00
|
|
|
|
2019-05-05 16:38:55 +00:00
|
|
|
assert hass.data[google.DATA_INDEX].get(test_calendar['id']) is not None
|