Add type hints to integration tests (part 17) (#88163)

This commit is contained in:
epenet 2023-02-15 11:14:04 +01:00 committed by GitHub
parent 04e9c7748f
commit 2cdc741900
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 469 additions and 251 deletions

View file

@ -7,6 +7,7 @@ from unittest.mock import patch
import plexapi.exceptions
import pytest
import requests.exceptions
import requests_mock
from homeassistant.components.plex import config_flow
from homeassistant.components.plex.const import (
@ -44,9 +45,12 @@ from .helpers import trigger_plex_update, wait_for_debouncer
from .mock_classes import MockGDM
from tests.common import MockConfigEntry
from tests.typing import ClientSessionGenerator
async def test_bad_credentials(hass, current_request_with_host):
async def test_bad_credentials(
hass: HomeAssistant, current_request_with_host: None
) -> None:
"""Test when provided credentials are rejected."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -74,7 +78,9 @@ async def test_bad_credentials(hass, current_request_with_host):
assert result["errors"][CONF_TOKEN] == "faulty_credentials"
async def test_bad_hostname(hass, mock_plex_calls, current_request_with_host):
async def test_bad_hostname(
hass: HomeAssistant, mock_plex_calls, current_request_with_host: None
) -> None:
"""Test when an invalid address is provided."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -103,7 +109,9 @@ async def test_bad_hostname(hass, mock_plex_calls, current_request_with_host):
assert result["errors"][CONF_HOST] == "not_found"
async def test_unknown_exception(hass, current_request_with_host):
async def test_unknown_exception(
hass: HomeAssistant, current_request_with_host: None
) -> None:
"""Test when an unknown exception is encountered."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -128,8 +136,12 @@ async def test_unknown_exception(hass, current_request_with_host):
async def test_no_servers_found(
hass, mock_plex_calls, requests_mock, empty_payload, current_request_with_host
):
hass: HomeAssistant,
mock_plex_calls,
requests_mock: requests_mock.Mocker,
empty_payload,
current_request_with_host: None,
) -> None:
"""Test when no servers are on an account."""
requests_mock.get("https://plex.tv/api/resources", text=empty_payload)
@ -157,8 +169,8 @@ async def test_no_servers_found(
async def test_single_available_server(
hass, mock_plex_calls, current_request_with_host
):
hass: HomeAssistant, mock_plex_calls, current_request_with_host: None
) -> None:
"""Test creating an entry with one server available."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -198,12 +210,12 @@ async def test_single_available_server(
async def test_multiple_servers_with_selection(
hass,
hass: HomeAssistant,
mock_plex_calls,
requests_mock,
requests_mock: requests_mock.Mocker,
plextv_resources_two_servers,
current_request_with_host,
):
current_request_with_host: None,
) -> None:
"""Test creating an entry with multiple servers available."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -256,12 +268,12 @@ async def test_multiple_servers_with_selection(
async def test_adding_last_unconfigured_server(
hass,
hass: HomeAssistant,
mock_plex_calls,
requests_mock,
requests_mock: requests_mock.Mocker,
plextv_resources_two_servers,
current_request_with_host,
):
current_request_with_host: None,
) -> None:
"""Test automatically adding last unconfigured server when multiple servers on account."""
MockConfigEntry(
domain=DOMAIN,
@ -314,13 +326,13 @@ async def test_adding_last_unconfigured_server(
async def test_all_available_servers_configured(
hass,
hass: HomeAssistant,
entry,
requests_mock,
requests_mock: requests_mock.Mocker,
plextv_account,
plextv_resources_two_servers,
current_request_with_host,
):
current_request_with_host: None,
) -> None:
"""Test when all available servers are already configured."""
entry.add_to_hass(hass)
@ -360,7 +372,7 @@ async def test_all_available_servers_configured(
assert result["reason"] == "all_configured"
async def test_option_flow(hass, entry, mock_plex_server):
async def test_option_flow(hass: HomeAssistant, entry, mock_plex_server) -> None:
"""Test config options flow selection."""
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state is ConfigEntryState.LOADED
@ -392,7 +404,9 @@ async def test_option_flow(hass, entry, mock_plex_server):
}
async def test_missing_option_flow(hass, entry, mock_plex_server):
async def test_missing_option_flow(
hass: HomeAssistant, entry, mock_plex_server
) -> None:
"""Test config options flow selection when no options stored."""
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state is ConfigEntryState.LOADED
@ -424,7 +438,9 @@ async def test_missing_option_flow(hass, entry, mock_plex_server):
}
async def test_option_flow_new_users_available(hass, entry, setup_plex_server):
async def test_option_flow_new_users_available(
hass: HomeAssistant, entry, setup_plex_server
) -> None:
"""Test config options multiselect defaults when new Plex users are seen."""
OPTIONS_OWNER_ONLY = copy.deepcopy(DEFAULT_OPTIONS)
OPTIONS_OWNER_ONLY[Platform.MEDIA_PLAYER][CONF_MONITORED_USERS] = {
@ -454,7 +470,9 @@ async def test_option_flow_new_users_available(hass, entry, setup_plex_server):
assert "[New]" in multiselect_defaults[user]
async def test_external_timed_out(hass, current_request_with_host):
async def test_external_timed_out(
hass: HomeAssistant, current_request_with_host: None
) -> None:
"""Test when external flow times out."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -478,7 +496,11 @@ async def test_external_timed_out(hass, current_request_with_host):
assert result["reason"] == "token_request_timeout"
async def test_callback_view(hass, hass_client_no_auth, current_request_with_host):
async def test_callback_view(
hass: HomeAssistant,
hass_client_no_auth: ClientSessionGenerator,
current_request_with_host: None,
) -> None:
"""Test callback view."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
@ -501,7 +523,9 @@ async def test_callback_view(hass, hass_client_no_auth, current_request_with_hos
assert resp.status == HTTPStatus.OK
async def test_manual_config(hass, mock_plex_calls, current_request_with_host):
async def test_manual_config(
hass: HomeAssistant, mock_plex_calls, current_request_with_host: None
) -> None:
"""Test creating via manual configuration."""
class WrongCertValidaitionException(requests.exceptions.SSLError):
@ -636,8 +660,12 @@ async def test_manual_config(hass, mock_plex_calls, current_request_with_host):
async def test_manual_config_with_token(
hass, mock_plex_calls, requests_mock, empty_library, empty_payload
):
hass: HomeAssistant,
mock_plex_calls,
requests_mock: requests_mock.Mocker,
empty_library,
empty_payload,
) -> None:
"""Test creating via manual configuration with only token."""
result = await hass.config_entries.flow.async_init(
@ -680,7 +708,9 @@ async def test_manual_config_with_token(
await hass.async_block_till_done()
async def test_setup_with_limited_credentials(hass, entry, setup_plex_server):
async def test_setup_with_limited_credentials(
hass: HomeAssistant, entry, setup_plex_server
) -> None:
"""Test setup with a user with limited permissions."""
with patch(
"plexapi.server.PlexServer.systemAccounts",
@ -722,8 +752,12 @@ async def test_integration_discovery(hass: HomeAssistant) -> None:
async def test_trigger_reauth(
hass, entry, mock_plex_server, mock_websocket, current_request_with_host
):
hass: HomeAssistant,
entry,
mock_plex_server,
mock_websocket,
current_request_with_host: None,
) -> None:
"""Test setup and reauthorization of a Plex token."""
assert entry.state is ConfigEntryState.LOADED
@ -768,14 +802,14 @@ async def test_trigger_reauth(
async def test_trigger_reauth_multiple_servers_available(
hass,
hass: HomeAssistant,
entry,
mock_plex_server,
mock_websocket,
current_request_with_host,
requests_mock,
current_request_with_host: None,
requests_mock: requests_mock.Mocker,
plextv_resources_two_servers,
):
) -> None:
"""Test setup and reauthorization of a Plex token when multiple servers are available."""
assert entry.state is ConfigEntryState.LOADED
@ -839,7 +873,9 @@ async def test_client_request_missing(hass: HomeAssistant) -> None:
)
async def test_client_header_issues(hass, current_request_with_host):
async def test_client_header_issues(
hass: HomeAssistant, current_request_with_host: None
) -> None:
"""Test when client headers are not set properly."""
class MockRequest: