2018-08-24 08:39:35 +00:00
|
|
|
"""Tests for the Google Hangouts config flow."""
|
|
|
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
from homeassistant import data_entry_flow
|
|
|
|
from homeassistant.components.hangouts import config_flow
|
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_works(hass, aioclient_mock):
|
|
|
|
"""Test config flow without 2fa."""
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth"):
|
2018-08-24 08:39:35 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{"email": "test@test.com", "password": "1232456"}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
|
|
assert result["title"] == "test@test.com"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
|
|
|
|
2019-04-05 17:11:04 +00:00
|
|
|
async def test_flow_works_with_authcode(hass, aioclient_mock):
|
|
|
|
"""Test config flow without 2fa."""
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth"):
|
2019-04-05 17:11:04 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{
|
|
|
|
"email": "test@test.com",
|
|
|
|
"password": "1232456",
|
|
|
|
"authorization_code": "c29tZXJhbmRvbXN0cmluZw==",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
|
|
assert result["title"] == "test@test.com"
|
2019-04-05 17:11:04 +00:00
|
|
|
|
|
|
|
|
2018-08-24 08:39:35 +00:00
|
|
|
async def test_flow_works_with_2fa(hass, aioclient_mock):
|
|
|
|
"""Test config flow with 2fa."""
|
|
|
|
from homeassistant.components.hangouts.hangups_utils import Google2FAError
|
|
|
|
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth", side_effect=Google2FAError):
|
2018-08-24 08:39:35 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{"email": "test@test.com", "password": "1232456"}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
assert result["step_id"] == "2fa"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth"):
|
|
|
|
result = await flow.async_step_2fa({"2fa": 123456})
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
|
|
assert result["title"] == "test@test.com"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_with_unknown_2fa(hass, aioclient_mock):
|
|
|
|
"""Test config flow with invalid 2fa method."""
|
|
|
|
from homeassistant.components.hangouts.hangups_utils import GoogleAuthError
|
|
|
|
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch(
|
|
|
|
"hangups.get_auth",
|
|
|
|
side_effect=GoogleAuthError("Unknown verification code input"),
|
|
|
|
):
|
2018-08-24 08:39:35 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{"email": "test@test.com", "password": "1232456"}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
assert result["errors"]["base"] == "invalid_2fa_method"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_invalid_login(hass, aioclient_mock):
|
|
|
|
"""Test config flow with invalid 2fa method."""
|
|
|
|
from homeassistant.components.hangouts.hangups_utils import GoogleAuthError
|
|
|
|
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth", side_effect=GoogleAuthError):
|
2018-08-24 08:39:35 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{"email": "test@test.com", "password": "1232456"}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
assert result["errors"]["base"] == "invalid_login"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_flow_invalid_2fa(hass, aioclient_mock):
|
|
|
|
"""Test config flow with 2fa."""
|
|
|
|
from homeassistant.components.hangouts.hangups_utils import Google2FAError
|
|
|
|
|
|
|
|
flow = config_flow.HangoutsFlowHandler()
|
|
|
|
|
|
|
|
flow.hass = hass
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth", side_effect=Google2FAError):
|
2018-08-24 08:39:35 +00:00
|
|
|
result = await flow.async_step_user(
|
2019-07-31 19:25:30 +00:00
|
|
|
{"email": "test@test.com", "password": "1232456"}
|
|
|
|
)
|
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
assert result["step_id"] == "2fa"
|
2018-08-24 08:39:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
with patch("hangups.get_auth", side_effect=Google2FAError):
|
|
|
|
result = await flow.async_step_2fa({"2fa": 123456})
|
2018-08-24 08:39:35 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
|
|
|
assert result["errors"]["base"] == "invalid_2fa"
|