diff --git a/tests/components/forked_daapd/test_config_flow.py b/tests/components/forked_daapd/test_config_flow.py index 181c963ee4f857ee24d438427372ce91739808aa..f655e727667228b088cee84ee551a48586dea815 100644 --- a/tests/components/forked_daapd/test_config_flow.py +++ b/tests/components/forked_daapd/test_config_flow.py @@ -16,7 +16,7 @@ from homeassistant.config_entries import ( ) from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT -from tests.async_mock import patch +from tests.async_mock import AsyncMock, patch from tests.common import MockConfigEntry SAMPLE_CONFIG = { @@ -69,7 +69,8 @@ async def test_show_form(hass): async def test_config_flow(hass, config_entry): """Test that the user step works.""" with patch( - "homeassistant.components.forked_daapd.config_flow.ForkedDaapdAPI.test_connection" + "homeassistant.components.forked_daapd.config_flow.ForkedDaapdAPI.test_connection", + new=AsyncMock(), ) as mock_test_connection, patch( "homeassistant.components.forked_daapd.media_player.ForkedDaapdAPI.get_request", autospec=True, @@ -119,7 +120,8 @@ async def test_zeroconf_updates_title(hass, config_entry): async def test_config_flow_no_websocket(hass, config_entry): """Test config flow setup without websocket enabled on server.""" with patch( - "homeassistant.components.forked_daapd.config_flow.ForkedDaapdAPI.test_connection" + "homeassistant.components.forked_daapd.config_flow.ForkedDaapdAPI.test_connection", + new=AsyncMock(), ) as mock_test_connection: # test invalid config data mock_test_connection.return_value = ["websocket_not_enabled"] diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index 93192e89df3ffb7baceee3ccb24d541054add8dd..366b52ca4e772d99eb8f3660e2475f257530ebd7 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -25,9 +25,11 @@ async def test_form(hass): return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False}, ), patch( "aioshelly.Device.create", - return_value=Mock( - shutdown=AsyncMock(), - settings={"name": "Test name", "device": {"mac": "test-mac"}}, + new=AsyncMock( + return_value=Mock( + shutdown=AsyncMock(), + settings={"name": "Test name", "device": {"mac": "test-mac"}}, + ) ), ), patch( "homeassistant.components.shelly.async_setup", return_value=True @@ -72,9 +74,11 @@ async def test_form_auth(hass): with patch( "aioshelly.Device.create", - return_value=Mock( - shutdown=AsyncMock(), - settings={"name": "Test name", "device": {"mac": "test-mac"}}, + new=AsyncMock( + return_value=Mock( + shutdown=AsyncMock(), + settings={"name": "Test name", "device": {"mac": "test-mac"}}, + ) ), ), patch( "homeassistant.components.shelly.async_setup", return_value=True @@ -136,7 +140,7 @@ async def test_form_errors_test_connection(hass, error): "aioshelly.get_info", return_value={"mac": "test-mac", "auth": False} ), patch( "aioshelly.Device.create", - side_effect=exc, + new=AsyncMock(side_effect=exc), ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -199,7 +203,7 @@ async def test_form_auth_errors_test_connection(hass, error): with patch( "aioshelly.Device.create", - side_effect=exc, + new=AsyncMock(side_effect=exc), ): result3 = await hass.config_entries.flow.async_configure( result2["flow_id"], @@ -227,9 +231,11 @@ async def test_zeroconf(hass): with patch( "aioshelly.Device.create", - return_value=Mock( - shutdown=AsyncMock(), - settings={"name": "Test name", "device": {"mac": "test-mac"}}, + new=AsyncMock( + return_value=Mock( + shutdown=AsyncMock(), + settings={"name": "Test name", "device": {"mac": "test-mac"}}, + ) ), ), patch( "homeassistant.components.shelly.async_setup", return_value=True @@ -274,7 +280,7 @@ async def test_zeroconf_confirm_error(hass, error): with patch( "aioshelly.Device.create", - side_effect=exc, + new=AsyncMock(side_effect=exc), ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], @@ -349,9 +355,11 @@ async def test_zeroconf_require_auth(hass): with patch( "aioshelly.Device.create", - return_value=Mock( - shutdown=AsyncMock(), - settings={"name": "Test name", "device": {"mac": "test-mac"}}, + new=AsyncMock( + return_value=Mock( + shutdown=AsyncMock(), + settings={"name": "Test name", "device": {"mac": "test-mac"}}, + ) ), ), patch( "homeassistant.components.shelly.async_setup", return_value=True diff --git a/tests/components/simplisafe/test_config_flow.py b/tests/components/simplisafe/test_config_flow.py index 86cd0fc384cbdc74b9450d10c1cf283e8cc3e67e..e3d0b0479c4a099b1087e74c178eb68226912833 100644 --- a/tests/components/simplisafe/test_config_flow.py +++ b/tests/components/simplisafe/test_config_flow.py @@ -10,7 +10,7 @@ from homeassistant.components.simplisafe import DOMAIN from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER from homeassistant.const import CONF_CODE, CONF_PASSWORD, CONF_TOKEN, CONF_USERNAME -from tests.async_mock import MagicMock, PropertyMock, patch +from tests.async_mock import AsyncMock, MagicMock, PropertyMock, patch from tests.common import MockConfigEntry @@ -49,7 +49,7 @@ async def test_invalid_credentials(hass): with patch( "simplipy.API.login_via_credentials", - side_effect=InvalidCredentialsError, + new=AsyncMock(side_effect=InvalidCredentialsError), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=conf @@ -105,7 +105,9 @@ async def test_step_import(hass): with patch( "homeassistant.components.simplisafe.async_setup_entry", return_value=True - ), patch("simplipy.API.login_via_credentials", return_value=mock_api()): + ), patch( + "simplipy.API.login_via_credentials", new=AsyncMock(return_value=mock_api()) + ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=conf ) @@ -140,7 +142,9 @@ async def test_step_reauth(hass): with patch( "homeassistant.components.simplisafe.async_setup_entry", return_value=True - ), patch("simplipy.API.login_via_credentials", return_value=mock_api()): + ), patch( + "simplipy.API.login_via_credentials", new=AsyncMock(return_value=mock_api()) + ): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={CONF_PASSWORD: "password"} ) @@ -160,7 +164,9 @@ async def test_step_user(hass): with patch( "homeassistant.components.simplisafe.async_setup_entry", return_value=True - ), patch("simplipy.API.login_via_credentials", return_value=mock_api()): + ), patch( + "simplipy.API.login_via_credentials", new=AsyncMock(return_value=mock_api()) + ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=conf ) @@ -183,7 +189,8 @@ async def test_step_user_mfa(hass): } with patch( - "simplipy.API.login_via_credentials", side_effect=PendingAuthorizationError + "simplipy.API.login_via_credentials", + new=AsyncMock(side_effect=PendingAuthorizationError), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=conf @@ -191,7 +198,8 @@ async def test_step_user_mfa(hass): assert result["step_id"] == "mfa" with patch( - "simplipy.API.login_via_credentials", side_effect=PendingAuthorizationError + "simplipy.API.login_via_credentials", + new=AsyncMock(side_effect=PendingAuthorizationError), ): # Simulate the user pressing the MFA submit button without having clicked # the link in the MFA email: @@ -202,7 +210,9 @@ async def test_step_user_mfa(hass): with patch( "homeassistant.components.simplisafe.async_setup_entry", return_value=True - ), patch("simplipy.API.login_via_credentials", return_value=mock_api()): + ), patch( + "simplipy.API.login_via_credentials", new=AsyncMock(return_value=mock_api()) + ): result = await hass.config_entries.flow.async_configure( result["flow_id"], user_input={} ) @@ -222,7 +232,7 @@ async def test_unknown_error(hass): with patch( "simplipy.API.login_via_credentials", - side_effect=SimplipyError, + new=AsyncMock(side_effect=SimplipyError), ): result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_USER}, data=conf