Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/components/mqtt/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Test fixtures for mqtt component."""
import pytest

from tests.common import async_mock_mqtt_component


@pytest.fixture
def mqtt_mock(loop, hass):
"""Fixture to mock MQTT."""
client = loop.run_until_complete(async_mock_mqtt_component(hass))
client.reset_mock()
return client
6 changes: 4 additions & 2 deletions tests/components/sensor/test_mqtt_room.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.const import (CONF_NAME, CONF_PLATFORM)
from homeassistant.util import dt

from tests.common import async_fire_mqtt_message
from tests.common import async_fire_mqtt_message, async_mock_mqtt_component

DEVICE_ID = '123TESTMAC'
NAME = 'test_device'
Expand Down Expand Up @@ -64,8 +64,10 @@ async def assert_distance(hass, distance):
assert state.attributes.get('distance') == distance


async def test_room_update(hass, mqtt_mock):
async def test_room_update(hass):
"""Test the updating between rooms."""
await async_mock_mqtt_component(hass)

assert await async_setup_component(hass, sensor.DOMAIN, {
sensor.DOMAIN: {
CONF_PLATFORM: 'mqtt_room',
Expand Down
72 changes: 50 additions & 22 deletions tests/components/test_snips.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
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_service)
async_mock_service, async_mock_mqtt_component)


async def test_snips_config(hass, mqtt_mock):
async def test_snips_config(hass):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {
"feedback_sounds": True,
Expand All @@ -25,8 +27,10 @@ async def test_snips_config(hass, mqtt_mock):
assert result


async def test_snips_bad_config(hass, mqtt_mock):
async def test_snips_bad_config(hass):
"""Test Snips bad config."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {
"feedback_sounds": "on",
Expand All @@ -37,8 +41,10 @@ async def test_snips_bad_config(hass, mqtt_mock):
assert not result


async def test_snips_config_feedback_on(hass, mqtt_mock):
async def test_snips_config_feedback_on(hass):
"""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": {
Expand All @@ -57,8 +63,10 @@ async def test_snips_config_feedback_on(hass, mqtt_mock):
assert calls[1].data['retain']


async def test_snips_config_feedback_off(hass, mqtt_mock):
async def test_snips_config_feedback_off(hass):
"""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": {
Expand All @@ -77,8 +85,10 @@ async def test_snips_config_feedback_off(hass, mqtt_mock):
assert not calls[1].data['retain']


async def test_snips_config_no_feedback(hass, mqtt_mock):
async def test_snips_config_no_feedback(hass):
"""Test Snips Config."""
await async_mock_mqtt_component(hass)

calls = async_mock_service(hass, 'snips', 'say')
result = await async_setup_component(hass, "snips", {
"snips": {},
Expand All @@ -88,8 +98,10 @@ async def test_snips_config_no_feedback(hass, mqtt_mock):
assert len(calls) == 0


async def test_snips_intent(hass, mqtt_mock):
async def test_snips_intent(hass):
"""Test intent via Snips."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {},
})
Expand Down Expand Up @@ -134,8 +146,10 @@ async def test_snips_intent(hass, mqtt_mock):
assert intent.text_input == 'turn the lights green'


async def test_snips_service_intent(hass, mqtt_mock):
async def test_snips_service_intent(hass):
"""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", {
Expand Down Expand Up @@ -178,8 +192,10 @@ async def test_snips_service_intent(hass, mqtt_mock):
assert 'site_id' not in calls[0].data


async def test_snips_intent_with_duration(hass, mqtt_mock):
async def test_snips_intent_with_duration(hass):
"""Test intent with Snips duration."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {},
})
Expand Down Expand Up @@ -232,8 +248,10 @@ async def test_snips_intent_with_duration(hass, mqtt_mock):
'timer_duration_raw': {'value': 'five minutes'}}


async def test_intent_speech_response(hass, mqtt_mock):
async def test_intent_speech_response(hass):
"""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": {},
Expand Down Expand Up @@ -273,8 +291,10 @@ async def test_intent_speech_response(hass, mqtt_mock):
assert topic == 'hermes/dialogueManager/endSession'


async def test_unknown_intent(hass, mqtt_mock, caplog):
async def test_unknown_intent(hass, caplog):
"""Test unknown intent."""
await async_mock_mqtt_component(hass)

caplog.set_level(logging.WARNING)
result = await async_setup_component(hass, "snips", {
"snips": {},
Expand All @@ -297,8 +317,10 @@ async def test_unknown_intent(hass, mqtt_mock, caplog):
assert 'Received unknown intent unknownIntent' in caplog.text


async def test_snips_intent_user(hass, mqtt_mock):
async def test_snips_intent_user(hass):
"""Test intentName format user_XXX__intentName."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {},
})
Expand All @@ -324,8 +346,10 @@ async def test_snips_intent_user(hass, mqtt_mock):
assert intent.intent_type == 'Lights'


async def test_snips_intent_username(hass, mqtt_mock):
async def test_snips_intent_username(hass):
"""Test intentName format username:intentName."""
await async_mock_mqtt_component(hass)

result = await async_setup_component(hass, "snips", {
"snips": {},
})
Expand All @@ -351,8 +375,10 @@ async def test_snips_intent_username(hass, mqtt_mock):
assert intent.intent_type == 'Lights'


async def test_snips_low_probability(hass, mqtt_mock, caplog):
async def test_snips_low_probability(hass, caplog):
"""Test intent via Snips."""
await async_mock_mqtt_component(hass)

caplog.set_level(logging.WARNING)
result = await async_setup_component(hass, "snips", {
"snips": {
Expand All @@ -378,8 +404,10 @@ async def test_snips_low_probability(hass, mqtt_mock, caplog):
assert 'Intent below probaility threshold 0.49 < 0.5' in caplog.text


async def test_intent_special_slots(hass, mqtt_mock):
async def test_intent_special_slots(hass):
"""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": {},
Expand Down Expand Up @@ -420,7 +448,7 @@ async def test_intent_special_slots(hass, mqtt_mock):
assert calls[0].data['site_id'] == 'default'


async def test_snips_say(hass, caplog):
async def test_snips_say(hass):
"""Test snips say with invalid config."""
calls = async_mock_service(hass, 'snips', 'say', snips.SERVICE_SCHEMA_SAY)
data = {'text': 'Hello'}
Expand All @@ -433,7 +461,7 @@ async def test_snips_say(hass, caplog):
assert calls[0].data['text'] == 'Hello'


async def test_snips_say_action(hass, caplog):
async def test_snips_say_action(hass):
"""Test snips say_action with invalid config."""
calls = async_mock_service(hass, 'snips', 'say_action',
snips.SERVICE_SCHEMA_SAY_ACTION)
Expand All @@ -449,7 +477,7 @@ async def test_snips_say_action(hass, caplog):
assert calls[0].data['intent_filter'] == ['myIntent']


async def test_snips_say_invalid_config(hass, caplog):
async def test_snips_say_invalid_config(hass):
"""Test snips say with invalid config."""
calls = async_mock_service(hass, 'snips', 'say',
snips.SERVICE_SCHEMA_SAY)
Expand All @@ -462,7 +490,7 @@ async def test_snips_say_invalid_config(hass, caplog):
assert len(calls) == 0


async def test_snips_say_action_invalid(hass, caplog):
async def test_snips_say_action_invalid(hass):
"""Test snips say_action with invalid config."""
calls = async_mock_service(hass, 'snips', 'say_action',
snips.SERVICE_SCHEMA_SAY_ACTION)
Expand All @@ -476,7 +504,7 @@ async def test_snips_say_action_invalid(hass, caplog):
assert len(calls) == 0


async def test_snips_feedback_on(hass, caplog):
async def test_snips_feedback_on(hass):
"""Test snips say with invalid config."""
calls = async_mock_service(hass, 'snips', 'feedback_on',
snips.SERVICE_SCHEMA_FEEDBACK)
Expand All @@ -491,7 +519,7 @@ async def test_snips_feedback_on(hass, caplog):
assert calls[0].data['site_id'] == 'remote'


async def test_snips_feedback_off(hass, caplog):
async def test_snips_feedback_off(hass):
"""Test snips say with invalid config."""
calls = async_mock_service(hass, 'snips', 'feedback_off',
snips.SERVICE_SCHEMA_FEEDBACK)
Expand All @@ -506,7 +534,7 @@ async def test_snips_feedback_off(hass, caplog):
assert calls[0].data['site_id'] == 'remote'


async def test_snips_feedback_config(hass, caplog):
async def test_snips_feedback_config(hass):
"""Test snips say with invalid config."""
calls = async_mock_service(hass, 'snips', 'feedback_on',
snips.SERVICE_SCHEMA_FEEDBACK)
Expand Down
10 changes: 1 addition & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.auth.providers import legacy_api_password, homeassistant

from tests.common import (
async_test_home_assistant, INSTANCES, async_mock_mqtt_component, mock_coro,
async_test_home_assistant, INSTANCES, mock_coro,
mock_storage as mock_storage, MockUser, CLIENT_ID)
from tests.test_util.aiohttp import mock_aiohttp_client
from tests.mock.zwave import MockNetwork, MockOption
Expand Down Expand Up @@ -92,14 +92,6 @@ def aioclient_mock():
yield mock_session


@pytest.fixture
def mqtt_mock(loop, hass):
"""Fixture to mock MQTT."""
client = loop.run_until_complete(async_mock_mqtt_component(hass))
client.reset_mock()
return client


@pytest.fixture
def mock_openzwave():
"""Mock out Open Z-Wave."""
Expand Down