mirror of
https://github.com/home-assistant/core.git
synced 2025-08-13 15:30:03 +00:00
.github
config
docs
homeassistant
script
tests
components
alarm_control_panel
automation
binary_sensor
camera
__init__.py
test_generic.py
test_local_file.py
test_uvc.py
climate
cover
device_tracker
fan
light
lock
media_player
mqtt
notify
recorder
sensor
switch
weather
__init__.py
test_alexa.py
test_api.py
test_configurator.py
test_conversation.py
test_demo.py
test_device_sun_light_trigger.py
test_emulated_hue.py
test_frontend.py
test_graphite.py
test_group.py
test_history.py
test_http.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_select.py
test_input_slider.py
test_introduction.py
test_logbook.py
test_logentries.py
test_logger.py
test_mqtt_eventstream.py
test_panel_custom.py
test_panel_iframe.py
test_persistent_notification.py
test_pilight.py
test_proximity.py
test_rfxtrx.py
test_scene.py
test_script.py
test_shell_command.py
test_sleepiq.py
test_splunk.py
test_statsd.py
test_sun.py
test_updater.py
test_weblink.py
test_zone.py
fixtures
helpers
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_core.py
test_loader.py
test_main.py
test_remote.py
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.hound.yml
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini

* Remove ThreadPool with async executor * Fix zigbee * update unittest * fix remote api * add pending task to remote * fix lint * remove unused import * remove old stuff for lazy tests * fix bug and add a exception handler to executor * change executor handling * change to wait from gather * fix unittest
61 lines
1.9 KiB
Python
61 lines
1.9 KiB
Python
"""The tests for local file camera component."""
|
|
import asyncio
|
|
from unittest import mock
|
|
|
|
# Using third party package because of a bug reading binary data in Python 3.4
|
|
# https://bugs.python.org/issue23004
|
|
from mock_open import MockOpen
|
|
|
|
from homeassistant.bootstrap import setup_component
|
|
|
|
from tests.common import assert_setup_component, mock_http_component
|
|
|
|
|
|
@asyncio.coroutine
|
|
def test_loading_file(hass, test_client):
|
|
"""Test that it loads image from disk."""
|
|
@mock.patch('os.path.isfile', mock.Mock(return_value=True))
|
|
@mock.patch('os.access', mock.Mock(return_value=True))
|
|
def setup_platform():
|
|
"""Setup platform inside callback."""
|
|
assert setup_component(hass, 'camera', {
|
|
'camera': {
|
|
'name': 'config_test',
|
|
'platform': 'local_file',
|
|
'file_path': 'mock.file',
|
|
}})
|
|
|
|
yield from hass.loop.run_in_executor(None, setup_platform)
|
|
|
|
client = yield from test_client(hass.http.app)
|
|
|
|
m_open = MockOpen(read_data=b'hello')
|
|
with mock.patch(
|
|
'homeassistant.components.camera.local_file.open',
|
|
m_open, create=True
|
|
):
|
|
resp = yield from client.get('/api/camera_proxy/camera.config_test')
|
|
|
|
assert resp.status == 200
|
|
body = yield from resp.text()
|
|
assert body == 'hello'
|
|
|
|
|
|
@asyncio.coroutine
|
|
def test_file_not_readable(hass):
|
|
"""Test local file will not setup when file is not readable."""
|
|
mock_http_component(hass)
|
|
|
|
def run_test():
|
|
with mock.patch('os.path.isfile', mock.Mock(return_value=True)), \
|
|
mock.patch('os.access', return_value=False), \
|
|
assert_setup_component(0, 'camera'):
|
|
assert setup_component(hass, 'camera', {
|
|
'camera': {
|
|
'name': 'config_test',
|
|
'platform': 'local_file',
|
|
'file_path': 'mock.file',
|
|
}})
|
|
|
|
yield from hass.loop.run_in_executor(None, run_test)
|