Add fetching camera thumbnails over websocket (#14231)

* Add fetching camera thumbnails over websocket

* Lint
This commit is contained in:
Paulus Schoutsen authored and Pascal Vizeli committed 2018-05-03 22:02:59 +02:00
1 parent 4ecce2598a
commit 58257af289
8 files changed
+135 -74

No files matched your search

@@ -3,14 +3,13 @@ import asyncio
from unittest.mock import patch, PropertyMock
from homeassistant.core import callback
from homeassistant.const import ATTR_ENTITY_PICTURE
from homeassistant.setup import setup_component
import homeassistant.components.image_processing as ip
from homeassistant.components import camera, image_processing as ip
from homeassistant.components.image_processing.openalpr_cloud import (
OPENALPR_API_URL)
from tests.common import (
get_test_home_assistant, assert_setup_component, load_fixture)
get_test_home_assistant, assert_setup_component, load_fixture, mock_coro)
class TestOpenAlprCloudSetup(object):
@@ -131,11 +130,6 @@ class TestOpenAlprCloud(object):
new_callable=PropertyMock(return_value=False)):
setup_component(self.hass, ip.DOMAIN, config)
state = self.hass.states.get('camera.demo_camera')
self.url = "{0}{1}".format(
self.hass.config.api.base_url,
state.attributes.get(ATTR_ENTITY_PICTURE))
self.alpr_events = []
@callback
@@ -158,18 +152,20 @@ class TestOpenAlprCloud(object):
def test_openalpr_process_image(self, aioclient_mock):
"""Setup and scan a picture and test plates from event."""
aioclient_mock.get(self.url, content=b'image')
aioclient_mock.post(
OPENALPR_API_URL, params=self.params,
text=load_fixture('alpr_cloud.json'), status=200
)
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
with patch('homeassistant.components.camera.async_get_image',
return_value=mock_coro(
camera.Image('image/jpeg', b'image'))):
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
state = self.hass.states.get('image_processing.test_local')
assert len(aioclient_mock.mock_calls) == 2
assert len(aioclient_mock.mock_calls) == 1
assert len(self.alpr_events) == 5
assert state.attributes.get('vehicles') == 1
assert state.state == 'H786P0J'
@@ -184,28 +180,32 @@ class TestOpenAlprCloud(object):
def test_openalpr_process_image_api_error(self, aioclient_mock):
"""Setup and scan a picture and test api error."""
aioclient_mock.get(self.url, content=b'image')
aioclient_mock.post(
OPENALPR_API_URL, params=self.params,
text="{'error': 'error message'}", status=400
)
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
with patch('homeassistant.components.camera.async_get_image',
return_value=mock_coro(
camera.Image('image/jpeg', b'image'))):
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
assert len(aioclient_mock.mock_calls) == 2
assert len(aioclient_mock.mock_calls) == 1
assert len(self.alpr_events) == 0
def test_openalpr_process_image_api_timeout(self, aioclient_mock):
"""Setup and scan a picture and test api error."""
aioclient_mock.get(self.url, content=b'image')
aioclient_mock.post(
OPENALPR_API_URL, params=self.params,
exc=asyncio.TimeoutError()
)
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
with patch('homeassistant.components.camera.async_get_image',
return_value=mock_coro(
camera.Image('image/jpeg', b'image'))):
ip.scan(self.hass, entity_id='image_processing.test_local')
self.hass.block_till_done()
assert len(aioclient_mock.mock_calls) == 2
assert len(aioclient_mock.mock_calls) == 1
assert len(self.alpr_events) == 0