2016-03-09 09:25:50 +00:00
|
|
|
"""The tests for the 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
|
|
|
|
|
2016-09-25 21:15:21 +00:00
|
|
|
from homeassistant.bootstrap import setup_component
|
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
|
|
|
|
|
|
|
class TestDemo(unittest.TestCase):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test the Demo component."""
|
2014-11-29 06:49:29 +00:00
|
|
|
|
|
|
|
def setUp(self): # pylint: disable=invalid-name
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Setup things to be run when tests are started."""
|
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
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Stop everything that was started."""
|
2014-11-29 06:49:29 +00:00
|
|
|
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
|
|
|
|
|
2016-07-26 05:49:10 +00:00
|
|
|
def test_if_demo_state_shows_by_default(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test if demo state shows if we give no configuration."""
|
2016-09-25 21:15:21 +00:00
|
|
|
setup_component(self.hass, demo.DOMAIN, {demo.DOMAIN: {}})
|
2015-03-17 05:20:31 +00:00
|
|
|
|
|
|
|
self.assertIsNotNone(self.hass.states.get('a.Demo_Mode'))
|
|
|
|
|
2016-07-26 05:49:10 +00:00
|
|
|
def test_hiding_demo_state(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test if you can hide the demo card."""
|
2016-09-25 21:15:21 +00:00
|
|
|
setup_component(self.hass, demo.DOMAIN, {
|
|
|
|
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
|
|
|
|
2016-07-26 05:49:10 +00:00
|
|
|
def test_all_entities_can_be_loaded_over_json(self):
|
2016-03-09 09:25:50 +00:00
|
|
|
"""Test if you can hide the demo card."""
|
2016-09-25 21:15:21 +00:00
|
|
|
setup_component(self.hass, demo.DOMAIN, {
|
|
|
|
demo.DOMAIN: {'hide_demo_state': 1}})
|
2015-09-13 15:08:46 +00:00
|
|
|
|
|
|
|
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!')
|