Prevent 3rd party lib from opening sockets in samsungtv tests (#56334)

This commit is contained in:
Erik Montnemery 2021-09-19 10:24:27 +02:00 committed by GitHub
parent 80a57f5118
commit ec52763706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 13 deletions

View file

@ -112,3 +112,10 @@ def delay_fixture():
def mock_now():
"""Fixture for dtutil.now."""
return dt_util.utcnow()
@pytest.fixture(name="no_mac_address")
def mac_address_fixture():
"""Patch getmac.get_mac_address."""
with patch("getmac.get_mac_address", return_value=None) as mac:
yield mac

View file

@ -389,7 +389,9 @@ async def test_ssdp_legacy_not_supported(hass: HomeAssistant, remote: Mock):
async def test_ssdp_websocket_success_populates_mac_address(
hass: HomeAssistant, remotews: Mock
hass: HomeAssistant,
remote: Mock,
remotews: Mock,
):
"""Test starting a flow from ssdp for a supported device populates the mac."""
result = await hass.config_entries.flow.async_init(
@ -441,7 +443,9 @@ async def test_ssdp_model_not_supported(hass: HomeAssistant, remote: Mock):
assert result["reason"] == RESULT_NOT_SUPPORTED
async def test_ssdp_not_successful(hass: HomeAssistant, remote: Mock):
async def test_ssdp_not_successful(
hass: HomeAssistant, remote: Mock, no_mac_address: Mock
):
"""Test starting a flow from discovery but no device found."""
with patch(
"homeassistant.components.samsungtv.bridge.Remote",
@ -469,7 +473,9 @@ async def test_ssdp_not_successful(hass: HomeAssistant, remote: Mock):
assert result["reason"] == RESULT_CANNOT_CONNECT
async def test_ssdp_not_successful_2(hass: HomeAssistant, remote: Mock):
async def test_ssdp_not_successful_2(
hass: HomeAssistant, remote: Mock, no_mac_address: Mock
):
"""Test starting a flow from discovery but no device found."""
with patch(
"homeassistant.components.samsungtv.bridge.Remote",
@ -564,7 +570,9 @@ async def test_import_legacy(hass: HomeAssistant, remote: Mock):
assert entries[0].data[CONF_PORT] == LEGACY_PORT
async def test_import_legacy_without_name(hass: HomeAssistant, remote: Mock):
async def test_import_legacy_without_name(
hass: HomeAssistant, remote: Mock, no_mac_address: Mock
):
"""Test importing from yaml without a name."""
with patch(
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
@ -651,7 +659,7 @@ async def test_import_unknown_host(hass: HomeAssistant, remotews: Mock):
assert result["reason"] == RESULT_UNKNOWN_HOST
async def test_dhcp(hass: HomeAssistant, remotews: Mock):
async def test_dhcp(hass: HomeAssistant, remote: Mock, remotews: Mock):
"""Test starting a flow from dhcp."""
# confirm to add the entry
result = await hass.config_entries.flow.async_init(
@ -677,7 +685,7 @@ async def test_dhcp(hass: HomeAssistant, remotews: Mock):
assert result["result"].unique_id == "be9554b9-c9fb-41f4-8920-22da015376a4"
async def test_zeroconf(hass: HomeAssistant, remotews: Mock):
async def test_zeroconf(hass: HomeAssistant, remote: Mock, remotews: Mock):
"""Test starting a flow from zeroconf."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
@ -715,7 +723,7 @@ async def test_zeroconf_ignores_soundbar(hass: HomeAssistant, remotews_soundbar:
async def test_zeroconf_no_device_info(
hass: HomeAssistant, remotews_no_device_info: Mock
hass: HomeAssistant, remote: Mock, remotews_no_device_info: Mock
):
"""Test starting a flow from zeroconf where device_info returns None."""
result = await hass.config_entries.flow.async_init(

View file

@ -53,7 +53,7 @@ REMOTE_CALL = {
}
async def test_setup(hass: HomeAssistant, remote: Mock):
async def test_setup(hass: HomeAssistant, remote: Mock, no_mac_address: Mock):
"""Test Samsung TV integration is setup."""
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote, patch(
"homeassistant.components.samsungtv.config_flow.socket.gethostbyname",
@ -129,7 +129,9 @@ async def test_setup_duplicate_config(hass: HomeAssistant, remote: Mock, caplog)
assert "duplicate host entries found" in caplog.text
async def test_setup_duplicate_entries(hass: HomeAssistant, remote: Mock, caplog):
async def test_setup_duplicate_entries(
hass: HomeAssistant, remote: Mock, no_mac_address: Mock, caplog
):
"""Test duplicate setup of platform."""
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()

View file

@ -127,10 +127,9 @@ def delay_fixture():
yield delay
@pytest.fixture
def mock_now():
"""Fixture for dtutil.now."""
return dt_util.utcnow()
@pytest.fixture(autouse=True)
def mock_no_mac_address(no_mac_address):
"""Fake mac address in all mediaplayer tests."""
async def setup_samsungtv(hass, config):