Skip to content

Commit

Permalink
Add type hints to integration tests (part 4) (home-assistant#87848)
Browse files Browse the repository at this point in the history
  • Loading branch information
epenet authored Feb 11, 2023
1 parent a385a00 commit 9f688a5
Show file tree
Hide file tree
Showing 52 changed files with 733 additions and 336 deletions.
3 changes: 2 additions & 1 deletion tests/components/comfoconnect/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from homeassistant.components.sensor import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component

from tests.common import assert_setup_component
Expand Down Expand Up @@ -50,7 +51,7 @@ async def setup_sensor(hass, mock_bridge_discover, mock_comfoconnect_command):
await hass.async_block_till_done()


async def test_sensors(hass, setup_sensor):
async def test_sensors(hass: HomeAssistant, setup_sensor) -> None:
"""Test the sensors."""
state = hass.states.get("sensor.comfoairq_inside_humidity")
assert state is not None
Expand Down
34 changes: 26 additions & 8 deletions tests/components/config/test_area_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pytest_unordered import unordered

from homeassistant.components.config import area_registry
from homeassistant.core import HomeAssistant
from homeassistant.helpers import area_registry as ar

from tests.common import ANY

Expand All @@ -14,7 +16,9 @@ def client(hass, hass_ws_client):
return hass.loop.run_until_complete(hass_ws_client(hass))


async def test_list_areas(hass, client, area_registry):
async def test_list_areas(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test list entries."""
area1 = area_registry.async_create("mock 1")
area2 = area_registry.async_create(
Expand All @@ -40,7 +44,9 @@ async def test_list_areas(hass, client, area_registry):
]


async def test_create_area(hass, client, area_registry):
async def test_create_area(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test create entry."""
# Create area with only mandatory parameters
await client.send_json(
Expand Down Expand Up @@ -79,7 +85,9 @@ async def test_create_area(hass, client, area_registry):
assert len(area_registry.areas) == 2


async def test_create_area_with_name_already_in_use(hass, client, area_registry):
async def test_create_area_with_name_already_in_use(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test create entry that should fail."""
area_registry.async_create("mock")

Expand All @@ -95,7 +103,9 @@ async def test_create_area_with_name_already_in_use(hass, client, area_registry)
assert len(area_registry.areas) == 1


async def test_delete_area(hass, client, area_registry):
async def test_delete_area(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test delete entry."""
area = area_registry.async_create("mock")

Expand All @@ -109,7 +119,9 @@ async def test_delete_area(hass, client, area_registry):
assert not area_registry.areas


async def test_delete_non_existing_area(hass, client, area_registry):
async def test_delete_non_existing_area(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test delete entry that should fail."""
area_registry.async_create("mock")

Expand All @@ -125,7 +137,9 @@ async def test_delete_non_existing_area(hass, client, area_registry):
assert len(area_registry.areas) == 1


async def test_update_area(hass, client, area_registry):
async def test_update_area(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test update entry."""
area = area_registry.async_create("mock 1")

Expand Down Expand Up @@ -171,7 +185,9 @@ async def test_update_area(hass, client, area_registry):
assert len(area_registry.areas) == 1


async def test_update_area_with_same_name(hass, client, area_registry):
async def test_update_area_with_same_name(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test update entry."""
area = area_registry.async_create("mock 1")

Expand All @@ -191,7 +207,9 @@ async def test_update_area_with_same_name(hass, client, area_registry):
assert len(area_registry.areas) == 1


async def test_update_area_with_name_already_in_use(hass, client, area_registry):
async def test_update_area_with_name_already_in_use(
hass: HomeAssistant, client, area_registry: ar.AreaRegistry
) -> None:
"""Test update entry."""
area = area_registry.async_create("mock 1")
area_registry.async_create("mock 2")
Expand Down
48 changes: 38 additions & 10 deletions tests/components/config/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def setup_config(hass, aiohttp_client):
hass.loop.run_until_complete(auth_config.async_setup(hass))


async def test_list_requires_admin(hass, hass_ws_client, hass_read_only_access_token):
async def test_list_requires_admin(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
hass_read_only_access_token: str,
) -> None:
"""Test get users requires auth."""
client = await hass_ws_client(hass, hass_read_only_access_token)

Expand All @@ -26,7 +30,9 @@ async def test_list_requires_admin(hass, hass_ws_client, hass_read_only_access_t
assert result["error"]["code"] == "unauthorized"


async def test_list(hass, hass_ws_client, hass_admin_user):
async def test_list(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_admin_user: MockUser
) -> None:
"""Test get users."""
group = MockGroup().add_to_hass(hass)

Expand Down Expand Up @@ -108,7 +114,11 @@ async def test_list(hass, hass_ws_client, hass_admin_user):
}


async def test_delete_requires_admin(hass, hass_ws_client, hass_read_only_access_token):
async def test_delete_requires_admin(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
hass_read_only_access_token: str,
) -> None:
"""Test delete command requires an admin."""
client = await hass_ws_client(hass, hass_read_only_access_token)

Expand All @@ -121,7 +131,9 @@ async def test_delete_requires_admin(hass, hass_ws_client, hass_read_only_access
assert result["error"]["code"] == "unauthorized"


async def test_delete_unable_self_account(hass, hass_ws_client, hass_access_token):
async def test_delete_unable_self_account(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_access_token: str
) -> None:
"""Test we cannot delete our own account."""
client = await hass_ws_client(hass, hass_access_token)
refresh_token = await hass.auth.async_validate_access_token(hass_access_token)
Expand All @@ -135,7 +147,9 @@ async def test_delete_unable_self_account(hass, hass_ws_client, hass_access_toke
assert result["error"]["code"] == "no_delete_self"


async def test_delete_unknown_user(hass, hass_ws_client, hass_access_token):
async def test_delete_unknown_user(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_access_token: str
) -> None:
"""Test we cannot delete an unknown user."""
client = await hass_ws_client(hass, hass_access_token)

Expand All @@ -148,7 +162,9 @@ async def test_delete_unknown_user(hass, hass_ws_client, hass_access_token):
assert result["error"]["code"] == "not_found"


async def test_delete(hass, hass_ws_client, hass_access_token):
async def test_delete(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_access_token: str
) -> None:
"""Test delete command works."""
client = await hass_ws_client(hass, hass_access_token)
test_user = MockUser(id="efg").add_to_hass(hass)
Expand All @@ -164,7 +180,9 @@ async def test_delete(hass, hass_ws_client, hass_access_token):
assert len(await hass.auth.async_get_users()) == cur_users - 1


async def test_create(hass, hass_ws_client, hass_access_token):
async def test_create(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_access_token: str
) -> None:
"""Test create command works."""
client = await hass_ws_client(hass, hass_access_token)

Expand All @@ -186,7 +204,9 @@ async def test_create(hass, hass_ws_client, hass_access_token):
assert not user.system_generated


async def test_create_user_group(hass, hass_ws_client, hass_access_token):
async def test_create_user_group(
hass: HomeAssistant, hass_ws_client: WebSocketGenerator, hass_access_token: str
) -> None:
"""Test create user with a group."""
client = await hass_ws_client(hass, hass_access_token)

Expand Down Expand Up @@ -215,7 +235,11 @@ async def test_create_user_group(hass, hass_ws_client, hass_access_token):
assert not user.system_generated


async def test_create_requires_admin(hass, hass_ws_client, hass_read_only_access_token):
async def test_create_requires_admin(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
hass_read_only_access_token: str,
) -> None:
"""Test create command requires an admin."""
client = await hass_ws_client(hass, hass_read_only_access_token)

Expand Down Expand Up @@ -253,7 +277,11 @@ async def test_update(hass: HomeAssistant, hass_ws_client: WebSocketGenerator) -
assert data_user["group_ids"] == ["system-read-only"]


async def test_update_requires_admin(hass, hass_ws_client, hass_read_only_access_token):
async def test_update_requires_admin(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
hass_read_only_access_token: str,
) -> None:
"""Test update command requires an admin."""
client = await hass_ws_client(hass, hass_read_only_access_token)

Expand Down
Loading

0 comments on commit 9f688a5

Please sign in to comment.