Prepare MQTT platform tests part9 (#90133)

* Tests switch

* Tests text

* Tests update
This commit is contained in:
Jan Bouwhuis 2023-03-23 19:17:27 +01:00 committed by GitHub
parent db63c8584e
commit 185d6d74d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 249 additions and 243 deletions

View file

@ -14,7 +14,6 @@ from homeassistant.const import (
Platform,
)
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from .test_common import (
help_test_availability_when_connection_lost,
@ -72,13 +71,9 @@ async def async_set_value(
)
async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the controlling state via topic."""
assert await async_setup_component(
hass,
mqtt.DOMAIN,
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -88,10 +83,14 @@ async def test_controlling_state_via_topic(
"mode": "password",
}
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
}
],
)
async def test_controlling_state_via_topic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the controlling state via topic."""
await mqtt_mock_entry_no_yaml_config()
state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN
@ -114,15 +113,9 @@ async def test_controlling_state_via_topic(
assert state.state == ""
async def test_controlling_validation_state_via_topic(
hass: HomeAssistant,
mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the validation of a received state."""
assert await async_setup_component(
hass,
mqtt.DOMAIN,
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -135,10 +128,16 @@ async def test_controlling_validation_state_via_topic(
"pattern": "(y|n)",
}
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
}
],
)
async def test_controlling_validation_state_via_topic(
hass: HomeAssistant,
mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
) -> None:
"""Test the validation of a received state."""
await mqtt_mock_entry_no_yaml_config()
state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN
@ -188,11 +187,9 @@ async def test_controlling_validation_state_via_topic(
assert state.state == "no"
async def test_attribute_validation_max_greater_then_min(hass: HomeAssistant) -> None:
"""Test the validation of min and max configuration attributes."""
assert not await async_setup_component(
hass,
mqtt.DOMAIN,
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -202,17 +199,20 @@ async def test_attribute_validation_max_greater_then_min(hass: HomeAssistant) ->
"max": 10,
}
}
},
)
async def test_attribute_validation_max_not_greater_then_max_state_length(
hass: HomeAssistant,
}
],
)
async def test_attribute_validation_max_greater_then_min(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the max value of of max configuration attribute."""
assert not await async_setup_component(
hass,
mqtt.DOMAIN,
"""Test the validation of min and max configuration attributes."""
with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config()
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -222,17 +222,20 @@ async def test_attribute_validation_max_not_greater_then_max_state_length(
"max": 257,
}
}
},
)
async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
}
],
)
async def test_attribute_validation_max_not_greater_then_max_state_length(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending MQTT commands in optimistic mode."""
assert await async_setup_component(
hass,
mqtt.DOMAIN,
"""Test the max value of of max configuration attribute."""
with pytest.raises(AssertionError):
await mqtt_mock_entry_no_yaml_config()
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -241,10 +244,14 @@ async def test_sending_mqtt_commands_and_optimistic(
"qos": "2",
}
}
},
)
await hass.async_block_till_done()
mqtt_mock = await mqtt_mock_entry_with_yaml_config()
}
],
)
async def test_sending_mqtt_commands_and_optimistic(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the sending MQTT commands in optimistic mode."""
mqtt_mock = await mqtt_mock_entry_no_yaml_config()
state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN
@ -269,13 +276,9 @@ async def test_sending_mqtt_commands_and_optimistic(
assert state.state == "some new state"
async def test_set_text_validation(
hass: HomeAssistant, mqtt_mock_entry_with_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the initial state in optimistic mode."""
assert await async_setup_component(
hass,
mqtt.DOMAIN,
@pytest.mark.parametrize(
"hass_config",
[
{
mqtt.DOMAIN: {
text.DOMAIN: {
@ -287,10 +290,14 @@ async def test_set_text_validation(
"pattern": "(y|n)",
}
}
},
)
await hass.async_block_till_done()
await mqtt_mock_entry_with_yaml_config()
}
],
)
async def test_set_text_validation(
hass: HomeAssistant, mqtt_mock_entry_no_yaml_config: MqttMockHAClientGenerator
) -> None:
"""Test the initial state in optimistic mode."""
await mqtt_mock_entry_no_yaml_config()
state = hass.states.get("text.test")
assert state.state == STATE_UNKNOWN