1
0
mirror of https://github.com/home-assistant/core.git synced 2026-04-28 04:33:49 +01:00

Add type hints to integration tests (part 1) (#87777)

This commit is contained in:
epenet
2023-02-09 16:09:13 +01:00
committed by GitHub
parent 2b3e6a4ca8
commit 07a1a0efa9
51 changed files with 905 additions and 471 deletions

View File

@@ -26,7 +26,11 @@ MOCK_VERSION_DEV = "1970.1.0.dev0"
MOCK_VERSION_NIGHTLY = "1970.1.0.dev19700101"
async def test_no_send(hass, caplog, aioclient_mock):
async def test_no_send(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send when no preferences are defined."""
analytics = Analytics(hass)
with patch(
@@ -75,7 +79,11 @@ async def test_load_with_supervisor_without_diagnostics(hass: HomeAssistant) ->
assert not analytics.preferences[ATTR_DIAGNOSTICS]
async def test_failed_to_send(hass, caplog, aioclient_mock):
async def test_failed_to_send(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test failed to send payload."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=400)
analytics = Analytics(hass)
@@ -90,7 +98,11 @@ async def test_failed_to_send(hass, caplog, aioclient_mock):
)
async def test_failed_to_send_raises(hass, caplog, aioclient_mock):
async def test_failed_to_send_raises(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test raises when failed to send payload."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, exc=aiohttp.ClientError())
analytics = Analytics(hass)
@@ -102,7 +114,11 @@ async def test_failed_to_send_raises(hass, caplog, aioclient_mock):
assert "Error sending analytics" in caplog.text
async def test_send_base(hass, caplog, aioclient_mock):
async def test_send_base(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -123,7 +139,11 @@ async def test_send_base(hass, caplog, aioclient_mock):
assert "'integrations':" not in caplog.text
async def test_send_base_with_supervisor(hass, caplog, aioclient_mock):
async def test_send_base_with_supervisor(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
@@ -170,7 +190,11 @@ async def test_send_base_with_supervisor(hass, caplog, aioclient_mock):
assert "'integrations':" not in caplog.text
async def test_send_usage(hass, caplog, aioclient_mock):
async def test_send_usage(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send usage preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -189,7 +213,11 @@ async def test_send_usage(hass, caplog, aioclient_mock):
assert "'certificate': False" in caplog.text
async def test_send_usage_with_supervisor(hass, caplog, aioclient_mock):
async def test_send_usage_with_supervisor(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send usage with supervisor preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -242,7 +270,11 @@ async def test_send_usage_with_supervisor(hass, caplog, aioclient_mock):
assert "'addon_count':" not in caplog.text
async def test_send_statistics(hass, caplog, aioclient_mock):
async def test_send_statistics(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send statistics preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -260,7 +292,11 @@ async def test_send_statistics(hass, caplog, aioclient_mock):
assert "'integrations':" not in caplog.text
async def test_send_statistics_one_integration_fails(hass, caplog, aioclient_mock):
async def test_send_statistics_one_integration_fails(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send statistics preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -281,8 +317,10 @@ async def test_send_statistics_one_integration_fails(hass, caplog, aioclient_moc
async def test_send_statistics_async_get_integration_unknown_exception(
hass, caplog, aioclient_mock
):
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send statistics preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -298,7 +336,11 @@ async def test_send_statistics_async_get_integration_unknown_exception(
await analytics.send_analytics()
async def test_send_statistics_with_supervisor(hass, caplog, aioclient_mock):
async def test_send_statistics_with_supervisor(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send statistics preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -366,7 +408,11 @@ async def test_reusing_uuid(
assert analytics.uuid == "NOT_MOCK_UUID"
async def test_custom_integrations(hass, aioclient_mock, enable_custom_integrations):
async def test_custom_integrations(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
enable_custom_integrations: None,
) -> None:
"""Test sending custom integrations."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -398,7 +444,11 @@ async def test_dev_url(
assert str(payload[1]) == ANALYTICS_ENDPOINT_URL_DEV
async def test_dev_url_error(hass, aioclient_mock, caplog):
async def test_dev_url_error(
hass: HomeAssistant,
aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test sending payload to dev url that returns error."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL_DEV, status=400)
analytics = Analytics(hass)
@@ -458,7 +508,9 @@ async def test_send_with_no_energy(
assert "energy" not in postdata
async def test_send_with_no_energy_config(recorder_mock, hass, aioclient_mock):
async def test_send_with_no_energy_config(
recorder_mock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -480,7 +532,9 @@ async def test_send_with_no_energy_config(recorder_mock, hass, aioclient_mock):
assert not postdata["energy"]["configured"]
async def test_send_with_energy_config(recorder_mock, hass, aioclient_mock):
async def test_send_with_energy_config(
recorder_mock, hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test send base preferences are defined."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)
@@ -502,7 +556,11 @@ async def test_send_with_energy_config(recorder_mock, hass, aioclient_mock):
assert postdata["energy"]["configured"]
async def test_send_usage_with_certificate(hass, caplog, aioclient_mock):
async def test_send_usage_with_certificate(
hass: HomeAssistant,
caplog: pytest.LogCaptureFixture,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test send usage preferences with certificate."""
aioclient_mock.post(ANALYTICS_ENDPOINT_URL, status=200)
analytics = Analytics(hass)