Skip to content

Commit

Permalink
Add mqtt discovery schema error tests for all platforms (#101583)
Browse files Browse the repository at this point in the history
Add mqtt discovery schema error tests
  • Loading branch information
jbouwh authored Oct 7, 2023
1 parent 9407c49 commit 55bf309
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tests/components/mqtt/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55bf309

Please sign in to comment.