Allow IntegrationNotFound when checking config in safe mode (#56283)

Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
J. Nick Koston 2021-09-17 19:25:50 -10:00 committed by GitHub
parent bad6b2f7f5
commit eb98ac9415
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 5 deletions

View file

@ -7,6 +7,7 @@ from homeassistant.helpers.check_config import (
CheckConfigError,
async_check_ha_config_file,
)
from homeassistant.requirements import RequirementsNotFound
from tests.common import mock_platform, patch_yaml_files
@ -75,7 +76,7 @@ async def test_component_platform_not_found(hass):
assert res.keys() == {"homeassistant"}
assert res.errors[0] == CheckConfigError(
"Component error: beer - Integration 'beer' not found.", None, None
"Integration error: beer - Integration 'beer' not found.", None, None
)
# Only 1 error expected
@ -83,6 +84,42 @@ async def test_component_platform_not_found(hass):
assert not res.errors
async def test_component_requirement_not_found(hass):
"""Test errors if component with a requirement not found not found."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "test_custom_component:"}
with patch(
"homeassistant.helpers.check_config.async_get_integration_with_requirements",
side_effect=RequirementsNotFound("test_custom_component", ["any"]),
), patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant"}
assert res.errors[0] == CheckConfigError(
"Integration error: test_custom_component - Requirements for test_custom_component not found: ['any'].",
None,
None,
)
# Only 1 error expected
res.errors.pop(0)
assert not res.errors
async def test_component_not_found_safe_mode(hass):
"""Test no errors if component not found in safe mode."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "beer:"}
hass.config.safe_mode = True
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant"}
assert not res.errors
async def test_component_platform_not_found_2(hass):
"""Test errors if component or platform not found."""
# Make sure they don't exist
@ -103,6 +140,21 @@ async def test_component_platform_not_found_2(hass):
assert not res.errors
async def test_platform_not_found_safe_mode(hass):
"""Test no errors if platform not found in safe_mode."""
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
hass.config.safe_mode = True
with patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
log_ha_config(res)
assert res.keys() == {"homeassistant", "light"}
assert res["light"] == []
assert not res.errors
async def test_package_invalid(hass):
"""Test a valid platform setup."""
files = {