1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Differentiate between warnings and errors in check_config helper (#102902)

* Differentiate between warnings and errors in check_config helper

* Update tests

* Treat configuration errors in frontend and its dependencies as errors

* Improve test coverage

* Address review comments

* Improve test coverage

* Improve test coverage

* Address review comments

* Add comment
This commit is contained in:
Erik Montnemery
2023-11-05 03:08:04 +01:00
committed by GitHub
parent 936956a430
commit 3ba8a82243
6 changed files with 290 additions and 75 deletions

View File

@@ -1,6 +1,6 @@
"""Test core config."""
from http import HTTPStatus
from unittest.mock import patch
from unittest.mock import Mock, patch
import pytest
@@ -37,9 +37,14 @@ async def test_validate_config_ok(
client = await hass_client()
no_error = Mock()
no_error.errors = None
no_error.error_str = ""
no_error.warning_str = ""
with patch(
"homeassistant.components.config.core.async_check_ha_config_file",
return_value=None,
"homeassistant.components.config.core.check_config.async_check_ha_config_file",
return_value=no_error,
):
resp = await client.post("/api/config/core/check_config")
@@ -47,10 +52,16 @@ async def test_validate_config_ok(
result = await resp.json()
assert result["result"] == "valid"
assert result["errors"] is None
assert result["warnings"] is None
error_warning = Mock()
error_warning.errors = ["beer"]
error_warning.error_str = "beer"
error_warning.warning_str = "milk"
with patch(
"homeassistant.components.config.core.async_check_ha_config_file",
return_value="beer",
"homeassistant.components.config.core.check_config.async_check_ha_config_file",
return_value=error_warning,
):
resp = await client.post("/api/config/core/check_config")
@@ -58,6 +69,24 @@ async def test_validate_config_ok(
result = await resp.json()
assert result["result"] == "invalid"
assert result["errors"] == "beer"
assert result["warnings"] == "milk"
warning = Mock()
warning.errors = None
warning.error_str = ""
warning.warning_str = "milk"
with patch(
"homeassistant.components.config.core.check_config.async_check_ha_config_file",
return_value=warning,
):
resp = await client.post("/api/config/core/check_config")
assert resp.status == HTTPStatus.OK
result = await resp.json()
assert result["result"] == "valid"
assert result["errors"] is None
assert result["warnings"] == "milk"
async def test_validate_config_requires_admin(