Fix missing mocking (#60181)
This commit is contained in:
parent
83aff48db9
commit
e673d9dbd0
1 changed files with 112 additions and 77 deletions
|
@ -124,6 +124,14 @@ MOCK_DEVICE_INFO = {
|
||||||
},
|
},
|
||||||
"id": "123",
|
"id": "123",
|
||||||
}
|
}
|
||||||
|
MOCK_DEVICE_INFO_2 = {
|
||||||
|
"device": {
|
||||||
|
"type": "Samsung SmartTV",
|
||||||
|
"name": "fake2_name",
|
||||||
|
"modelName": "fake2_model",
|
||||||
|
},
|
||||||
|
"id": "345",
|
||||||
|
}
|
||||||
|
|
||||||
AUTODETECT_LEGACY = {
|
AUTODETECT_LEGACY = {
|
||||||
"name": "HomeAssistant",
|
"name": "HomeAssistant",
|
||||||
|
@ -208,7 +216,9 @@ async def test_user_websocket(hass: HomeAssistant, remotews: Mock):
|
||||||
assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
|
||||||
|
|
||||||
|
|
||||||
async def test_user_legacy_missing_auth(hass: HomeAssistant, remote: Mock):
|
async def test_user_legacy_missing_auth(
|
||||||
|
hass: HomeAssistant, remote: Mock, remotews: Mock
|
||||||
|
):
|
||||||
"""Test starting a flow by user with authentication."""
|
"""Test starting a flow by user with authentication."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.samsungtv.bridge.Remote",
|
"homeassistant.components.samsungtv.bridge.Remote",
|
||||||
|
@ -288,6 +298,10 @@ async def test_user_not_successful_2(hass: HomeAssistant, remotews: Mock):
|
||||||
async def test_ssdp(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp(hass: HomeAssistant, remote: Mock):
|
||||||
"""Test starting a flow from discovery."""
|
"""Test starting a flow from discovery."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
|
||||||
|
return_value=MOCK_DEVICE_INFO,
|
||||||
|
), patch("getmac.get_mac_address", return_value="aa:bb:cc:dd:ee:ff"):
|
||||||
# confirm to add the entry
|
# confirm to add the entry
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA
|
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA
|
||||||
|
@ -300,9 +314,9 @@ async def test_ssdp(hass: HomeAssistant, remote: Mock):
|
||||||
result["flow_id"], user_input="whatever"
|
result["flow_id"], user_input="whatever"
|
||||||
)
|
)
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == "create_entry"
|
||||||
assert result["title"] == "fake_model"
|
assert result["title"] == "fake_name (fake_model)"
|
||||||
assert result["data"][CONF_HOST] == "fake_host"
|
assert result["data"][CONF_HOST] == "fake_host"
|
||||||
assert result["data"][CONF_NAME] == "fake_model"
|
assert result["data"][CONF_NAME] == "fake_name"
|
||||||
assert result["data"][CONF_MANUFACTURER] == "Samsung fake_manufacturer"
|
assert result["data"][CONF_MANUFACTURER] == "Samsung fake_manufacturer"
|
||||||
assert result["data"][CONF_MODEL] == "fake_model"
|
assert result["data"][CONF_MODEL] == "fake_model"
|
||||||
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172de"
|
||||||
|
@ -311,6 +325,10 @@ async def test_ssdp(hass: HomeAssistant, remote: Mock):
|
||||||
async def test_ssdp_noprefix(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp_noprefix(hass: HomeAssistant, remote: Mock):
|
||||||
"""Test starting a flow from discovery without prefixes."""
|
"""Test starting a flow from discovery without prefixes."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
|
||||||
|
return_value=MOCK_DEVICE_INFO_2,
|
||||||
|
), patch("getmac.get_mac_address", return_value="aa:bb:cc:dd:ee:ff"):
|
||||||
# confirm to add the entry
|
# confirm to add the entry
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -330,15 +348,17 @@ async def test_ssdp_noprefix(hass: HomeAssistant, remote: Mock):
|
||||||
result["flow_id"], user_input="whatever"
|
result["flow_id"], user_input="whatever"
|
||||||
)
|
)
|
||||||
assert result["type"] == "create_entry"
|
assert result["type"] == "create_entry"
|
||||||
assert result["title"] == "fake2_model"
|
assert result["title"] == "fake2_name (fake2_model)"
|
||||||
assert result["data"][CONF_HOST] == "fake2_host"
|
assert result["data"][CONF_HOST] == "fake2_host"
|
||||||
assert result["data"][CONF_NAME] == "fake2_model"
|
assert result["data"][CONF_NAME] == "fake2_name"
|
||||||
assert result["data"][CONF_MANUFACTURER] == "Samsung fake2_manufacturer"
|
assert result["data"][CONF_MANUFACTURER] == "Samsung fake2_manufacturer"
|
||||||
assert result["data"][CONF_MODEL] == "fake2_model"
|
assert result["data"][CONF_MODEL] == "fake2_model"
|
||||||
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172df"
|
assert result["result"].unique_id == "0d1cef00-00dc-1000-9c80-4844f7b172df"
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_legacy_missing_auth(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp_legacy_missing_auth(
|
||||||
|
hass: HomeAssistant, remote: Mock, remotews: Mock
|
||||||
|
):
|
||||||
"""Test starting a flow from discovery with authentication."""
|
"""Test starting a flow from discovery with authentication."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.samsungtv.bridge.Remote",
|
"homeassistant.components.samsungtv.bridge.Remote",
|
||||||
|
@ -365,7 +385,9 @@ async def test_ssdp_legacy_missing_auth(hass: HomeAssistant, remote: Mock):
|
||||||
assert result["reason"] == RESULT_AUTH_MISSING
|
assert result["reason"] == RESULT_AUTH_MISSING
|
||||||
|
|
||||||
|
|
||||||
async def test_ssdp_legacy_not_supported(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp_legacy_not_supported(
|
||||||
|
hass: HomeAssistant, remote: Mock, remotews: Mock
|
||||||
|
):
|
||||||
"""Test starting a flow from discovery for not supported device."""
|
"""Test starting a flow from discovery for not supported device."""
|
||||||
|
|
||||||
# confirm to add the entry
|
# confirm to add the entry
|
||||||
|
@ -505,6 +527,11 @@ async def test_ssdp_not_successful_2(
|
||||||
async def test_ssdp_already_in_progress(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp_already_in_progress(hass: HomeAssistant, remote: Mock):
|
||||||
"""Test starting a flow from discovery twice."""
|
"""Test starting a flow from discovery twice."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
|
||||||
|
return_value=MOCK_DEVICE_INFO,
|
||||||
|
), patch("getmac.get_mac_address", return_value="aa:bb:cc:dd:ee:ff"):
|
||||||
|
|
||||||
# confirm to add the entry
|
# confirm to add the entry
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA
|
DOMAIN, context={"source": config_entries.SOURCE_SSDP}, data=MOCK_SSDP_DATA
|
||||||
|
@ -523,6 +550,11 @@ async def test_ssdp_already_in_progress(hass: HomeAssistant, remote: Mock):
|
||||||
async def test_ssdp_already_configured(hass: HomeAssistant, remote: Mock):
|
async def test_ssdp_already_configured(hass: HomeAssistant, remote: Mock):
|
||||||
"""Test starting a flow from discovery when already configured."""
|
"""Test starting a flow from discovery when already configured."""
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.bridge.SamsungTVWSBridge.device_info",
|
||||||
|
return_value=MOCK_DEVICE_INFO,
|
||||||
|
), patch("getmac.get_mac_address", return_value="aa:bb:cc:dd:ee:ff"):
|
||||||
|
|
||||||
# entry was added
|
# entry was added
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA
|
DOMAIN, context={"source": config_entries.SOURCE_USER}, data=MOCK_USER_DATA
|
||||||
|
@ -549,7 +581,7 @@ async def test_import_legacy(hass: HomeAssistant, remote: Mock):
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
|
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
|
||||||
return_value="fake_host",
|
return_value="fake_host",
|
||||||
):
|
), patch("getmac.get_mac_address", return_value="aa:bb:cc:dd:ee:ff"):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
context={"source": config_entries.SOURCE_IMPORT},
|
||||||
|
@ -570,7 +602,10 @@ async def test_import_legacy(hass: HomeAssistant, remote: Mock):
|
||||||
|
|
||||||
|
|
||||||
async def test_import_legacy_without_name(
|
async def test_import_legacy_without_name(
|
||||||
hass: HomeAssistant, remote: Mock, no_mac_address: Mock
|
hass: HomeAssistant,
|
||||||
|
remote: Mock,
|
||||||
|
remotews_no_device_info: Mock,
|
||||||
|
no_mac_address: Mock,
|
||||||
):
|
):
|
||||||
"""Test importing from yaml without a name."""
|
"""Test importing from yaml without a name."""
|
||||||
with patch(
|
with patch(
|
||||||
|
@ -595,7 +630,7 @@ async def test_import_legacy_without_name(
|
||||||
assert entries[0].data[CONF_PORT] == LEGACY_PORT
|
assert entries[0].data[CONF_PORT] == LEGACY_PORT
|
||||||
|
|
||||||
|
|
||||||
async def test_import_websocket(hass: HomeAssistant):
|
async def test_import_websocket(hass: HomeAssistant, remotews: Mock):
|
||||||
"""Test importing from yaml with hostname."""
|
"""Test importing from yaml with hostname."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
|
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
|
||||||
|
@ -929,7 +964,7 @@ async def test_autodetect_none(hass: HomeAssistant, remote: Mock, remotews: Mock
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def test_update_old_entry(hass: HomeAssistant, remote: Mock):
|
async def test_update_old_entry(hass: HomeAssistant, remote: Mock, remotews: Mock):
|
||||||
"""Test update of old entry."""
|
"""Test update of old entry."""
|
||||||
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
|
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
|
||||||
remote().rest_device_info.return_value = {
|
remote().rest_device_info.return_value = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue