* Fix demo

* Fix types

* Fix all the things

* Fix type

* Fix test

* Lint
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2019-04-14 16:59:06 -07:00
1 parent 1d2e9b6915
commit 6b0180f753
20 files changed
+137 -200

No files matched your search

+6 -6
View File
@@ -157,7 +157,7 @@ def test_snapshot_service(hass, mock_camera):
async def test_websocket_camera_thumbnail(hass, hass_ws_client, mock_camera):
"""Test camera_thumbnail websocket command."""
await async_setup_component(hass, 'camera')
await async_setup_component(hass, 'camera', {})
client = await hass_ws_client(hass)
await client.send_json({
@@ -179,7 +179,7 @@ async def test_websocket_camera_thumbnail(hass, hass_ws_client, mock_camera):
async def test_websocket_stream_no_source(hass, hass_ws_client,
mock_camera, mock_stream):
"""Test camera/stream websocket command."""
await async_setup_component(hass, 'camera')
await async_setup_component(hass, 'camera', {})
with patch('homeassistant.components.camera.request_stream',
return_value='http://home.assistant/playlist.m3u8') \
@@ -203,7 +203,7 @@ async def test_websocket_stream_no_source(hass, hass_ws_client,
async def test_websocket_camera_stream(hass, hass_ws_client,
mock_camera, mock_stream):
"""Test camera/stream websocket command."""
await async_setup_component(hass, 'camera')
await async_setup_component(hass, 'camera', {})
with patch('homeassistant.components.camera.request_stream',
return_value='http://home.assistant/playlist.m3u8'
@@ -231,7 +231,7 @@ async def test_websocket_camera_stream(hass, hass_ws_client,
async def test_websocket_get_prefs(hass, hass_ws_client,
mock_camera):
"""Test get camera preferences websocket command."""
await async_setup_component(hass, 'camera')
await async_setup_component(hass, 'camera', {})
# Request preferences through websocket
client = await hass_ws_client(hass)
@@ -249,7 +249,7 @@ async def test_websocket_get_prefs(hass, hass_ws_client,
async def test_websocket_update_prefs(hass, hass_ws_client,
mock_camera, setup_camera_prefs):
"""Test updating preference."""
await async_setup_component(hass, 'camera')
await async_setup_component(hass, 'camera', {})
assert setup_camera_prefs[PREF_PRELOAD_STREAM]
client = await hass_ws_client(hass)
await client.send_json({
@@ -281,7 +281,7 @@ async def test_play_stream_service_no_source(hass, mock_camera, mock_stream):
async def test_handle_play_stream_service(hass, mock_camera, mock_stream):
"""Test camera play_stream service."""
await async_setup_component(hass, 'media_player')
await async_setup_component(hass, 'media_player', {})
data = {
ATTR_ENTITY_ID: 'camera.demo_camera',
camera.ATTR_MEDIA_PLAYER: 'media_player.test'
+1 -1
View File
@@ -24,7 +24,7 @@ def hass_ws_client(aiohttp_client, hass_access_token):
"""Websocket client fixture connected to websocket server."""
async def create_client(hass, access_token=hass_access_token):
"""Create a websocket client."""
assert await async_setup_component(hass, 'websocket_api')
assert await async_setup_component(hass, 'websocket_api', {})
client = await aiohttp_client(hass.http.app)
+7 -4
View File
@@ -42,8 +42,9 @@ class TestDemoPlatform(unittest.TestCase):
# In this test, one zone and geolocation entities have been
# generated.
all_states = self.hass.states.all()
assert len(all_states) == NUMBER_OF_DEMO_DEVICES + 1
all_states = [self.hass.states.get(entity_id) for entity_id
in self.hass.states.entity_ids(geo_location.DOMAIN)]
assert len(all_states) == NUMBER_OF_DEMO_DEVICES
for state in all_states:
# Check a single device's attributes.
@@ -66,6 +67,8 @@ class TestDemoPlatform(unittest.TestCase):
self.hass.block_till_done()
# Get all states again, ensure that the number of states is still
# the same, but the lists are different.
all_states_updated = self.hass.states.all()
assert len(all_states_updated) == NUMBER_OF_DEMO_DEVICES + 1
all_states_updated = [
self.hass.states.get(entity_id) for entity_id
in self.hass.states.entity_ids(geo_location.DOMAIN)]
assert len(all_states_updated) == NUMBER_OF_DEMO_DEVICES
assert all_states != all_states_updated
+8 -38
View File
@@ -1,5 +1,4 @@
"""The tests for the Demo component."""
import asyncio
import json
import os
@@ -16,18 +15,6 @@ def mock_history(hass):
hass.config.components.add('history')
@pytest.fixture
def minimize_demo_platforms(hass):
"""Cleanup demo component for tests."""
orig = demo.COMPONENTS_WITH_DEMO_PLATFORM
demo.COMPONENTS_WITH_DEMO_PLATFORM = [
'switch', 'light', 'media_player']
yield
demo.COMPONENTS_WITH_DEMO_PLATFORM = orig
@pytest.fixture(autouse=True)
def demo_cleanup(hass):
"""Clean up device tracker demo file."""
@@ -38,32 +25,15 @@ def demo_cleanup(hass):
pass
@pytest.mark.skip
@asyncio.coroutine
def test_if_demo_state_shows_by_default(hass, minimize_demo_platforms):
"""Test if demo state shows if we give no configuration."""
yield from async_setup_component(hass, demo.DOMAIN, {demo.DOMAIN: {}})
assert hass.states.get('a.Demo_Mode') is not None
@pytest.mark.skip
@asyncio.coroutine
def test_hiding_demo_state(hass, minimize_demo_platforms):
"""Test if you can hide the demo card."""
yield from async_setup_component(hass, demo.DOMAIN, {
demo.DOMAIN: {'hide_demo_state': 1}})
assert hass.states.get('a.Demo_Mode') is None
@pytest.mark.skip
@asyncio.coroutine
def test_all_entities_can_be_loaded_over_json(hass):
"""Test if you can hide the demo card."""
yield from async_setup_component(hass, demo.DOMAIN, {
demo.DOMAIN: {'hide_demo_state': 1}})
async def test_setting_up_demo(hass):
"""Test if we can set up the demo and dump it to JSON."""
assert await async_setup_component(hass, demo.DOMAIN, {
'demo': {}
})
await hass.async_start()
# This is done to make sure entity components don't accidentally store
# non-JSON-serializable data in the state machine.
try:
json.dumps(hass.states.async_all(), cls=JSONEncoder)
except Exception:
+1 -1
View File
@@ -74,7 +74,7 @@ class TestNotifyDemo(unittest.TestCase):
self.hass.block_till_done()
assert notify.DOMAIN in self.hass.config.components
assert mock_demo_get_service.called
assert mock_demo_get_service.call_args[0] == (
assert mock_demo_get_service.mock_calls[0][1] == (
self.hass, {}, {'test_key': 'test_val'})
@callback
+1 -2
View File
@@ -179,10 +179,9 @@ async def test_gravatar_and_picture(hass):
autospec=True)
async def test_discover_platform(mock_demo_setup_scanner, mock_see, hass):
"""Test discovery of device_tracker demo platform."""
assert device_tracker.DOMAIN not in hass.config.components
await discovery.async_load_platform(
hass, device_tracker.DOMAIN, 'demo', {'test_key': 'test_val'},
{'demo': {}})
{'bla': {}})
await hass.async_block_till_done()
assert device_tracker.DOMAIN in hass.config.components
assert mock_demo_setup_scanner.called
+4 -4
View File
@@ -210,7 +210,7 @@ async def test_themes_reload_themes(hass, hass_ws_client):
async def test_missing_themes(hass, hass_ws_client):
"""Test that themes API works when themes are not defined."""
await async_setup_component(hass, 'frontend')
await async_setup_component(hass, 'frontend', {})
client = await hass_ws_client(hass)
await client.send_json({
@@ -247,7 +247,7 @@ def test_extra_urls_es5(mock_http_client_with_urls, mock_onboarded):
async def test_get_panels(hass, hass_ws_client):
"""Test get_panels command."""
await async_setup_component(hass, 'frontend')
await async_setup_component(hass, 'frontend', {})
await hass.components.frontend.async_register_built_in_panel(
'map', 'Map', 'mdi:tooltip-account', require_admin=True)
@@ -272,7 +272,7 @@ async def test_get_panels(hass, hass_ws_client):
async def test_get_panels_non_admin(hass, hass_ws_client, hass_admin_user):
"""Test get_panels command."""
hass_admin_user.groups = []
await async_setup_component(hass, 'frontend')
await async_setup_component(hass, 'frontend', {})
await hass.components.frontend.async_register_built_in_panel(
'map', 'Map', 'mdi:tooltip-account', require_admin=True)
await hass.components.frontend.async_register_built_in_panel(
@@ -295,7 +295,7 @@ async def test_get_panels_non_admin(hass, hass_ws_client, hass_admin_user):
async def test_get_translations(hass, hass_ws_client):
"""Test get_translations command."""
await async_setup_component(hass, 'frontend')
await async_setup_component(hass, 'frontend', {})
client = await hass_ws_client(hass)
with patch('homeassistant.components.frontend.async_get_translations',
+1 -1
View File
@@ -8,7 +8,7 @@ from homeassistant.setup import async_setup_component
async def test_setup_component(hass):
"""Simple test setup of component."""
result = await async_setup_component(hass, geo_location.DOMAIN)
result = await async_setup_component(hass, geo_location.DOMAIN, {})
assert result
@@ -174,7 +174,7 @@ async def test_gen_auth_url(hass, mock_logi_circle): # pylint: disable=W0621
flow = config_flow.LogiCircleFlowHandler()
flow.hass = hass
flow.flow_impl = 'test-auth-url'
await async_setup_component(hass, 'http')
await async_setup_component(hass, 'http', {})
result = flow._get_authorization_url() # pylint: disable=W0212
assert result == 'http://authorize.url'