Add type hints to integration tests (part 7) (#87980)

This commit is contained in:
epenet 2023-02-13 09:53:09 +01:00 committed by GitHub
parent b9beed4624
commit b68f502769
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
51 changed files with 755 additions and 395 deletions

View file

@ -1,5 +1,4 @@
"""The tests for the google calendar platform."""
from __future__ import annotations
from collections.abc import Awaitable, Callable
@ -33,6 +32,7 @@ from .conftest import (
from tests.common import async_fire_time_changed
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
TEST_ENTITY = TEST_API_ENTITY
TEST_ENTITY_NAME = TEST_API_ENTITY_NAME
@ -145,7 +145,9 @@ async def ws_client(
return create_client
async def test_all_day_event(hass, mock_events_list_items, component_setup):
async def test_all_day_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test for an all day calendar event."""
week_from_today = dt_util.now().date() + datetime.timedelta(days=7)
end_event = week_from_today + datetime.timedelta(days=1)
@ -174,7 +176,9 @@ async def test_all_day_event(hass, mock_events_list_items, component_setup):
}
async def test_future_event(hass, mock_events_list_items, component_setup):
async def test_future_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test for an upcoming event."""
one_hour_from_now = dt_util.now() + datetime.timedelta(minutes=30)
end_event = one_hour_from_now + datetime.timedelta(minutes=60)
@ -203,7 +207,9 @@ async def test_future_event(hass, mock_events_list_items, component_setup):
}
async def test_in_progress_event(hass, mock_events_list_items, component_setup):
async def test_in_progress_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an event that is active now."""
middle_of_event = dt_util.now() - datetime.timedelta(minutes=30)
end_event = middle_of_event + datetime.timedelta(minutes=60)
@ -232,7 +238,9 @@ async def test_in_progress_event(hass, mock_events_list_items, component_setup):
}
async def test_offset_in_progress_event(hass, mock_events_list_items, component_setup):
async def test_offset_in_progress_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an event that is active now with an offset."""
middle_of_event = dt_util.now() + datetime.timedelta(minutes=14)
end_event = middle_of_event + datetime.timedelta(minutes=60)
@ -264,8 +272,8 @@ async def test_offset_in_progress_event(hass, mock_events_list_items, component_
async def test_all_day_offset_in_progress_event(
hass, mock_events_list_items, component_setup
):
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an all day event that is currently in progress due to an offset."""
tomorrow = dt_util.now().date() + datetime.timedelta(days=1)
end_event = tomorrow + datetime.timedelta(days=1)
@ -296,7 +304,9 @@ async def test_all_day_offset_in_progress_event(
}
async def test_all_day_offset_event(hass, mock_events_list_items, component_setup):
async def test_all_day_offset_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an all day event that not in progress due to an offset."""
now = dt_util.now()
day_after_tomorrow = now.date() + datetime.timedelta(days=2)
@ -329,7 +339,9 @@ async def test_all_day_offset_event(hass, mock_events_list_items, component_setu
}
async def test_missing_summary(hass, mock_events_list_items, component_setup):
async def test_missing_summary(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test that a summary is optional."""
start_event = dt_util.now() + datetime.timedelta(minutes=14)
end_event = start_event + datetime.timedelta(minutes=60)
@ -360,11 +372,11 @@ async def test_missing_summary(hass, mock_events_list_items, component_setup):
async def test_update_error(
hass,
hass: HomeAssistant,
component_setup,
mock_events_list,
aioclient_mock,
):
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test that the calendar update handles a server error."""
now = dt_util.now()
@ -435,8 +447,11 @@ async def test_update_error(
async def test_calendars_api(
hass, hass_client, component_setup, mock_events_list_items
):
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
component_setup,
mock_events_list_items,
) -> None:
"""Test the Rest API returns the calendar."""
mock_events_list_items([])
assert await component_setup()
@ -454,13 +469,13 @@ async def test_calendars_api(
async def test_http_event_api_failure(
hass,
hass_client,
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
component_setup,
mock_calendars_list,
mock_events_list,
aioclient_mock,
):
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test the Rest API response during a calendar failure."""
mock_events_list({}, exc=ClientError())
@ -478,8 +493,11 @@ async def test_http_event_api_failure(
@pytest.mark.freeze_time("2022-03-27 12:05:00+00:00")
async def test_http_api_event(
hass, hass_client, mock_events_list_items, component_setup
):
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_events_list_items,
component_setup,
) -> None:
"""Test querying the API and fetching events from the server."""
hass.config.set_time_zone("Asia/Baghdad")
event = {
@ -503,8 +521,11 @@ async def test_http_api_event(
@pytest.mark.freeze_time("2022-03-27 12:05:00+00:00")
async def test_http_api_all_day_event(
hass, hass_client, mock_events_list_items, component_setup
):
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_events_list_items,
component_setup,
) -> None:
"""Test querying the API and fetching events from the server."""
event = {
**TEST_EVENT,
@ -541,14 +562,14 @@ async def test_http_api_all_day_event(
],
)
async def test_opaque_event(
hass,
hass_client,
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_calendars_yaml,
mock_events_list_items,
component_setup,
transparency,
expect_visible_event,
):
) -> None:
"""Test querying the API and fetching events from the server."""
event = {
**TEST_EVENT,
@ -572,11 +593,11 @@ async def test_opaque_event(
@pytest.mark.parametrize("mock_test_setup", [None])
async def test_scan_calendar_error(
hass,
hass: HomeAssistant,
component_setup,
mock_calendars_list,
config_entry,
):
) -> None:
"""Test that the calendar update handles a server error."""
config_entry.add_to_hass(hass)
mock_calendars_list({}, exc=ClientError())
@ -586,8 +607,8 @@ async def test_scan_calendar_error(
async def test_future_event_update_behavior(
hass, mock_events_list_items, component_setup
):
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an future event that becomes active."""
now = dt_util.now()
now_utc = dt_util.utcnow()
@ -621,8 +642,8 @@ async def test_future_event_update_behavior(
async def test_future_event_offset_update_behavior(
hass, mock_events_list_items, component_setup
):
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test an future event that becomes active."""
now = dt_util.now()
now_utc = dt_util.utcnow()
@ -660,11 +681,11 @@ async def test_future_event_offset_update_behavior(
async def test_unique_id(
hass,
hass: HomeAssistant,
mock_events_list_items,
component_setup,
config_entry,
):
) -> None:
"""Test entity is created with a unique id based on the config entry."""
mock_events_list_items([])
assert await component_setup()
@ -682,12 +703,12 @@ async def test_unique_id(
"old_unique_id", [CALENDAR_ID, f"{CALENDAR_ID}-we_are_we_are_a_test_calendar"]
)
async def test_unique_id_migration(
hass,
hass: HomeAssistant,
mock_events_list_items,
component_setup,
config_entry,
old_unique_id,
):
) -> None:
"""Test that old unique id format is migrated to the new format that supports multiple accounts."""
entity_registry = er.async_get(hass)
@ -737,12 +758,12 @@ async def test_unique_id_migration(
],
)
async def test_invalid_unique_id_cleanup(
hass,
hass: HomeAssistant,
mock_events_list_items,
component_setup,
config_entry,
mock_calendars_yaml,
):
) -> None:
"""Test that old unique id format that is not actually unique is removed."""
entity_registry = er.async_get(hass)
@ -789,13 +810,13 @@ async def test_invalid_unique_id_cleanup(
],
)
async def test_all_day_iter_order(
hass,
hass_client,
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
mock_events_list_items,
component_setup,
time_zone,
event_order,
):
) -> None:
"""Test the sort order of an all day events depending on the time zone."""
hass.config.set_time_zone(time_zone)
mock_events_list_items(
@ -921,12 +942,12 @@ async def test_websocket_create_all_day(
async def test_websocket_delete(
ws_client: ClientFixture,
hass_client,
hass_client: ClientSessionGenerator,
component_setup,
mock_events_list: ApiResult,
mock_events_list_items: ApiResult,
aioclient_mock,
):
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test websocket delete command."""
mock_events_list_items(
[
@ -964,12 +985,12 @@ async def test_websocket_delete(
async def test_websocket_delete_recurring_event_instance(
ws_client: ClientFixture,
hass_client,
hass_client: ClientSessionGenerator,
component_setup,
mock_events_list: ApiResult,
mock_events_list_items: ApiResult,
aioclient_mock,
):
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test websocket delete command with recurring events."""
mock_events_list_items(
[
@ -1159,7 +1180,9 @@ async def test_readonly_search_calendar(
@pytest.mark.parametrize("calendar_access_role", ["reader", "freeBusyReader"])
async def test_all_day_reader_access(hass, mock_events_list_items, component_setup):
async def test_all_day_reader_access(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test that reader / freebusy reader access can load properly."""
week_from_today = dt_util.now().date() + datetime.timedelta(days=7)
end_event = week_from_today + datetime.timedelta(days=1)
@ -1188,7 +1211,9 @@ async def test_all_day_reader_access(hass, mock_events_list_items, component_set
@pytest.mark.parametrize("calendar_access_role", ["reader", "freeBusyReader"])
async def test_reader_in_progress_event(hass, mock_events_list_items, component_setup):
async def test_reader_in_progress_event(
hass: HomeAssistant, mock_events_list_items, component_setup
) -> None:
"""Test reader access for an event in process."""
middle_of_event = dt_util.now() - datetime.timedelta(minutes=30)
end_event = middle_of_event + datetime.timedelta(minutes=60)