Check for uncaught service not found exceptions (#58010)

This commit is contained in:
Paulus Schoutsen 2021-11-01 06:33:09 -07:00 committed by GitHub
parent 0e19278309
commit f51e1fcb67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 84 additions and 49 deletions

View file

@ -3,6 +3,8 @@ from http import HTTPStatus
import json
from unittest.mock import patch
import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.helpers import entity_registry as er
@ -10,7 +12,18 @@ from homeassistant.helpers import entity_registry as er
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
async def test_get_device_config(hass, hass_client):
@pytest.fixture
async def setup_automation(
hass, automation_config, stub_blueprint_populate # noqa: F811
):
"""Set up automation integration."""
assert await async_setup_component(
hass, "automation", {"automation": automation_config}
)
@pytest.mark.parametrize("automation_config", ({},))
async def test_get_device_config(hass, hass_client, setup_automation):
"""Test getting device config."""
with patch.object(config, "SECTIONS", ["automation"]):
await async_setup_component(hass, "config", {})
@ -30,7 +43,8 @@ async def test_get_device_config(hass, hass_client):
assert result == {"id": "moon"}
async def test_update_device_config(hass, hass_client):
@pytest.mark.parametrize("automation_config", ({},))
async def test_update_device_config(hass, hass_client, setup_automation):
"""Test updating device config."""
with patch.object(config, "SECTIONS", ["automation"]):
await async_setup_component(hass, "config", {})
@ -66,7 +80,8 @@ async def test_update_device_config(hass, hass_client):
assert written[0] == orig_data
async def test_bad_formatted_automations(hass, hass_client):
@pytest.mark.parametrize("automation_config", ({},))
async def test_bad_formatted_automations(hass, hass_client, setup_automation):
"""Test that we handle automations without ID."""
with patch.object(config, "SECTIONS", ["automation"]):
await async_setup_component(hass, "config", {})
@ -110,29 +125,27 @@ async def test_bad_formatted_automations(hass, hass_client):
assert orig_data[1] == {"id": "moon", "trigger": [], "condition": [], "action": []}
async def test_delete_automation(hass, hass_client):
@pytest.mark.parametrize(
"automation_config",
(
[
{
"id": "sun",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
},
{
"id": "moon",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
},
],
),
)
async def test_delete_automation(hass, hass_client, setup_automation):
"""Test deleting an automation."""
ent_reg = er.async_get(hass)
assert await async_setup_component(
hass,
"automation",
{
"automation": [
{
"id": "sun",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
},
{
"id": "moon",
"trigger": {"platform": "event", "event_type": "test_event"},
"action": {"service": "test.automation"},
},
]
},
)
assert len(ent_reg.entities) == 2
with patch.object(config, "SECTIONS", ["automation"]):

View file

@ -3,11 +3,19 @@ from http import HTTPStatus
import json
from unittest.mock import patch
import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.config import DATA_CUSTOMIZE
@pytest.fixture(autouse=True)
async def setup_homeassistant(hass):
"""Set up homeassistant integration."""
assert await async_setup_component(hass, "homeassistant", {})
async def test_get_entity(hass, hass_client):
"""Test getting entity."""
with patch.object(config, "SECTIONS", ["customize"]):

View file

@ -3,13 +3,22 @@ from http import HTTPStatus
import json
from unittest.mock import patch
import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from homeassistant.helpers import entity_registry as er
from homeassistant.util.yaml import dump
async def test_create_scene(hass, hass_client):
@pytest.fixture
async def setup_scene(hass, scene_config):
"""Set up scene integration."""
assert await async_setup_component(hass, "scene", {"scene": scene_config})
@pytest.mark.parametrize("scene_config", ({},))
async def test_create_scene(hass, hass_client, setup_scene):
"""Test creating a scene."""
with patch.object(config, "SECTIONS", ["scene"]):
await async_setup_component(hass, "config", {})
@ -58,7 +67,8 @@ async def test_create_scene(hass, hass_client):
)
async def test_update_scene(hass, hass_client):
@pytest.mark.parametrize("scene_config", ({},))
async def test_update_scene(hass, hass_client, setup_scene):
"""Test updating a scene."""
with patch.object(config, "SECTIONS", ["scene"]):
await async_setup_component(hass, "config", {})
@ -110,7 +120,8 @@ async def test_update_scene(hass, hass_client):
)
async def test_bad_formatted_scene(hass, hass_client):
@pytest.mark.parametrize("scene_config", ({},))
async def test_bad_formatted_scene(hass, hass_client, setup_scene):
"""Test that we handle scene without ID."""
with patch.object(config, "SECTIONS", ["scene"]):
await async_setup_component(hass, "config", {})
@ -163,21 +174,19 @@ async def test_bad_formatted_scene(hass, hass_client):
}
async def test_delete_scene(hass, hass_client):
@pytest.mark.parametrize(
"scene_config",
(
[
{"id": "light_on", "name": "Light on", "entities": {}},
{"id": "light_off", "name": "Light off", "entities": {}},
],
),
)
async def test_delete_scene(hass, hass_client, setup_scene):
"""Test deleting a scene."""
ent_reg = er.async_get(hass)
assert await async_setup_component(
hass,
"scene",
{
"scene": [
{"id": "light_on", "name": "Light on", "entities": {}},
{"id": "light_off", "name": "Light off", "entities": {}},
]
},
)
assert len(ent_reg.entities) == 2
with patch.object(config, "SECTIONS", ["scene"]):

View file

@ -2,9 +2,19 @@
from http import HTTPStatus
from unittest.mock import patch
import pytest
from homeassistant.bootstrap import async_setup_component
from homeassistant.components import config
from tests.components.blueprint.conftest import stub_blueprint_populate # noqa: F401
@pytest.fixture(autouse=True)
async def setup_script(hass, stub_blueprint_populate): # noqa: F811
"""Set up script integration."""
assert await async_setup_component(hass, "script", {})
async def test_delete_script(hass, hass_client):
"""Test deleting a script."""