2018-09-20 23:46:51 +02:00
|
|
|
"""Fixtures for cloud tests."""
|
2021-01-01 22:31:56 +01:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
2019-06-28 20:43:57 -07:00
|
|
|
import jwt
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.components.cloud import const, prefs
|
2019-06-17 13:50:01 -07:00
|
|
|
|
2018-09-20 23:46:51 +02:00
|
|
|
from . import mock_cloud, mock_cloud_prefs
|
|
|
|
|
2023-05-24 21:00:35 +02:00
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def mock_tts_cache_dir_autouse(mock_tts_cache_dir):
|
|
|
|
"""Mock the TTS cache dir with empty dir."""
|
|
|
|
return mock_tts_cache_dir
|
2023-04-26 03:40:01 +02:00
|
|
|
|
2018-09-20 23:46:51 +02:00
|
|
|
|
2019-03-11 20:21:20 +01:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def mock_user_data():
|
|
|
|
"""Mock os module."""
|
2021-09-06 16:05:33 -07:00
|
|
|
with patch("hass_nabucasa.Cloud._write_user_info") as writer:
|
2019-03-11 20:21:20 +01:00
|
|
|
yield writer
|
|
|
|
|
|
|
|
|
2018-09-20 23:46:51 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def mock_cloud_fixture(hass):
|
|
|
|
"""Fixture for cloud component."""
|
2019-06-21 02:17:21 -07:00
|
|
|
hass.loop.run_until_complete(mock_cloud(hass))
|
2018-09-20 23:46:51 +02:00
|
|
|
return mock_cloud_prefs(hass)
|
2019-06-17 13:50:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
async def cloud_prefs(hass):
|
|
|
|
"""Fixture for cloud preferences."""
|
|
|
|
cloud_prefs = prefs.CloudPreferences(hass)
|
|
|
|
await cloud_prefs.async_initialize()
|
|
|
|
return cloud_prefs
|
2019-06-28 20:43:57 -07:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
async def mock_cloud_setup(hass):
|
|
|
|
"""Set up the cloud."""
|
|
|
|
await mock_cloud(hass)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def mock_cloud_login(hass, mock_cloud_setup):
|
|
|
|
"""Mock cloud is logged in."""
|
2019-07-31 12:25:30 -07:00
|
|
|
hass.data[const.DOMAIN].id_token = jwt.encode(
|
|
|
|
{
|
|
|
|
"email": "hello@home-assistant.io",
|
2021-02-16 21:49:53 -08:00
|
|
|
"custom:sub-exp": "2300-01-03",
|
|
|
|
"cognito:username": "abcdefghjkl",
|
|
|
|
},
|
|
|
|
"test",
|
|
|
|
)
|
2021-09-01 09:54:54 -07:00
|
|
|
with patch.object(hass.data[const.DOMAIN].auth, "async_check_token"):
|
|
|
|
yield
|
2021-02-16 21:49:53 -08:00
|
|
|
|
|
|
|
|
2022-11-28 23:35:24 +01:00
|
|
|
@pytest.fixture(name="mock_auth")
|
|
|
|
def mock_auth_fixture():
|
|
|
|
"""Mock check token."""
|
|
|
|
with patch("hass_nabucasa.auth.CognitoAuth.async_check_token"), patch(
|
|
|
|
"hass_nabucasa.auth.CognitoAuth.async_renew_access_token"
|
|
|
|
):
|
|
|
|
yield
|
|
|
|
|
|
|
|
|
2021-02-16 21:49:53 -08:00
|
|
|
@pytest.fixture
|
|
|
|
def mock_expired_cloud_login(hass, mock_cloud_setup):
|
|
|
|
"""Mock cloud is logged in."""
|
|
|
|
hass.data[const.DOMAIN].id_token = jwt.encode(
|
|
|
|
{
|
|
|
|
"email": "hello@home-assistant.io",
|
|
|
|
"custom:sub-exp": "2018-01-01",
|
2019-07-31 12:25:30 -07:00
|
|
|
"cognito:username": "abcdefghjkl",
|
|
|
|
},
|
|
|
|
"test",
|
|
|
|
)
|