Skip to content

Commit

Permalink
Clean up mqtt device tracker tests (#23700)
Browse files Browse the repository at this point in the history
* Move mqtt device tracker test under mqtt dir

* Patch config file load and save

* Clean up

* Sort imports

* Put expected value last in assertions
  • Loading branch information
MartinHjelmare authored and rohankapoorcom committed May 5, 2019
1 parent c0f9ccf commit 4fe0cd7
Showing 1 changed file with 15 additions and 22 deletions.
@@ -1,27 +1,18 @@
"""The tests for the MQTT device tracker platform."""
import logging
import os
from asynctest import patch
import pytest

from homeassistant.setup import async_setup_component
from homeassistant.components import device_tracker
from homeassistant.const import CONF_PLATFORM
from homeassistant.setup import async_setup_component

from tests.common import (
async_mock_mqtt_component, async_fire_mqtt_message)

_LOGGER = logging.getLogger(__name__)
from tests.common import async_fire_mqtt_message


@pytest.fixture(autouse=True)
def setup_comp(hass):
"""Initialize components."""
hass.loop.run_until_complete(async_mock_mqtt_component(hass))
yaml_devices = hass.config.path(device_tracker.YAML_DEVICES)
yield
if os.path.isfile(yaml_devices):
os.remove(yaml_devices)
def setup_comp(hass, mqtt_mock):
"""Set up mqtt component."""
pass


async def test_ensure_device_tracker_platform_validation(hass):
Expand All @@ -45,7 +36,7 @@ async def mock_setup_scanner(hass, config, see, discovery_info=None):
assert mock_sp.call_count == 1


async def test_new_message(hass):
async def test_new_message(hass, mock_device_tracker_conf):
"""Test new message."""
dev_id = 'paulus'
entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
Expand All @@ -61,10 +52,10 @@ async def test_new_message(hass):
})
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert location == hass.states.get(entity_id).state
assert hass.states.get(entity_id).state == location


async def test_single_level_wildcard_topic(hass):
async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
"""Test single level wildcard topic."""
dev_id = 'paulus'
entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
Expand All @@ -81,10 +72,10 @@ async def test_single_level_wildcard_topic(hass):
})
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert location == hass.states.get(entity_id).state
assert hass.states.get(entity_id).state == location


async def test_multi_level_wildcard_topic(hass):
async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
"""Test multi level wildcard topic."""
dev_id = 'paulus'
entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
Expand All @@ -101,10 +92,11 @@ async def test_multi_level_wildcard_topic(hass):
})
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert location == hass.states.get(entity_id).state
assert hass.states.get(entity_id).state == location


async def test_single_level_wildcard_topic_not_matching(hass):
async def test_single_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf):
"""Test not matching single level wildcard topic."""
dev_id = 'paulus'
entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
Expand All @@ -124,7 +116,8 @@ async def test_single_level_wildcard_topic_not_matching(hass):
assert hass.states.get(entity_id) is None


async def test_multi_level_wildcard_topic_not_matching(hass):
async def test_multi_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf):
"""Test not matching multi level wildcard topic."""
dev_id = 'paulus'
entity_id = device_tracker.ENTITY_ID_FORMAT.format(dev_id)
Expand Down

0 comments on commit 4fe0cd7

Please sign in to comment.