1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -7,21 +7,16 @@ import homeassistant.components.google as google
from homeassistant.setup import async_setup_component
@pytest.fixture(name='google_setup')
@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')
"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
@@ -29,45 +24,43 @@ def mock_google_setup(hass):
async def test_setup_component(hass, google_setup):
"""Test setup component."""
config = {
'google': {
'client_id': 'id',
'client_secret': 'secret',
}
}
config = {"google": {"client_id": "id", "client_secret": "secret"}}
assert await async_setup_component(hass, 'google', config)
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(
google.get_calendar_info, hass, test_calendar)
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,
}]
"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,
}
],
}
async def test_found_calendar(
hass, google_setup, mock_next_event, test_calendar):
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,
"google": {
"client_id": "id",
"client_secret": "secret",
"track_new_calendar": True,
}
}
assert await async_setup_component(hass, 'google', config)
assert await async_setup_component(hass, "google", config)
assert hass.data[google.DATA_INDEX] == {}
await hass.services.async_call(
'google', google.SERVICE_FOUND_CALENDARS, test_calendar, blocking=True)
"google", google.SERVICE_FOUND_CALENDARS, test_calendar, blocking=True
)
assert hass.data[google.DATA_INDEX].get(test_calendar['id']) is not None
assert hass.data[google.DATA_INDEX].get(test_calendar["id"]) is not None