* add a component for hangouts
* add a notify component for hangouts
* add an extra message as title
* add support to listen to all conversations hangouts has
* move hangouts to package and add parameter documentation
* update .coveragerc and requirements_all.txt
* makes linter happy again
* bugfix
* add conversations parameter to command words
* Move the resolution of conversation names to conversations in own a function
* typo
* rename group of exclusion form 'id' to 'id or name'
* refactoring and use config_flow
* makes linter happy again
* remove unused imports
* fix not working regex commands
* fix translations
* cleanup
* remove step_init
* remove logging entry
* clean up events
* move constant
* remove unsed import
* add new files to .converagerc
* isort imports
* add hangouts_utils to ignored packages
* upadte doc and format
* fix I/O not in executor jon
* rename SERVICE_UPDATE_USERS_AND_CONVERSATIONS to SERVICE_UPDATE
* move EVENT_HANGOUTS_{CONNECTED,DISCONNECTED} to dispatcher
* add config flow tests
* Update tox.ini
93 lines
3.2 KiB
Python
93 lines
3.2 KiB
Python
"""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
|
|
|
|
with patch('hangups.get_auth'):
|
|
result = await flow.async_step_user(
|
|
{'email': 'test@test.com', 'password': '1232456'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
assert result['title'] == 'test@test.com'
|
|
|
|
|
|
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
|
|
|
|
with patch('hangups.get_auth', side_effect=Google2FAError):
|
|
result = await flow.async_step_user(
|
|
{'email': 'test@test.com', 'password': '1232456'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['step_id'] == '2fa'
|
|
|
|
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'
|
|
|
|
|
|
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
|
|
|
|
with patch('hangups.get_auth',
|
|
side_effect=GoogleAuthError('Unknown verification code input')):
|
|
result = await flow.async_step_user(
|
|
{'email': 'test@test.com', 'password': '1232456'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['errors']['base'] == 'invalid_2fa_method'
|
|
|
|
|
|
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
|
|
|
|
with patch('hangups.get_auth',
|
|
side_effect=GoogleAuthError):
|
|
result = await flow.async_step_user(
|
|
{'email': 'test@test.com', 'password': '1232456'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['errors']['base'] == 'invalid_login'
|
|
|
|
|
|
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
|
|
|
|
with patch('hangups.get_auth', side_effect=Google2FAError):
|
|
result = await flow.async_step_user(
|
|
{'email': 'test@test.com', 'password': '1232456'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['step_id'] == '2fa'
|
|
|
|
with patch('hangups.get_auth', side_effect=Google2FAError):
|
|
result = await flow.async_step_2fa({'2fa': 123456})
|
|
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['errors']['base'] == 'invalid_2fa'
|