Skip to content

Commit 249c153

Browse files
authored
Address comments for Brother tests (home-assistant#156877)
1 parent 081b769 commit 249c153

File tree

3 files changed

+35
-47
lines changed

3 files changed

+35
-47
lines changed

tests/components/brother/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
from tests.common import MockConfigEntry
66

77

8-
async def init_integration(
9-
hass: HomeAssistant, entry: MockConfigEntry
10-
) -> MockConfigEntry:
8+
async def init_integration(hass: HomeAssistant, entry: MockConfigEntry) -> None:
119
"""Set up the Brother integration in Home Assistant."""
1210
entry.add_to_hass(hass)
1311

tests/components/brother/conftest.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ def mock_setup_entry() -> Generator[AsyncMock]:
9090
yield mock_setup_entry
9191

9292

93-
@pytest.fixture
94-
def mock_unload_entry() -> Generator[AsyncMock]:
95-
"""Override async_unload_entry."""
96-
with patch(
97-
"homeassistant.components.brother.async_unload_entry", return_value=True
98-
) as mock_unload_entry:
99-
yield mock_unload_entry
100-
101-
10293
@pytest.fixture
10394
def mock_brother() -> Generator[AsyncMock]:
10495
"""Mock the Brother class."""

tests/components/brother/test_config_flow.py

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Define tests for the Brother Printer config flow."""
22

33
from ipaddress import ip_address
4-
from unittest.mock import AsyncMock, patch
4+
from unittest.mock import AsyncMock
55

66
from brother import SnmpError, UnsupportedModelError
77
import pytest
@@ -27,17 +27,7 @@
2727
SECTION_ADVANCED_SETTINGS: {CONF_PORT: 161, CONF_COMMUNITY: "public"},
2828
}
2929

30-
pytestmark = pytest.mark.usefixtures("mock_setup_entry", "mock_unload_entry")
31-
32-
33-
async def test_show_form(hass: HomeAssistant) -> None:
34-
"""Test that the form is served with no input."""
35-
result = await hass.config_entries.flow.async_init(
36-
DOMAIN, context={"source": SOURCE_USER}
37-
)
38-
39-
assert result["type"] is FlowResultType.FORM
40-
assert result["step_id"] == "user"
30+
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
4131

4232

4333
@pytest.mark.parametrize("host", ["example.local", "127.0.0.1", "2001:db8::1428:57ab"])
@@ -49,9 +39,15 @@ async def test_create_entry(
4939
config[CONF_HOST] = host
5040

5141
result = await hass.config_entries.flow.async_init(
52-
DOMAIN,
53-
context={"source": SOURCE_USER},
54-
data=config,
42+
DOMAIN, context={"source": SOURCE_USER}
43+
)
44+
45+
assert result["type"] is FlowResultType.FORM
46+
assert result["step_id"] == "user"
47+
48+
result = await hass.config_entries.flow.async_configure(
49+
flow_id=result["flow_id"],
50+
user_input=config,
5551
)
5652

5753
assert result["type"] is FlowResultType.CREATE_ENTRY
@@ -60,6 +56,7 @@ async def test_create_entry(
6056
assert result["data"][CONF_TYPE] == "laser"
6157
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_PORT] == 161
6258
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY] == "public"
59+
assert result["result"].unique_id == "0123456789"
6360

6461

6562
async def test_invalid_hostname(
@@ -97,6 +94,7 @@ async def test_invalid_hostname(
9794
assert result["data"][CONF_TYPE] == "laser"
9895
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_PORT] == 161
9996
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY] == "public"
97+
assert result["result"].unique_id == "0123456789"
10098

10199

102100
@pytest.mark.parametrize(
@@ -142,6 +140,7 @@ async def test_errors(
142140
assert result["data"][CONF_TYPE] == "laser"
143141
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_PORT] == 161
144142
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY] == "public"
143+
assert result["result"].unique_id == "0123456789"
145144

146145

147146
async def test_unsupported_model_error(
@@ -250,32 +249,31 @@ async def test_zeroconf_device_exists_abort(
250249
assert mock_config_entry.data[CONF_HOST] == "127.0.0.1"
251250

252251

253-
async def test_zeroconf_no_probe_existing_device(hass: HomeAssistant) -> None:
252+
async def test_zeroconf_no_probe_existing_device(
253+
hass: HomeAssistant, mock_brother_client: AsyncMock
254+
) -> None:
254255
"""Test we do not probe the device is the host is already configured."""
255256
entry = MockConfigEntry(domain=DOMAIN, unique_id="0123456789", data=CONFIG)
256257
entry.add_to_hass(hass)
257-
with (
258-
patch("homeassistant.components.brother.Brother.initialize"),
259-
patch("homeassistant.components.brother.Brother._get_data") as mock_get_data,
260-
):
261-
result = await hass.config_entries.flow.async_init(
262-
DOMAIN,
263-
context={"source": SOURCE_ZEROCONF},
264-
data=ZeroconfServiceInfo(
265-
ip_address=ip_address("127.0.0.1"),
266-
ip_addresses=[ip_address("127.0.0.1")],
267-
hostname="example.local.",
268-
name="Brother Printer",
269-
port=None,
270-
properties={},
271-
type="mock_type",
272-
),
273-
)
274-
await hass.async_block_till_done()
258+
259+
result = await hass.config_entries.flow.async_init(
260+
DOMAIN,
261+
context={"source": SOURCE_ZEROCONF},
262+
data=ZeroconfServiceInfo(
263+
ip_address=ip_address("127.0.0.1"),
264+
ip_addresses=[ip_address("127.0.0.1")],
265+
hostname="example.local.",
266+
name="Brother Printer",
267+
port=None,
268+
properties={},
269+
type="mock_type",
270+
),
271+
)
272+
await hass.async_block_till_done()
275273

276274
assert result["type"] is FlowResultType.ABORT
277275
assert result["reason"] == "already_configured"
278-
assert len(mock_get_data.mock_calls) == 0
276+
mock_brother_client.async_update.assert_not_called()
279277

280278

281279
async def test_zeroconf_confirm_create_entry(
@@ -315,6 +313,7 @@ async def test_zeroconf_confirm_create_entry(
315313
assert result["data"][CONF_TYPE] == "laser"
316314
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_PORT] == 161
317315
assert result["data"][SECTION_ADVANCED_SETTINGS][CONF_COMMUNITY] == "public"
316+
assert result["result"].unique_id == "0123456789"
318317

319318

320319
async def test_reconfigure_successful(

0 commit comments

Comments
 (0)