Mqtt camera test (#7175)

* mock mqtt

* minor fix

* minor fix

* minor fix
This commit is contained in:
Gianluca Barbaro 2017-04-19 18:26:44 +02:00 committed by Paulus Schoutsen
parent 9b43b39370
commit 632256fae2

View File

@ -1,31 +1,47 @@
"""The tests for mqtt camera component.""" """The tests for mqtt camera component."""
import asyncio import asyncio
import unittest
import pytest
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
import homeassistant.components.mqtt as mqtt
from tests.common import (
get_test_home_assistant, mock_mqtt_component, get_test_instance_port)
import requests
SERVER_PORT = get_test_instance_port()
HTTP_BASE_URL = 'http://127.0.0.1:{}'.format(SERVER_PORT)
@pytest.mark.skip class TestComponentsMQTTCamera(unittest.TestCase):
"""Test MQTT camera platform."""
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.mock_mqtt = mock_mqtt_component(self.hass)
def tearDown(self): # pylint: disable=invalid-name
"""Stop everything that was started."""
self.hass.stop()
@asyncio.coroutine @asyncio.coroutine
def test_run_camera_setup(hass, test_client): def test_run_camera_setup(self):
"""Test that it fetches the given dispatcher data.""" """Test that it fetches the given payload."""
topic = 'test/camera' topic = 'test/camera'
yield from async_setup_component(hass, 'camera', { yield from async_setup_component(self.hass, 'camera', {
'camera': { 'camera': {
'platform': 'mqtt', 'platform': 'mqtt',
'topic': topic, 'topic': topic,
'name': 'Test Camera', 'name': 'Test Camera',
}}) }})
client = yield from test_client(hass.http.app) self.mock_mqtt.publish(self.hass, topic, 0xFFD8FF)
yield from self.hass.async_block_till_done()
mqtt.publish(hass, topic, 0xFFD8FF) resp = requests.get(HTTP_BASE_URL +
yield from hass.async_block_till_done() '/api/camera_proxy/camera.test_camera')
resp = yield from client.get('/api/camera_proxy/camera.test_camera') assert resp.status_code == 200
body = yield from resp.text
assert resp.status == 200
body = yield from resp.text()
assert body == '16767231' assert body == '16767231'