Fix openuv.config_flow unit test (#16419)

pull/16384/merge
Jason Hu 2018-09-04 12:18:35 -07:00 committed by Pascal Vizeli
parent 746f4ac158
commit 3afc983c05
1 changed files with 18 additions and 15 deletions

View File

@ -26,7 +26,6 @@ async def test_duplicate_error(hass):
assert result['errors'] == {'base': 'identifier_exists'}
@patch('pyopenuv.util.validate_api_key', return_value=mock_coro(False))
async def test_invalid_api_key(hass):
"""Test that an invalid API key throws an error."""
conf = {
@ -39,8 +38,10 @@ async def test_invalid_api_key(hass):
flow = config_flow.OpenUvFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {'base': 'invalid_api_key'}
with patch('pyopenuv.util.validate_api_key',
return_value=mock_coro(False)):
result = await flow.async_step_user(user_input=conf)
assert result['errors'] == {'base': 'invalid_api_key'}
async def test_show_form(hass):
@ -54,7 +55,6 @@ async def test_show_form(hass):
assert result['step_id'] == 'user'
@patch('pyopenuv.util.validate_api_key', return_value=mock_coro(True))
async def test_step_import(hass):
"""Test that the import step works."""
conf = {
@ -64,15 +64,16 @@ async def test_step_import(hass):
flow = config_flow.OpenUvFlowHandler()
flow.hass = hass
result = await flow.async_step_import(import_config=conf)
with patch('pyopenuv.util.validate_api_key',
return_value=mock_coro(True)):
result = await flow.async_step_import(import_config=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '{0}, {1}'.format(
hass.config.latitude, hass.config.longitude)
assert result['data'] == conf
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '{0}, {1}'.format(
hass.config.latitude, hass.config.longitude)
assert result['data'] == conf
@patch('pyopenuv.util.validate_api_key', return_value=mock_coro(True))
async def test_step_user(hass):
"""Test that the user step works."""
conf = {
@ -85,9 +86,11 @@ async def test_step_user(hass):
flow = config_flow.OpenUvFlowHandler()
flow.hass = hass
result = await flow.async_step_user(user_input=conf)
with patch('pyopenuv.util.validate_api_key',
return_value=mock_coro(True)):
result = await flow.async_step_user(user_input=conf)
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '{0}, {1}'.format(
conf[CONF_LATITUDE], conf[CONF_LONGITUDE])
assert result['data'] == conf
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result['title'] == '{0}, {1}'.format(
conf[CONF_LATITUDE], conf[CONF_LONGITUDE])
assert result['data'] == conf