core/tests/components/test_demo.py

51 lines
1.6 KiB
Python
Raw Normal View History

2014-11-29 06:49:29 +00:00
"""
2015-01-09 04:05:12 +00:00
tests.test_component_demo
~~~~~~~~~~~~~~~~~~~~~~~~~
2014-11-29 06:49:29 +00:00
Tests demo component.
"""
import json
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
2015-08-17 03:44:46 +00:00
import homeassistant.core as ha
2014-11-29 06:49:29 +00:00
import homeassistant.components.demo as demo
from homeassistant.remote import JSONEncoder
2014-11-29 06:49:29 +00:00
from tests.common import mock_http_component
2015-07-11 07:02:52 +00:00
2014-11-29 06:49:29 +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
self.hass = ha.HomeAssistant()
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()
2015-09-13 05:56:49 +00:00
def test_if_demo_state_shows_by_default(self, mock_sun_setup):
""" 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. """
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'))
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!')