Add custom integration block list (#112481)
* Add custom integration block list * Fix typo * Add version condition * Add block reason, simplify blocked versions, add tests * Change logic for OK versions * Add link to custom integration's issue tracker * Add missing file --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import threading
|
||||
from typing import Any
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
from awesomeversion import AwesomeVersion
|
||||
import pytest
|
||||
|
||||
from homeassistant import loader
|
||||
@@ -167,6 +168,57 @@ async def test_custom_integration_version_not_valid(
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"blocked_versions",
|
||||
[
|
||||
loader.BlockedIntegration(None, "breaks Home Assistant"),
|
||||
loader.BlockedIntegration(AwesomeVersion("2.0.0"), "breaks Home Assistant"),
|
||||
],
|
||||
)
|
||||
async def test_custom_integration_version_blocked(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enable_custom_integrations: None,
|
||||
blocked_versions,
|
||||
) -> None:
|
||||
"""Test that we log a warning when custom integrations have a blocked version."""
|
||||
with patch.dict(
|
||||
loader.BLOCKED_CUSTOM_INTEGRATIONS, {"test_blocked_version": blocked_versions}
|
||||
):
|
||||
with pytest.raises(loader.IntegrationNotFound):
|
||||
await loader.async_get_integration(hass, "test_blocked_version")
|
||||
|
||||
assert (
|
||||
"Version 1.0.0 of custom integration 'test_blocked_version' breaks"
|
||||
" Home Assistant and was blocked from loading, please report it to the"
|
||||
" author of the 'test_blocked_version' custom integration"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"blocked_versions",
|
||||
[
|
||||
loader.BlockedIntegration(AwesomeVersion("0.9.9"), "breaks Home Assistant"),
|
||||
loader.BlockedIntegration(AwesomeVersion("1.0.0"), "breaks Home Assistant"),
|
||||
],
|
||||
)
|
||||
async def test_custom_integration_version_not_blocked(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
enable_custom_integrations: None,
|
||||
blocked_versions,
|
||||
) -> None:
|
||||
"""Test that we log a warning when custom integrations have a blocked version."""
|
||||
with patch.dict(
|
||||
loader.BLOCKED_CUSTOM_INTEGRATIONS, {"test_blocked_version": blocked_versions}
|
||||
):
|
||||
await loader.async_get_integration(hass, "test_blocked_version")
|
||||
|
||||
assert (
|
||||
"Version 1.0.0 of custom integration 'test_blocked_version'"
|
||||
) not in caplog.text
|
||||
|
||||
|
||||
async def test_get_integration(hass: HomeAssistant) -> None:
|
||||
"""Test resolving integration."""
|
||||
with pytest.raises(loader.IntegrationNotLoaded):
|
||||
|
||||
Reference in New Issue
Block a user