Add type hints to integration tests (part 12) (#87997)

This commit is contained in:
epenet 2023-02-13 13:03:51 +01:00 committed by GitHub
parent 896dd1a36b
commit ea29cdfe83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 371 additions and 246 deletions

View file

@ -3,6 +3,7 @@ import re
from unittest.mock import patch
from pyisy import ISYConnectionError, ISYInvalidAuthError
import pytest
from homeassistant import config_entries, data_entry_flow
from homeassistant.components import dhcp, ssdp
@ -110,7 +111,7 @@ def _get_schema_default(schema, key_name):
raise KeyError(f"{key_name} not found in schema")
async def test_form(hass: HomeAssistant):
async def test_form(hass: HomeAssistant) -> None:
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
@ -138,7 +139,7 @@ async def test_form(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_invalid_host(hass: HomeAssistant):
async def test_form_invalid_host(hass: HomeAssistant) -> None:
"""Test we handle invalid host."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -158,7 +159,7 @@ async def test_form_invalid_host(hass: HomeAssistant):
assert result2["errors"] == {"base": "invalid_host"}
async def test_form_invalid_auth(hass: HomeAssistant):
async def test_form_invalid_auth(hass: HomeAssistant) -> None:
"""Test we handle invalid auth."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -176,7 +177,7 @@ async def test_form_invalid_auth(hass: HomeAssistant):
assert result2["errors"] == {CONF_PASSWORD: "invalid_auth"}
async def test_form_unknown_exeption(hass: HomeAssistant):
async def test_form_unknown_exeption(hass: HomeAssistant) -> None:
"""Test we handle generic exceptions."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -194,7 +195,7 @@ async def test_form_unknown_exeption(hass: HomeAssistant):
assert result2["errors"] == {"base": "unknown"}
async def test_form_isy_connection_error(hass: HomeAssistant):
async def test_form_isy_connection_error(hass: HomeAssistant) -> None:
"""Test we handle invalid auth."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -212,7 +213,9 @@ async def test_form_isy_connection_error(hass: HomeAssistant):
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_isy_parse_response_error(hass: HomeAssistant, caplog):
async def test_form_isy_parse_response_error(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test we handle poorly formatted XML response from ISY."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -230,7 +233,7 @@ async def test_form_isy_parse_response_error(hass: HomeAssistant, caplog):
assert "ISY Could not parse response, poorly formatted XML." in caplog.text
async def test_form_no_name_in_response(hass: HomeAssistant):
async def test_form_no_name_in_response(hass: HomeAssistant) -> None:
"""Test we handle invalid response from ISY with name not set."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
@ -250,7 +253,7 @@ async def test_form_no_name_in_response(hass: HomeAssistant):
assert result2["errors"] == {"base": "cannot_connect"}
async def test_form_existing_config_entry(hass: HomeAssistant):
async def test_form_existing_config_entry(hass: HomeAssistant) -> None:
"""Test if config entry already exists."""
MockConfigEntry(domain=DOMAIN, unique_id=MOCK_UUID).add_to_hass(hass)
@ -359,7 +362,7 @@ async def test_form_ssdp_already_configured(hass: HomeAssistant) -> None:
assert result["type"] == data_entry_flow.FlowResultType.ABORT
async def test_form_ssdp(hass: HomeAssistant):
async def test_form_ssdp(hass: HomeAssistant) -> None:
"""Test we can setup from ssdp."""
result = await hass.config_entries.flow.async_init(
@ -399,7 +402,7 @@ async def test_form_ssdp(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_ssdp_existing_entry(hass: HomeAssistant):
async def test_form_ssdp_existing_entry(hass: HomeAssistant) -> None:
"""Test we update the ip of an existing entry from ssdp."""
entry = MockConfigEntry(
@ -430,7 +433,7 @@ async def test_form_ssdp_existing_entry(hass: HomeAssistant):
assert entry.data[CONF_HOST] == f"http://3.3.3.3:80{ISY_URL_POSTFIX}"
async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant):
async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant) -> None:
"""Test we update the ip of an existing entry from ssdp with no port."""
entry = MockConfigEntry(
@ -461,7 +464,9 @@ async def test_form_ssdp_existing_entry_with_no_port(hass: HomeAssistant):
assert entry.data[CONF_HOST] == f"http://3.3.3.3:80/{ISY_URL_POSTFIX}"
async def test_form_ssdp_existing_entry_with_alternate_port(hass: HomeAssistant):
async def test_form_ssdp_existing_entry_with_alternate_port(
hass: HomeAssistant,
) -> None:
"""Test we update the ip of an existing entry from ssdp with an alternate port."""
entry = MockConfigEntry(
@ -492,7 +497,7 @@ async def test_form_ssdp_existing_entry_with_alternate_port(hass: HomeAssistant)
assert entry.data[CONF_HOST] == f"http://3.3.3.3:1443/{ISY_URL_POSTFIX}"
async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant):
async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant) -> None:
"""Test we update the ip of an existing entry from ssdp with no port and https."""
entry = MockConfigEntry(
@ -523,7 +528,7 @@ async def test_form_ssdp_existing_entry_no_port_https(hass: HomeAssistant):
assert entry.data[CONF_HOST] == f"https://3.3.3.3:443/{ISY_URL_POSTFIX}"
async def test_form_dhcp(hass: HomeAssistant):
async def test_form_dhcp(hass: HomeAssistant) -> None:
"""Test we can setup from dhcp."""
result = await hass.config_entries.flow.async_init(
@ -559,7 +564,7 @@ async def test_form_dhcp(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_dhcp_with_polisy(hass: HomeAssistant):
async def test_form_dhcp_with_polisy(hass: HomeAssistant) -> None:
"""Test we can setup from dhcp with polisy."""
result = await hass.config_entries.flow.async_init(
@ -599,7 +604,7 @@ async def test_form_dhcp_with_polisy(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_dhcp_with_eisy(hass: HomeAssistant):
async def test_form_dhcp_with_eisy(hass: HomeAssistant) -> None:
"""Test we can setup from dhcp with eisy."""
result = await hass.config_entries.flow.async_init(
@ -639,7 +644,7 @@ async def test_form_dhcp_with_eisy(hass: HomeAssistant):
assert len(mock_setup_entry.mock_calls) == 1
async def test_form_dhcp_existing_entry(hass: HomeAssistant):
async def test_form_dhcp_existing_entry(hass: HomeAssistant) -> None:
"""Test we update the ip of an existing entry from dhcp."""
entry = MockConfigEntry(
@ -666,7 +671,7 @@ async def test_form_dhcp_existing_entry(hass: HomeAssistant):
assert entry.data[CONF_HOST] == f"http://1.2.3.4{ISY_URL_POSTFIX}"
async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant):
async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant) -> None:
"""Test we update the ip of an existing entry from dhcp preserves port."""
entry = MockConfigEntry(
@ -697,7 +702,7 @@ async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant):
assert entry.data[CONF_USERNAME] == "bob"
async def test_form_dhcp_existing_ignored_entry(hass: HomeAssistant):
async def test_form_dhcp_existing_ignored_entry(hass: HomeAssistant) -> None:
"""Test we handled an ignored entry from dhcp."""
entry = MockConfigEntry(