* Change dependency to pyvesync-v2 for vesync switch * async vesync component * FInish data_entry_flow * Update config flow * strings.json * Minor fix * Syntax fix * Minor Fixs * UI Fix * Minor Correct * Debug lines * fix device dictionaries * Light switch fix * Cleanup * pylint fixes * Hassfest and setup scripts * Flake8 fixes * Add vesync light platform * Fix typo * Update Devices Service * Fix update devices service * Add initial test * Add Config Flow Tests * Remove Extra Platforms * Fix requirements * Update pypi package * Add login to config_flow Avoid setting up component if login credentials are invalid * Fix variable import * Update config_flow.py * Update config_flow.py * Put VS object into hass.data instead of config entry * Update __init__.py * Handle Login Error * Fix invalid login error * Fix typo * Remove line * PEP fixes * Fix change requests * Fix typo * Update __init__.py * Update switch.py * Flake8 fix * Update test requirements * Fix permission * Address change requests * Address change requests * Fix device discovery indent, add MockConfigEntry * Fix vesynclightswitch classs * Remove active time attribute * Remove time_zone, grammar check
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""Test for vesync config flow."""
|
|
from unittest.mock import patch
|
|
from homeassistant import data_entry_flow
|
|
from homeassistant.components.vesync import config_flow, DOMAIN
|
|
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
async def test_abort_already_setup(hass):
|
|
"""Test if we abort because component is already setup."""
|
|
flow = config_flow.VeSyncFlowHandler()
|
|
flow.hass = hass
|
|
MockConfigEntry(
|
|
domain=DOMAIN, title='user', data={'user': 'pass'}
|
|
).add_to_hass(hass)
|
|
result = await flow.async_step_user()
|
|
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
|
|
assert result['reason'] == 'already_setup'
|
|
|
|
|
|
async def test_invalid_login_error(hass):
|
|
"""Test if we return error for invalid username and password."""
|
|
test_dict = {CONF_USERNAME: 'user', CONF_PASSWORD: 'pass'}
|
|
flow = config_flow.VeSyncFlowHandler()
|
|
flow.hass = hass
|
|
with patch('pyvesync.vesync.VeSync.login', return_value=False):
|
|
result = await flow.async_step_user(user_input=test_dict)
|
|
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
assert result['errors'] == {'base': 'invalid_login'}
|
|
|
|
|
|
async def test_config_flow_configuration_yaml(hass):
|
|
"""Test config flow with configuration.yaml user input."""
|
|
test_dict = {CONF_USERNAME: 'user', CONF_PASSWORD: 'pass'}
|
|
flow = config_flow.VeSyncFlowHandler()
|
|
flow.hass = hass
|
|
with patch('pyvesync.vesync.VeSync.login', return_value=True):
|
|
result = await flow.async_step_import(test_dict)
|
|
|
|
assert result['data'].get(CONF_USERNAME) == test_dict[CONF_USERNAME]
|
|
assert result['data'].get(CONF_PASSWORD) == test_dict[CONF_PASSWORD]
|
|
|
|
|
|
async def test_config_flow_user_input(hass):
|
|
"""Test config flow with user input."""
|
|
flow = config_flow.VeSyncFlowHandler()
|
|
flow.hass = hass
|
|
result = await flow.async_step_user()
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
|
|
with patch('pyvesync.vesync.VeSync.login', return_value=True):
|
|
result = await flow.async_step_user(
|
|
{CONF_USERNAME: 'user', CONF_PASSWORD: 'pass'})
|
|
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
|
assert result['data'][CONF_USERNAME] == 'user'
|
|
assert result['data'][CONF_PASSWORD] == 'pass'
|