mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 04:37:06 +00:00
Clean up mqtt device tracker tests (#23700)
* Move mqtt device tracker test under mqtt dir * Patch config file load and save * Clean up * Sort imports * Put expected value last in assertions
This commit is contained in:
parent
c0f9ccfdbb
commit
4fe0cd76f8
@ -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):
|
||||
@ -45,7 +36,7 @@ async def test_ensure_device_tracker_platform_validation(hass):
|
||||
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)
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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)
|
Loading…
x
Reference in New Issue
Block a user