Continue on invalid platforms and new setup_component unit tests (#3736)

This commit is contained in:
Johann Kellerman authored and Paulus Schoutsen committed 2016-10-08 11:27:35 -07:00
1 parent 1b26b5ad14
commit 7b40a641ec
23 files changed
+842 -672

No files matched your search

+13 -12
View File
@@ -8,7 +8,7 @@ from werkzeug.test import EnvironBuilder
from homeassistant.bootstrap import setup_component
from homeassistant.components.http import request_class
from tests.common import get_test_home_assistant
from tests.common import get_test_home_assistant, assert_setup_component
class TestLocalCamera(unittest.TestCase):
@@ -28,21 +28,21 @@ class TestLocalCamera(unittest.TestCase):
"""Test that it loads image from disk."""
self.hass.wsgi = mock.MagicMock()
with NamedTemporaryFile() as fp:
fp.write('hello'.encode('utf-8'))
fp.flush()
with NamedTemporaryFile() as fptr:
fptr.write('hello'.encode('utf-8'))
fptr.flush()
assert setup_component(self.hass, 'camera', {
'camera': {
'name': 'config_test',
'platform': 'local_file',
'file_path': fp.name,
'file_path': fptr.name,
}})
image_view = self.hass.wsgi.mock_calls[0][1][0]
builder = EnvironBuilder(method='GET')
Request = request_class()
Request = request_class() # pylint: disable=invalid-name
request = Request(builder.get_environ())
request.authenticated = True
resp = image_view.get(request, 'camera.config_test')
@@ -54,16 +54,17 @@ class TestLocalCamera(unittest.TestCase):
"""Test local file will not setup when file is not readable."""
self.hass.wsgi = mock.MagicMock()
with NamedTemporaryFile() as fp:
fp.write('hello'.encode('utf-8'))
fp.flush()
with NamedTemporaryFile() as fptr:
fptr.write('hello'.encode('utf-8'))
fptr.flush()
with mock.patch('os.access', return_value=False):
assert not setup_component(self.hass, 'camera', {
with mock.patch('os.access', return_value=False), \
assert_setup_component(0):
assert setup_component(self.hass, 'camera', {
'camera': {
'name': 'config_test',
'platform': 'local_file',
'file_path': fp.name,
'file_path': fptr.name,
}})
assert [] == self.hass.states.all()