Drop use of async_mock_mqtt_component (#37011)

This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-06-22 23:59:50 +02:00
1 parent a2e2c35011
commit 280f49540e
25 files changed
+126 -209

No files matched your search

+15 -48
View File
@@ -10,18 +10,11 @@ from homeassistant.components.mqtt import MQTT_PUBLISH_SCHEMA
import homeassistant.components.snips as snips
from homeassistant.helpers.intent import ServiceIntentHandler, async_register
from tests.common import (
async_fire_mqtt_message,
async_mock_intent,
async_mock_mqtt_component,
async_mock_service,
)
from tests.common import async_fire_mqtt_message, async_mock_intent, async_mock_service
async def test_snips_config(hass):
async def test_snips_config(hass, mqtt_mock):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(
hass,
"snips",
@@ -36,10 +29,8 @@ async def test_snips_config(hass):
assert result
async def test_snips_bad_config(hass):
async def test_snips_bad_config(hass, mqtt_mock):
"""Test Snips bad config."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(
hass,
"snips",
@@ -54,10 +45,8 @@ async def test_snips_bad_config(hass):
assert not result
async def test_snips_config_feedback_on(hass):
async def test_snips_config_feedback_on(hass, mqtt_mock):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)
calls = async_mock_service(hass, "mqtt", "publish", MQTT_PUBLISH_SCHEMA)
result = await async_setup_component(
hass, "snips", {"snips": {"feedback_sounds": True}}
@@ -74,10 +63,8 @@ async def test_snips_config_feedback_on(hass):
assert calls[1].data["retain"]
async def test_snips_config_feedback_off(hass):
async def test_snips_config_feedback_off(hass, mqtt_mock):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)
calls = async_mock_service(hass, "mqtt", "publish", MQTT_PUBLISH_SCHEMA)
result = await async_setup_component(
hass, "snips", {"snips": {"feedback_sounds": False}}
@@ -94,10 +81,8 @@ async def test_snips_config_feedback_off(hass):
assert not calls[1].data["retain"]
async def test_snips_config_no_feedback(hass):
async def test_snips_config_no_feedback(hass, mqtt_mock):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)
calls = async_mock_service(hass, "snips", "say")
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
@@ -105,10 +90,8 @@ async def test_snips_config_no_feedback(hass):
assert len(calls) == 0
async def test_snips_intent(hass):
async def test_snips_intent(hass, mqtt_mock):
"""Test intent via Snips."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
payload = """
@@ -152,10 +135,8 @@ async def test_snips_intent(hass):
assert intent.text_input == "turn the lights green"
async def test_snips_service_intent(hass):
async def test_snips_service_intent(hass, mqtt_mock):
"""Test ServiceIntentHandler via Snips."""
await async_mock_mqtt_component(hass)
hass.states.async_set("light.kitchen", "off")
calls = async_mock_service(hass, "light", "turn_on")
result = await async_setup_component(hass, "snips", {"snips": {}})
@@ -196,10 +177,8 @@ async def test_snips_service_intent(hass):
assert "site_id" not in calls[0].data
async def test_snips_intent_with_duration(hass):
async def test_snips_intent_with_duration(hass, mqtt_mock):
"""Test intent with Snips duration."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
payload = """
@@ -251,10 +230,8 @@ async def test_snips_intent_with_duration(hass):
}
async def test_intent_speech_response(hass):
async def test_intent_speech_response(hass, mqtt_mock):
"""Test intent speech response via Snips."""
await async_mock_mqtt_component(hass)
calls = async_mock_service(hass, "mqtt", "publish", MQTT_PUBLISH_SCHEMA)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
@@ -292,10 +269,8 @@ async def test_intent_speech_response(hass):
assert topic == "hermes/dialogueManager/endSession"
async def test_unknown_intent(hass, caplog):
async def test_unknown_intent(hass, caplog, mqtt_mock):
"""Test unknown intent."""
await async_mock_mqtt_component(hass)
caplog.set_level(logging.WARNING)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
@@ -315,10 +290,8 @@ async def test_unknown_intent(hass, caplog):
assert "Received unknown intent unknownIntent" in caplog.text
async def test_snips_intent_user(hass):
async def test_snips_intent_user(hass, mqtt_mock):
"""Test intentName format user_XXX__intentName."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
payload = """
@@ -341,10 +314,8 @@ async def test_snips_intent_user(hass):
assert intent.intent_type == "Lights"
async def test_snips_intent_username(hass):
async def test_snips_intent_username(hass, mqtt_mock):
"""Test intentName format username:intentName."""
await async_mock_mqtt_component(hass)
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result
payload = """
@@ -367,10 +338,8 @@ async def test_snips_intent_username(hass):
assert intent.intent_type == "Lights"
async def test_snips_low_probability(hass, caplog):
async def test_snips_low_probability(hass, caplog, mqtt_mock):
"""Test intent via Snips."""
await async_mock_mqtt_component(hass)
caplog.set_level(logging.WARNING)
result = await async_setup_component(
hass, "snips", {"snips": {"probability_threshold": 0.5}}
@@ -393,10 +362,8 @@ async def test_snips_low_probability(hass, caplog):
assert "Intent below probaility threshold 0.49 < 0.5" in caplog.text
async def test_intent_special_slots(hass):
async def test_intent_special_slots(hass, mqtt_mock):
"""Test intent special slot values via Snips."""
await async_mock_mqtt_component(hass)
calls = async_mock_service(hass, "light", "turn_on")
result = await async_setup_component(hass, "snips", {"snips": {}})
assert result