From 3afc983c056e22017b32e3cfc8fc09d0f77dcfa1 Mon Sep 17 00:00:00 2001 From: Jason Hu Date: Tue, 4 Sep 2018 12:18:35 -0700 Subject: [PATCH] Fix openuv.config_flow unit test (#16419) --- tests/components/openuv/test_config_flow.py | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/tests/components/openuv/test_config_flow.py b/tests/components/openuv/test_config_flow.py index 0e50bddabde..07946fbbc09 100644 --- a/tests/components/openuv/test_config_flow.py +++ b/tests/components/openuv/test_config_flow.py @@ -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