Convert august to async so a token refresh lock can be used (#31848)

* Convert august to async so a token refresh lock can be used

* Update comment since we now have a lock

* Do not mock the lock

* Address review items
This commit is contained in:
J. Nick Koston authored and GitHub committed 2020-02-15 21:08:52 -08:00
1 parent fb8cbc2e93
commit f6d9e6b6c5
5 files changed
+119 -93

No files matched your search

+7 -4
View File
@@ -1,4 +1,5 @@
"""The tests for the august platform."""
import asyncio
from unittest.mock import MagicMock
from homeassistant.components import august
@@ -9,21 +10,23 @@ from tests.components.august.mocks import (
)
def test__refresh_access_token():
async def test__refresh_access_token(hass):
"""Set up things to be run when tests are started."""
authentication = _mock_august_authentication("original_token", 1234)
authenticator = _mock_august_authenticator()
token_refresh_lock = asyncio.Lock()
data = august.AugustData(
MagicMock(name="hass"), MagicMock(name="api"), authentication, authenticator
hass, MagicMock(name="api"), authentication, authenticator, token_refresh_lock
)
data._refresh_access_token_if_needed()
await data._async_refresh_access_token_if_needed()
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
)
data._refresh_access_token_if_needed()
await data._async_refresh_access_token_if_needed()
authenticator.refresh_access_token.assert_called()
assert data._access_token == "new_token"
assert data._access_token_expires == 5678