2020-02-12 06:13:54 +00:00
|
|
|
"""The tests for the august platform."""
|
2020-02-16 05:08:52 +00:00
|
|
|
import asyncio
|
2020-02-12 23:35:07 +00:00
|
|
|
from unittest.mock import MagicMock
|
2020-02-12 06:13:54 +00:00
|
|
|
|
|
|
|
from homeassistant.components import august
|
|
|
|
|
2020-02-12 23:35:07 +00:00
|
|
|
from tests.components.august.mocks import (
|
|
|
|
_mock_august_authentication,
|
|
|
|
_mock_august_authenticator,
|
|
|
|
)
|
2020-02-12 06:13:54 +00:00
|
|
|
|
|
|
|
|
2020-02-16 05:08:52 +00:00
|
|
|
async def test__refresh_access_token(hass):
|
2020-02-12 06:13:54 +00:00
|
|
|
"""Set up things to be run when tests are started."""
|
|
|
|
authentication = _mock_august_authentication("original_token", 1234)
|
|
|
|
authenticator = _mock_august_authenticator()
|
2020-02-16 05:08:52 +00:00
|
|
|
token_refresh_lock = asyncio.Lock()
|
|
|
|
|
2020-02-12 06:13:54 +00:00
|
|
|
data = august.AugustData(
|
2020-02-16 05:08:52 +00:00
|
|
|
hass, MagicMock(name="api"), authentication, authenticator, token_refresh_lock
|
2020-02-12 06:13:54 +00:00
|
|
|
)
|
2020-02-16 05:08:52 +00:00
|
|
|
await data._async_refresh_access_token_if_needed()
|
2020-02-12 06:13:54 +00:00
|
|
|
authenticator.refresh_access_token.assert_not_called()
|
|
|
|
|
|
|
|
authenticator.should_refresh.return_value = 1
|
|
|
|
authenticator.refresh_access_token.return_value = _mock_august_authentication(
|
|
|
|
"new_token", 5678
|
|
|
|
)
|
2020-02-16 05:08:52 +00:00
|
|
|
await data._async_refresh_access_token_if_needed()
|
2020-02-12 06:13:54 +00:00
|
|
|
authenticator.refresh_access_token.assert_called()
|
|
|
|
assert data._access_token == "new_token"
|
|
|
|
assert data._access_token_expires == 5678
|