1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Simplify google calendar authentication setup (#67314)

Simplify google calendar authentication to combine some of the cases together, and reduce unecessarily checks. Make the
tests share common authentication setup and reduce use of mocks by introducing a fake for holding on to credentials.
This makes future refactoring simpler, so we don't have to care as much about the interactions with the credentials
storage.
This commit is contained in:
Allen Porter
2022-02-26 15:17:02 -08:00
committed by GitHub
parent a151d3f9a0
commit 0e74184e4f
4 changed files with 77 additions and 59 deletions

View File

@@ -21,7 +21,6 @@ from homeassistant.components.google import (
CONF_TRACK,
DEVICE_SCHEMA,
SERVICE_SCAN_CALENDARS,
do_setup,
)
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers.template import DATE_STR_FORMAT
@@ -86,21 +85,18 @@ def get_calendar_info(calendar):
@pytest.fixture(autouse=True)
def mock_google_setup(hass, test_calendar):
def mock_google_setup(hass, test_calendar, mock_token_read):
"""Mock the google set up functions."""
hass.loop.run_until_complete(async_setup_component(hass, "group", {"group": {}}))
calendar = get_calendar_info(test_calendar)
calendars = {calendar[CONF_CAL_ID]: calendar}
patch_google_auth = patch(
"homeassistant.components.google.do_authentication", side_effect=do_setup
)
patch_google_load = patch(
"homeassistant.components.google.load_config", return_value=calendars
)
patch_google_services = patch("homeassistant.components.google.setup_services")
async_mock_service(hass, "google", SERVICE_SCAN_CALENDARS)
with patch_google_auth, patch_google_load, patch_google_services:
with patch_google_load, patch_google_services:
yield