Add mqtt discovery schema error tests for all platforms (#101583)

Add mqtt discovery schema error tests
This commit is contained in:
Jan Bouwhuis 2023-10-07 21:00:33 +02:00 committed by GitHub
parent 9407c49819
commit 55bf309d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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