Move mock_zeroconf to decorator in tests (#119061)
This commit is contained in:
parent
ae59d0eadf
commit
b2a54c50e2
7 changed files with 116 additions and 93 deletions
|
@ -47,8 +47,9 @@ def mock_setup_entry():
|
|||
yield
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_connection_works(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test we can finish a config flow."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
@ -89,8 +90,9 @@ async def test_user_connection_works(
|
|||
assert mock_client.noise_psk is None
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_connection_updates_host(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test setup up the same name updates the host."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -118,8 +120,9 @@ async def test_user_connection_updates_host(
|
|||
assert entry.data[CONF_HOST] == "127.0.0.1"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_sets_unique_id(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test that the user flow sets the unique id."""
|
||||
service_info = zeroconf.ZeroconfServiceInfo(
|
||||
|
@ -170,8 +173,9 @@ async def test_user_sets_unique_id(
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_resolve_error(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test user step with IP resolve error."""
|
||||
|
||||
|
@ -195,8 +199,9 @@ async def test_user_resolve_error(
|
|||
assert len(mock_client.disconnect.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_causes_zeroconf_to_abort(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test that the user flow sets the unique id and aborts the zeroconf flow."""
|
||||
service_info = zeroconf.ZeroconfServiceInfo(
|
||||
|
@ -242,8 +247,9 @@ async def test_user_causes_zeroconf_to_abort(
|
|||
assert not hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_connection_error(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test user step with connection error."""
|
||||
mock_client.device_info.side_effect = APIConnectionError
|
||||
|
@ -263,8 +269,9 @@ async def test_user_connection_error(
|
|||
assert len(mock_client.disconnect.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_with_password(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test user step with password."""
|
||||
mock_client.device_info.return_value = DeviceInfo(uses_password=True, name="test")
|
||||
|
@ -293,9 +300,8 @@ async def test_user_with_password(
|
|||
assert mock_client.password == "password1"
|
||||
|
||||
|
||||
async def test_user_invalid_password(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_invalid_password(hass: HomeAssistant, mock_client) -> None:
|
||||
"""Test user step with invalid password."""
|
||||
mock_client.device_info.return_value = DeviceInfo(uses_password=True, name="test")
|
||||
|
||||
|
@ -319,11 +325,11 @@ async def test_user_invalid_password(
|
|||
assert result["errors"] == {"base": "invalid_auth"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_dashboard_has_wrong_key(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_zeroconf: None,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step with key from dashboard that is incorrect."""
|
||||
|
@ -366,11 +372,11 @@ async def test_user_dashboard_has_wrong_key(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_discovers_name_and_gets_key_from_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_zeroconf: None,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name and get the key from the dashboard."""
|
||||
|
@ -418,12 +424,12 @@ async def test_user_discovers_name_and_gets_key_from_dashboard(
|
|||
"dashboard_exception",
|
||||
[aiohttp.ClientError(), json.JSONDecodeError("test", "test", 0)],
|
||||
)
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
|
||||
hass: HomeAssistant,
|
||||
dashboard_exception: Exception,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_zeroconf: None,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name and get the key from the dashboard."""
|
||||
|
@ -474,11 +480,11 @@ async def test_user_discovers_name_and_gets_key_from_dashboard_fails(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_discovers_name_and_dashboard_is_unavailable(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_dashboard,
|
||||
mock_zeroconf: None,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name but the dashboard is unavailable."""
|
||||
|
@ -529,8 +535,9 @@ async def test_user_discovers_name_and_dashboard_is_unavailable(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_login_connection_error(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test user step with connection error on login attempt."""
|
||||
mock_client.device_info.return_value = DeviceInfo(uses_password=True, name="test")
|
||||
|
@ -555,8 +562,9 @@ async def test_login_connection_error(
|
|||
assert result["errors"] == {"base": "connection_error"}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_initiation(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery importing works."""
|
||||
service_info = zeroconf.ZeroconfServiceInfo(
|
||||
|
@ -587,8 +595,9 @@ async def test_discovery_initiation(
|
|||
assert result["result"].unique_id == "11:22:33:44:55:aa"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_no_mac(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery aborted if old ESPHome without mac in zeroconf."""
|
||||
service_info = zeroconf.ZeroconfServiceInfo(
|
||||
|
@ -694,8 +703,9 @@ async def test_discovery_updates_unique_id(
|
|||
assert entry.unique_id == "11:22:33:44:55:aa"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_requires_psk(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test user step with requiring encryption key."""
|
||||
mock_client.device_info.side_effect = RequiresEncryptionAPIError
|
||||
|
@ -715,8 +725,9 @@ async def test_user_requires_psk(
|
|||
assert len(mock_client.disconnect.mock_calls) == 2
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_encryption_key_valid_psk(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test encryption key step with valid key."""
|
||||
|
||||
|
@ -749,8 +760,9 @@ async def test_encryption_key_valid_psk(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_encryption_key_invalid_psk(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test encryption key step with invalid key."""
|
||||
|
||||
|
@ -776,9 +788,8 @@ async def test_encryption_key_invalid_psk(
|
|||
assert mock_client.noise_psk == INVALID_NOISE_PSK
|
||||
|
||||
|
||||
async def test_reauth_initiation(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None
|
||||
) -> None:
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_initiation(hass: HomeAssistant, mock_client) -> None:
|
||||
"""Test reauth initiation shows form."""
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
|
@ -798,8 +809,9 @@ async def test_reauth_initiation(
|
|||
assert result["step_id"] == "reauth_confirm"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_confirm_valid(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test reauth initiation with valid PSK."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -827,10 +839,10 @@ async def test_reauth_confirm_valid(
|
|||
assert entry.data[CONF_NOISE_PSK] == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_fixed_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
|
@ -878,10 +890,10 @@ async def test_reauth_fixed_via_dashboard(
|
|||
assert len(mock_get_encryption_key.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_fixed_via_dashboard_add_encryption_remove_password(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_config_entry,
|
||||
mock_setup_entry: None,
|
||||
|
@ -946,10 +958,10 @@ async def test_reauth_fixed_via_remove_password(
|
|||
assert mock_config_entry.data[CONF_PASSWORD] == ""
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_fixed_via_dashboard_at_confirm(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
|
@ -1003,8 +1015,9 @@ async def test_reauth_fixed_via_dashboard_at_confirm(
|
|||
assert len(mock_get_encryption_key.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_confirm_invalid(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test reauth initiation with invalid PSK."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1044,8 +1057,9 @@ async def test_reauth_confirm_invalid(
|
|||
assert entry.data[CONF_NOISE_PSK] == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_reauth_confirm_invalid_with_unique_id(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test reauth initiation with invalid PSK."""
|
||||
entry = MockConfigEntry(
|
||||
|
@ -1166,10 +1180,10 @@ async def test_discovery_hassio(hass: HomeAssistant, mock_dashboard) -> None:
|
|||
assert dash.addon_slug == "mock-slug"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_zeroconf_encryption_key_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
|
@ -1232,10 +1246,10 @@ async def test_zeroconf_encryption_key_via_dashboard(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_zeroconf_encryption_key_via_dashboard_with_api_encryption_prop(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
|
@ -1298,10 +1312,10 @@ async def test_zeroconf_encryption_key_via_dashboard_with_api_encryption_prop(
|
|||
assert mock_client.noise_psk == VALID_NOISE_PSK
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_zeroconf_no_encryption_key_via_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_dashboard,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
|
@ -1375,10 +1389,10 @@ async def test_option_flow(
|
|||
assert len(mock_reload.mock_calls) == int(option_value)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_user_discovers_name_no_dashboard(
|
||||
hass: HomeAssistant,
|
||||
mock_client,
|
||||
mock_zeroconf: None,
|
||||
mock_setup_entry: None,
|
||||
) -> None:
|
||||
"""Test user step can discover the name and the there is not dashboard."""
|
||||
|
@ -1434,22 +1448,25 @@ async def mqtt_discovery_test_abort(hass: HomeAssistant, payload: str, reason: s
|
|||
assert flow["reason"] == reason
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_no_mac(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery aborted if mac is missing in MQTT payload."""
|
||||
await mqtt_discovery_test_abort(hass, "{}", "mqtt_missing_mac")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_no_api(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery aborted if api/port is missing in MQTT payload."""
|
||||
await mqtt_discovery_test_abort(hass, '{"mac":"abcdef123456"}', "mqtt_missing_api")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_no_ip(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery aborted if ip is missing in MQTT payload."""
|
||||
await mqtt_discovery_test_abort(
|
||||
|
@ -1457,8 +1474,9 @@ async def test_discovery_mqtt_no_ip(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("mock_zeroconf")
|
||||
async def test_discovery_mqtt_initiation(
|
||||
hass: HomeAssistant, mock_client, mock_zeroconf: None, mock_setup_entry: None
|
||||
hass: HomeAssistant, mock_client, mock_setup_entry: None
|
||||
) -> None:
|
||||
"""Test discovery importing works."""
|
||||
service_info = MqttServiceInfo(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue