Add warning to custom integrations without version (#45919)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Joakim Sørensen
2021-02-04 09:59:41 +01:00
committed by GitHub
co-authored by Paulus Schoutsen
parent 8256acb8ef
commit 06e6005fbb
9 changed files with 173 additions and 20 deletions
+47
View File
@@ -0,0 +1,47 @@
"""Tests for hassfest version."""
import pytest
import voluptuous as vol
from script.hassfest.manifest import (
CUSTOM_INTEGRATION_MANIFEST_SCHEMA,
validate_version,
)
from script.hassfest.model import Integration
@pytest.fixture
def integration():
"""Fixture for hassfest integration model."""
integration = Integration("")
integration.manifest = {
"domain": "test",
"documentation": "https://example.com",
"name": "test",
"codeowners": ["@awesome"],
}
return integration
def test_validate_version_no_key(integration: Integration):
"""Test validate version with no key."""
validate_version(integration)
assert (
"No 'version' key in the manifest file. This will cause a future version of Home Assistant to block this integration."
in [x.error for x in integration.warnings]
)
def test_validate_custom_integration_manifest(integration: Integration):
"""Test validate custom integration manifest."""
with pytest.raises(vol.Invalid):
integration.manifest["version"] = "lorem_ipsum"
CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
with pytest.raises(vol.Invalid):
integration.manifest["version"] = None
CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
integration.manifest["version"] = "1"
schema = CUSTOM_INTEGRATION_MANIFEST_SCHEMA(integration.manifest)
assert schema["version"] == "1"
+60 -2
View File
@@ -130,13 +130,69 @@ async def test_custom_component_name(hass):
async def test_log_warning_custom_component(hass, caplog):
"""Test that we log a warning when loading a custom component."""
hass.components.test_standalone
await loader.async_get_integration(hass, "test_standalone")
assert "You are using a custom integration test_standalone" in caplog.text
await loader.async_get_integration(hass, "test")
assert "You are using a custom integration test " in caplog.text
async def test_custom_integration_missing_version(hass, caplog):
"""Test that we log a warning when custom integrations are missing a version."""
test_integration_1 = loader.Integration(
hass, "custom_components.test1", None, {"domain": "test1"}
)
test_integration_2 = loader.Integration(
hass,
"custom_components.test2",
None,
loader.manifest_from_legacy_module("test2", "custom_components.test2"),
)
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
mock_get.return_value = {
"test1": test_integration_1,
"test2": test_integration_2,
}
await loader.async_get_integration(hass, "test1")
assert (
"No 'version' key in the manifest file for custom integration 'test1'."
in caplog.text
)
await loader.async_get_integration(hass, "test2")
assert (
"No 'version' key in the manifest file for custom integration 'test2'."
in caplog.text
)
async def test_no_version_warning_for_none_custom_integrations(hass, caplog):
"""Test that we do not log a warning when core integrations are missing a version."""
await loader.async_get_integration(hass, "hue")
assert (
"No 'version' key in the manifest file for custom integration 'hue'."
not in caplog.text
)
async def test_custom_integration_version_not_valid(hass, caplog):
"""Test that we log a warning when custom integrations have a invalid version."""
test_integration = loader.Integration(
hass, "custom_components.test", None, {"domain": "test", "version": "test"}
)
with patch("homeassistant.loader.async_get_custom_components") as mock_get:
mock_get.return_value = {"test": test_integration}
await loader.async_get_integration(hass, "test")
assert (
"'test' is not a valid version for custom integration 'test'."
in caplog.text
)
async def test_get_integration(hass):
"""Test resolving integration."""
integration = await loader.async_get_integration(hass, "hue")
@@ -154,7 +210,6 @@ async def test_get_integration_legacy(hass):
async def test_get_integration_custom_component(hass, enable_custom_integrations):
"""Test resolving integration."""
integration = await loader.async_get_integration(hass, "test_package")
print(integration)
assert integration.get_component().DOMAIN == "test_package"
assert integration.name == "Test Package"
@@ -189,6 +244,7 @@ def test_integration_properties(hass):
{"manufacturer": "Signify", "modelName": "Philips hue bridge 2015"},
],
"mqtt": ["hue/discovery"],
"version": "1.0.0",
},
)
assert integration.name == "Philips Hue"
@@ -215,6 +271,7 @@ def test_integration_properties(hass):
assert integration.dependencies == ["test-dep"]
assert integration.requirements == ["test-req==1.0.0"]
assert integration.is_built_in is True
assert integration.version == "1.0.0"
integration = loader.Integration(
hass,
@@ -233,6 +290,7 @@ def test_integration_properties(hass):
assert integration.dhcp is None
assert integration.ssdp is None
assert integration.mqtt is None
assert integration.version is None
integration = loader.Integration(
hass,