Add mqtt discovery schema error tests for all platforms (#101583)
Add mqtt discovery schema error tests
This commit is contained in:
parent
9407c49819
commit
55bf309d2f
1 changed files with 5 additions and 4 deletions
|
@ -122,23 +122,24 @@ async def test_invalid_json(
|
||||||
assert not mock_dispatcher_send.called
|
assert not mock_dispatcher_send.called
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("domain", [*list(mqtt.PLATFORMS), "device_automation", "tag"])
|
||||||
@pytest.mark.no_fail_on_log_exception
|
@pytest.mark.no_fail_on_log_exception
|
||||||
@patch("homeassistant.components.mqtt.PLATFORMS", [Platform.BINARY_SENSOR])
|
|
||||||
async def test_discovery_schema_error(
|
async def test_discovery_schema_error(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
|
domain: Platform | str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test unexpected error JSON config."""
|
"""Test unexpected error JSON config."""
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.binary_sensor.DISCOVERY_SCHEMA",
|
f"homeassistant.components.mqtt.{domain}.DISCOVERY_SCHEMA",
|
||||||
side_effect=AttributeError("Attribute abc not found"),
|
side_effect=AttributeError("Attribute abc not found"),
|
||||||
):
|
):
|
||||||
await mqtt_mock_entry()
|
await mqtt_mock_entry()
|
||||||
async_fire_mqtt_message(
|
async_fire_mqtt_message(
|
||||||
hass,
|
hass,
|
||||||
"homeassistant/binary_sensor/bla/config",
|
f"homeassistant/{domain}/bla/config",
|
||||||
'{"name": "Beer", "state_topic": "ok"}',
|
'{"name": "Beer", "some_topic": "bla"}',
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert "AttributeError: Attribute abc not found" in caplog.text
|
assert "AttributeError: Attribute abc not found" in caplog.text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue