Skip to content

Commit 1b0b6e6

Browse files
authored
Fix squeezebox tests opening sockets (home-assistant#156373)
1 parent 12fc79e commit 1b0b6e6

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

tests/components/squeezebox/test_config_flow.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from unittest.mock import patch
55

66
from pysqueezebox import Server
7+
import pytest
78

89
from homeassistant import config_entries
910
from homeassistant.components.squeezebox.const import (
@@ -96,6 +97,7 @@ async def test_user_form(hass: HomeAssistant) -> None:
9697
assert len(mock_setup_entry.mock_calls) == 1
9798

9899

100+
@pytest.mark.usefixtures("mock_setup_entry")
99101
async def test_options_form(hass: HomeAssistant) -> None:
100102
"""Test we can configure options."""
101103
entry = MockConfigEntry(
@@ -605,8 +607,8 @@ async def test_dhcp_discovery_no_server_found(hass: HomeAssistant) -> None:
605607

606608
# Now try to complete the edit step with full schema
607609
with patch(
608-
"homeassistant.components.squeezebox.config_flow.async_discover",
609-
mock_failed_discover,
610+
"pysqueezebox.Server.async_query",
611+
return_value=None,
610612
):
611613
result = await hass.config_entries.flow.async_configure(
612614
result["flow_id"],
@@ -621,7 +623,7 @@ async def test_dhcp_discovery_no_server_found(hass: HomeAssistant) -> None:
621623

622624
assert result["type"] is FlowResultType.FORM
623625
assert result["step_id"] == "edit"
624-
assert result["errors"] == {"base": "unknown"}
626+
assert result["errors"] == {"base": "cannot_connect"}
625627

626628

627629
async def test_dhcp_discovery_existing_player(

tests/components/squeezebox/test_init.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ def squeezebox_media_player_platform():
2626
yield
2727

2828

29+
@pytest.fixture(autouse=True)
30+
def mock_discovery():
31+
"""Mock discovery of squeezebox players."""
32+
with patch("homeassistant.components.squeezebox.media_player.async_discover"):
33+
yield
34+
35+
2936
async def test_init_api_fail(
3037
hass: HomeAssistant,
3138
config_entry: MockConfigEntry,

tests/components/squeezebox/test_media_player.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ def squeezebox_media_player_platform():
8686
yield
8787

8888

89+
@pytest.fixture(autouse=True)
90+
def mock_discovery():
91+
"""Mock discovery of squeezebox players."""
92+
with patch("homeassistant.components.squeezebox.media_player.async_discover"):
93+
yield
94+
95+
8996
async def test_entity_registry(
9097
hass: HomeAssistant,
9198
entity_registry: EntityRegistry,

0 commit comments

Comments
 (0)