Drop unnecessary block_till_done, improve tests (#23248)
This commit is contained in:
parent
0e429cca33
commit
13e0691c90
1 changed files with 9 additions and 19 deletions
|
@ -1,5 +1,4 @@
|
||||||
"""The tests for mqtt camera component."""
|
"""The tests for mqtt camera component."""
|
||||||
import asyncio
|
|
||||||
from unittest.mock import ANY
|
from unittest.mock import ANY
|
||||||
|
|
||||||
from homeassistant.components import camera, mqtt
|
from homeassistant.components import camera, mqtt
|
||||||
|
@ -11,12 +10,11 @@ from tests.common import (
|
||||||
mock_registry)
|
mock_registry)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_run_camera_setup(hass, aiohttp_client):
|
||||||
def test_run_camera_setup(hass, aiohttp_client):
|
|
||||||
"""Test that it fetches the given payload."""
|
"""Test that it fetches the given payload."""
|
||||||
topic = 'test/camera'
|
topic = 'test/camera'
|
||||||
yield from async_mock_mqtt_component(hass)
|
await async_mock_mqtt_component(hass)
|
||||||
yield from async_setup_component(hass, 'camera', {
|
await async_setup_component(hass, 'camera', {
|
||||||
'camera': {
|
'camera': {
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'topic': topic,
|
'topic': topic,
|
||||||
|
@ -26,20 +24,18 @@ def test_run_camera_setup(hass, aiohttp_client):
|
||||||
url = hass.states.get('camera.test_camera').attributes['entity_picture']
|
url = hass.states.get('camera.test_camera').attributes['entity_picture']
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, topic, 'beer')
|
async_fire_mqtt_message(hass, topic, 'beer')
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
|
|
||||||
client = yield from aiohttp_client(hass.http.app)
|
client = await aiohttp_client(hass.http.app)
|
||||||
resp = yield from client.get(url)
|
resp = await client.get(url)
|
||||||
assert resp.status == 200
|
assert resp.status == 200
|
||||||
body = yield from resp.text()
|
body = await resp.text()
|
||||||
assert body == 'beer'
|
assert body == 'beer'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_unique_id(hass):
|
||||||
def test_unique_id(hass):
|
|
||||||
"""Test unique id option only creates one camera per unique_id."""
|
"""Test unique id option only creates one camera per unique_id."""
|
||||||
yield from async_mock_mqtt_component(hass)
|
await async_mock_mqtt_component(hass)
|
||||||
yield from async_setup_component(hass, 'camera', {
|
await async_setup_component(hass, 'camera', {
|
||||||
'camera': [{
|
'camera': [{
|
||||||
'platform': 'mqtt',
|
'platform': 'mqtt',
|
||||||
'name': 'Test Camera 1',
|
'name': 'Test Camera 1',
|
||||||
|
@ -54,7 +50,6 @@ def test_unique_id(hass):
|
||||||
})
|
})
|
||||||
|
|
||||||
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
async_fire_mqtt_message(hass, 'test-topic', 'payload')
|
||||||
yield from hass.async_block_till_done()
|
|
||||||
assert len(hass.states.async_all()) == 1
|
assert len(hass.states.async_all()) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +66,6 @@ async def test_discovery_removal_camera(hass, mqtt_mock, caplog):
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
||||||
data)
|
data)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('camera.beer')
|
state = hass.states.get('camera.beer')
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -80,7 +74,6 @@ async def test_discovery_removal_camera(hass, mqtt_mock, caplog):
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
||||||
'')
|
'')
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('camera.beer')
|
state = hass.states.get('camera.beer')
|
||||||
assert state is None
|
assert state is None
|
||||||
|
@ -111,7 +104,6 @@ async def test_discovery_update_camera(hass, mqtt_mock, caplog):
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
||||||
data2)
|
data2)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('camera.beer')
|
state = hass.states.get('camera.beer')
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -143,7 +135,6 @@ async def test_discovery_broken(hass, mqtt_mock, caplog):
|
||||||
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
async_fire_mqtt_message(hass, 'homeassistant/camera/bla/config',
|
||||||
data2)
|
data2)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('camera.milk')
|
state = hass.states.get('camera.milk')
|
||||||
assert state is not None
|
assert state is not None
|
||||||
|
@ -173,7 +164,6 @@ async def test_entity_id_update(hass, mqtt_mock):
|
||||||
|
|
||||||
registry.async_update_entity('camera.beer', new_entity_id='camera.milk')
|
registry.async_update_entity('camera.beer', new_entity_id='camera.milk')
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
state = hass.states.get('camera.beer')
|
state = hass.states.get('camera.beer')
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue