2014-11-29 06:49:29 +00:00
|
|
|
"""
|
2015-01-09 04:05:12 +00:00
|
|
|
tests.test_component_demo
|
2016-02-13 13:19:11 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
2014-11-29 06:49:29 +00:00
|
|
|
|
|
|
|
Tests demo component.
|
|
|
|
"""
|
2015-09-13 15:08:46 +00:00
|
|
|
import json
|
2016-02-14 23:08:23 +00:00
|
|
|
import os
|
2014-11-29 06:49:29 +00:00
|
|
|
import unittest
|
2015-09-13 05:56:49 +00:00
|
|
|
from unittest.mock import patch
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2016-02-14 23:08:23 +00:00
|
|
|
from homeassistant.components import demo, device_tracker
|
2015-09-13 15:08:46 +00:00
|
|
|
from homeassistant.remote import JSONEncoder
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2016-02-14 23:08:23 +00:00
|
|
|
from tests.common import mock_http_component, get_test_home_assistant
|
2015-07-11 07:02:52 +00:00
|
|
|
|
2014-11-29 06:49:29 +00:00
|
|
|
|
2015-09-13 15:08:46 +00:00
|
|
|
@patch('homeassistant.components.sun.setup')
|
2014-11-29 06:49:29 +00:00
|
|
|
class TestDemo(unittest.TestCase):
|
|
|
|
""" Test the demo module. """
|
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
2016-02-14 23:08:23 +00:00
|
|
|
self.hass = get_test_home_assistant()
|
2015-07-11 07:02:52 +00:00
|
|
|
mock_http_component(self.hass)
|
2014-11-29 06:49:29 +00:00
|
|
|
|
|
|
|
def tearDown(self): # pylint: disable=invalid-name
|
|
|
|
""" Stop down stuff we started. """
|
|
|
|
self.hass.stop()
|
|
|
|
|
2016-02-14 23:08:23 +00:00
|
|
|
try:
|
|
|
|
os.remove(self.hass.config.path(device_tracker.YAML_DEVICES))
|
|
|
|
except FileNotFoundError:
|
|
|
|
pass
|
|
|
|
|
2015-09-13 05:56:49 +00:00
|
|
|
def test_if_demo_state_shows_by_default(self, mock_sun_setup):
|
2015-03-17 05:20:31 +00:00
|
|
|
""" Test if demo state shows if we give no configuration. """
|
|
|
|
demo.setup(self.hass, {demo.DOMAIN: {}})
|
|
|
|
|
|
|
|
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
|
|
|
|
2015-09-13 05:56:49 +00:00
|
|
|
def test_hiding_demo_state(self, mock_sun_setup):
|
2014-11-29 06:49:29 +00:00
|
|
|
""" Test if you can hide the demo card. """
|
2015-03-17 05:20:31 +00:00
|
|
|
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
2014-11-29 06:49:29 +00:00
|
|
|
|
|
|
|
self.assertIsNone(self.hass.states.get('a.Demo_Mode'))
|
2015-09-13 15:08:46 +00:00
|
|
|
|
|
|
|
def test_all_entities_can_be_loaded_over_json(self, mock_sun_setup):
|
|
|
|
""" Test if you can hide the demo card. """
|
|
|
|
demo.setup(self.hass, {demo.DOMAIN: {'hide_demo_state': 1}})
|
|
|
|
|
|
|
|
try:
|
|
|
|
json.dumps(self.hass.states.all(), cls=JSONEncoder)
|
|
|
|
except Exception:
|
|
|
|
self.fail('Unable to convert all demo entities to JSON. '
|
|
|
|
'Wrong data in state machine!')
|