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