Update Flo config flow and associated tests (#38722)
This commit is contained in:
parent
227d7c0a99
commit
6a24667944
6 changed files with 62 additions and 20 deletions
|
@ -1,7 +1,12 @@
|
|||
"""Test the flo config flow."""
|
||||
import json
|
||||
import time
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.flo.const import DOMAIN
|
||||
|
||||
from .common import TEST_EMAIL_ADDRESS, TEST_PASSWORD, TEST_TOKEN, TEST_USER_ID
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
|
@ -20,20 +25,37 @@ async def test_form(hass, aioclient_mock_fixture):
|
|||
"homeassistant.components.flo.async_setup_entry", return_value=True
|
||||
) as mock_setup_entry:
|
||||
result2 = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{"username": "test-username", "password": "test-password"},
|
||||
result["flow_id"], {"username": TEST_USER_ID, "password": TEST_PASSWORD}
|
||||
)
|
||||
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "Home"
|
||||
assert result2["data"] == {"username": "test-username", "password": "test-password"}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
assert result2["type"] == "create_entry"
|
||||
assert result2["title"] == "Home"
|
||||
assert result2["data"] == {"username": TEST_USER_ID, "password": TEST_PASSWORD}
|
||||
await hass.async_block_till_done()
|
||||
assert len(mock_setup.mock_calls) == 1
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_form_cannot_connect(hass, aioclient_mock):
|
||||
"""Test we handle cannot connect error."""
|
||||
now = round(time.time())
|
||||
# Mocks a failed login response for flo.
|
||||
aioclient_mock.post(
|
||||
"https://api.meetflo.com/api/v1/users/auth",
|
||||
json=json.dumps(
|
||||
{
|
||||
"token": TEST_TOKEN,
|
||||
"tokenPayload": {
|
||||
"user": {"user_id": TEST_USER_ID, "email": TEST_EMAIL_ADDRESS},
|
||||
"timestamp": now,
|
||||
},
|
||||
"tokenExpiration": 86400,
|
||||
"timeNow": now,
|
||||
}
|
||||
),
|
||||
headers={"Content-Type": "application/json"},
|
||||
status=400,
|
||||
)
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue