Fix side_effect patching in samsungtv tests (#66651)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/66696/head
epenet 2022-02-16 21:40:11 +01:00 committed by GitHub
parent 2d33e435b9
commit 0138caa277
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 16 deletions

View File

@ -267,7 +267,7 @@ async def test_user_websocket_not_supported(hass: HomeAssistant):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=WebSocketProtocolException("Boom"),
):
# websocket device not supported
@ -284,7 +284,7 @@ async def test_user_not_successful(hass: HomeAssistant):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=OSError("Boom"),
):
result = await hass.config_entries.flow.async_init(
@ -300,7 +300,7 @@ async def test_user_not_successful_2(hass: HomeAssistant):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=ConnectionFailure("Boom"),
):
result = await hass.config_entries.flow.async_init(
@ -455,7 +455,7 @@ async def test_ssdp_websocket_not_supported(hass: HomeAssistant):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=WebSocketProtocolException("Boom"),
):
# device not supported
@ -485,7 +485,7 @@ async def test_ssdp_not_successful(hass: HomeAssistant, no_mac_address: Mock):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
@ -513,7 +513,7 @@ async def test_ssdp_not_successful_2(hass: HomeAssistant, no_mac_address: Mock):
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=ConnectionFailure("Boom"),
), patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
@ -925,12 +925,17 @@ async def test_autodetect_legacy(hass: HomeAssistant, remote: Mock):
async def test_autodetect_none(hass: HomeAssistant):
"""Test for send key with autodetection of protocol."""
mock_remotews = Mock()
mock_remotews.__enter__ = Mock(return_value=mock_remotews)
mock_remotews.__exit__ = Mock()
mock_remotews.open = Mock(side_effect=OSError("Boom"))
with patch(
"homeassistant.components.samsungtv.bridge.Remote",
side_effect=OSError("Boom"),
) as remote, patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
side_effect=OSError("Boom"),
return_value=mock_remotews,
) as remotews:
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA
@ -1221,10 +1226,7 @@ async def test_form_reauth_websocket_cannot_connect(hass, remotews: Mock):
assert result["type"] == "form"
assert result["errors"] == {}
with patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
side_effect=ConnectionFailure,
):
with patch.object(remotews, "open", side_effect=ConnectionFailure):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
@ -1257,7 +1259,7 @@ async def test_form_reauth_websocket_not_supported(hass):
assert result["errors"] == {}
with patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
"homeassistant.components.samsungtv.bridge.SamsungTVWS.open",
side_effect=WebSocketException,
):
result2 = await hass.config_entries.flow.async_configure(

View File

@ -296,10 +296,7 @@ async def test_update_connection_failure(hass, remotews, mock_now):
):
await setup_samsungtv(hass, MOCK_CONFIGWS)
with patch(
"homeassistant.components.samsungtv.bridge.SamsungTVWS",
side_effect=ConnectionFailure("Boom"),
):
with patch.object(remotews, "open", side_effect=ConnectionFailure("Boom")):
next_update = mock_now + timedelta(minutes=5)
with patch("homeassistant.util.dt.utcnow", return_value=next_update):
async_fire_time_changed(hass, next_update)