Simplify MQTT test for setup manual mqtt item from yaml (#72916)

simplify test setup manual mqtt item from yaml
This commit is contained in:
Jan Bouwhuis 2022-06-13 13:44:12 +02:00 committed by GitHub
parent 48e3d68b53
commit 657e7f9a4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 48 additions and 116 deletions

View file

@ -953,13 +953,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = alarm_control_panel.DOMAIN platform = alarm_control_panel.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1063,13 +1063,11 @@ async def test_skip_restoring_state_with_over_due_expire_trigger(
assert "Skip state recovery after reload for binary_sensor.test3" in caplog.text assert "Skip state recovery after reload for binary_sensor.test3" in caplog.text
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = binary_sensor.DOMAIN platform = binary_sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -462,13 +462,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = button.DOMAIN platform = button.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -330,13 +330,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = camera.DOMAIN platform = camera.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1866,13 +1866,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = CLIMATE_DOMAIN platform = CLIMATE_DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1790,13 +1790,7 @@ async def help_test_reloadable_late(hass, caplog, tmp_path, domain, config):
assert hass.states.get(f"{domain}.test_new_3") assert hass.states.get(f"{domain}.test_new_3")
async def help_test_setup_manual_entity_from_yaml( async def help_test_setup_manual_entity_from_yaml(hass, platform, config):
hass,
caplog,
tmp_path,
platform,
config,
):
"""Help to test setup from yaml through configuration entry.""" """Help to test setup from yaml through configuration entry."""
config_structure = {mqtt.DOMAIN: {platform: config}} config_structure = {mqtt.DOMAIN: {platform: config}}

View file

@ -3348,13 +3348,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = cover.DOMAIN platform = cover.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -244,9 +244,7 @@ async def test_legacy_matching_source_type(
assert hass.states.get(entity_id).attributes["source_type"] == SOURCE_TYPE_BLUETOOTH assert hass.states.get(entity_id).attributes["source_type"] == SOURCE_TYPE_BLUETOOTH
async def test_setup_with_modern_schema( async def test_setup_with_modern_schema(hass, mock_device_tracker_conf):
hass, caplog, tmp_path, mock_device_tracker_conf
):
"""Test setup using the modern schema.""" """Test setup using the modern schema."""
dev_id = "jan" dev_id = "jan"
entity_id = f"{DOMAIN}.{dev_id}" entity_id = f"{DOMAIN}.{dev_id}"
@ -255,8 +253,6 @@ async def test_setup_with_modern_schema(
hass.config.components = {"zone"} hass.config.components = {"zone"}
config = {"name": dev_id, "state_topic": topic} config = {"name": dev_id, "state_topic": topic}
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, DOMAIN, config)
hass, caplog, tmp_path, DOMAIN, config
)
assert hass.states.get(entity_id) is not None assert hass.states.get(entity_id) is not None

View file

@ -1894,13 +1894,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = fan.DOMAIN platform = fan.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1267,13 +1267,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = humidifier.DOMAIN platform = humidifier.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1362,48 +1362,30 @@ async def test_setup_override_configuration(hass, caplog, tmp_path):
assert calls_username_password_set[0][1] == "somepassword" assert calls_username_password_set[0][1] == "somepassword"
async def test_setup_manual_mqtt_with_platform_key(hass, caplog, tmp_path): async def test_setup_manual_mqtt_with_platform_key(hass, caplog):
"""Test set up a manual MQTT item with a platform key.""" """Test set up a manual MQTT item with a platform key."""
config = {"platform": "mqtt", "name": "test", "command_topic": "test-topic"} config = {"platform": "mqtt", "name": "test", "command_topic": "test-topic"}
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, "light", config)
hass,
caplog,
tmp_path,
"light",
config,
)
assert ( assert (
"Invalid config for [light]: [platform] is an invalid option for [light]. " "Invalid config for [light]: [platform] is an invalid option for [light]. "
"Check: light->platform. (See ?, line ?)" in caplog.text "Check: light->platform. (See ?, line ?)" in caplog.text
) )
async def test_setup_manual_mqtt_with_invalid_config(hass, caplog, tmp_path): async def test_setup_manual_mqtt_with_invalid_config(hass, caplog):
"""Test set up a manual MQTT item with an invalid config.""" """Test set up a manual MQTT item with an invalid config."""
config = {"name": "test"} config = {"name": "test"}
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, "light", config)
hass,
caplog,
tmp_path,
"light",
config,
)
assert ( assert (
"Invalid config for [light]: required key not provided @ data['command_topic']." "Invalid config for [light]: required key not provided @ data['command_topic']."
" Got None. (See ?, line ?)" in caplog.text " Got None. (See ?, line ?)" in caplog.text
) )
async def test_setup_manual_mqtt_empty_platform(hass, caplog, tmp_path): async def test_setup_manual_mqtt_empty_platform(hass, caplog):
"""Test set up a manual MQTT platform without items.""" """Test set up a manual MQTT platform without items."""
config = None config = None
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, "light", config)
hass,
caplog,
tmp_path,
"light",
config,
)
assert "voluptuous.error.MultipleInvalid" not in caplog.text assert "voluptuous.error.MultipleInvalid" not in caplog.text

View file

@ -966,13 +966,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG) config = deepcopy(DEFAULT_CONFIG)
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -3787,13 +3787,11 @@ async def test_sending_mqtt_effect_command_with_template(
assert state.attributes.get("effect") == "colorloop" assert state.attributes.get("effect") == "colorloop"
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -2146,13 +2146,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1250,13 +1250,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = light.DOMAIN platform = light.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -738,7 +738,5 @@ async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path):
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -784,13 +784,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = number.DOMAIN platform = number.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -222,13 +222,11 @@ async def test_reloadable_late(hass, mqtt_client_mock, caplog, tmp_path):
await help_test_reloadable_late(hass, caplog, tmp_path, domain, config) await help_test_reloadable_late(hass, caplog, tmp_path, domain, config)
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = scene.DOMAIN platform = scene.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -667,13 +667,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = select.DOMAIN platform = select.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -1197,13 +1197,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = sensor.DOMAIN platform = sensor.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -959,13 +959,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = siren.DOMAIN platform = siren.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -692,13 +692,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = vacuum.DOMAIN platform = vacuum.DOMAIN
config = deepcopy(DEFAULT_CONFIG) config = deepcopy(DEFAULT_CONFIG)
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None

View file

@ -648,13 +648,11 @@ async def test_encoding_subscribable_topics(
) )
async def test_setup_manual_entity_from_yaml(hass, caplog, tmp_path): async def test_setup_manual_entity_from_yaml(hass):
"""Test setup manual configured MQTT entity.""" """Test setup manual configured MQTT entity."""
platform = switch.DOMAIN platform = switch.DOMAIN
config = copy.deepcopy(DEFAULT_CONFIG[platform]) config = copy.deepcopy(DEFAULT_CONFIG[platform])
config["name"] = "test" config["name"] = "test"
del config["platform"] del config["platform"]
await help_test_setup_manual_entity_from_yaml( await help_test_setup_manual_entity_from_yaml(hass, platform, config)
hass, caplog, tmp_path, platform, config
)
assert hass.states.get(f"{platform}.test") is not None assert hass.states.get(f"{platform}.test") is not None