|
26 | 26 | ) |
27 | 27 | from homeassistant.components.websocket_api import TYPE_RESULT |
28 | 28 | from homeassistant.core import HomeAssistant |
| 29 | +from homeassistant.exceptions import HomeAssistantError |
29 | 30 | from homeassistant.loader import async_get_integration |
30 | 31 | from homeassistant.setup import async_setup_component |
31 | 32 |
|
@@ -408,6 +409,35 @@ async def test_themes_reload_themes( |
408 | 409 | assert msg["result"]["default_theme"] == "default" |
409 | 410 |
|
410 | 411 |
|
| 412 | +@pytest.mark.usefixtures("frontend") |
| 413 | +async def test_themes_reload_invalid( |
| 414 | + hass: HomeAssistant, themes_ws_client: MockHAClientWebSocket |
| 415 | +) -> None: |
| 416 | + """Test frontend.reload_themes service with an invalid theme.""" |
| 417 | + |
| 418 | + with patch( |
| 419 | + "homeassistant.components.frontend.async_hass_config_yaml", |
| 420 | + return_value={DOMAIN: {CONF_THEMES: {"happy": {"primary-color": "pink"}}}}, |
| 421 | + ): |
| 422 | + await hass.services.async_call(DOMAIN, "reload_themes", blocking=True) |
| 423 | + |
| 424 | + with ( |
| 425 | + patch( |
| 426 | + "homeassistant.components.frontend.async_hass_config_yaml", |
| 427 | + return_value={DOMAIN: {CONF_THEMES: {"sad": "blue"}}}, |
| 428 | + ), |
| 429 | + pytest.raises(HomeAssistantError, match="Failed to reload themes"), |
| 430 | + ): |
| 431 | + await hass.services.async_call(DOMAIN, "reload_themes", blocking=True) |
| 432 | + |
| 433 | + await themes_ws_client.send_json({"id": 5, "type": "frontend/get_themes"}) |
| 434 | + |
| 435 | + msg = await themes_ws_client.receive_json() |
| 436 | + |
| 437 | + assert msg["result"]["themes"] == {"happy": {"primary-color": "pink"}} |
| 438 | + assert msg["result"]["default_theme"] == "default" |
| 439 | + |
| 440 | + |
411 | 441 | async def test_missing_themes(ws_client: MockHAClientWebSocket) -> None: |
412 | 442 | """Test that themes API works when themes are not defined.""" |
413 | 443 | await ws_client.send_json({"id": 5, "type": "frontend/get_themes"}) |
|
0 commit comments