mirror of
https://github.com/home-assistant/core.git
synced 2025-09-06 19:56:22 +00:00
.github
config
docs
homeassistant
script
tests
components
alarm_control_panel
automation
binary_sensor
camera
climate
cover
device_tracker
fan
light
lock
media_player
mqtt
notify
recorder
sensor
switch
weather
__init__.py
test_alexa.py
test_api.py
test_configurator.py
test_conversation.py
test_demo.py
test_device_sun_light_trigger.py
test_emulated_hue.py
test_frontend.py
test_graphite.py
test_group.py
test_history.py
test_http.py
test_influxdb.py
test_init.py
test_input_boolean.py
test_input_select.py
test_input_slider.py
test_introduction.py
test_logbook.py
test_logentries.py
test_logger.py
test_mqtt_eventstream.py
test_panel_custom.py
test_panel_iframe.py
test_persistent_notification.py
test_pilight.py
test_proximity.py
test_rfxtrx.py
test_scene.py
test_script.py
test_shell_command.py
test_sleepiq.py
test_splunk.py
test_statsd.py
test_sun.py
test_updater.py
test_weblink.py
test_zone.py
fixtures
helpers
resources
scripts
test_util
testing_config
util
__init__.py
common.py
conftest.py
test_bootstrap.py
test_config.py
test_core.py
test_loader.py
test_main.py
test_remote.py
virtualization
.coveragerc
.dockerignore
.gitignore
.gitmodules
.hound.yml
.travis.yml
CONTRIBUTING.md
Dockerfile
LICENSE
MANIFEST.in
README.rst
pylintrc
requirements_all.txt
requirements_docs.txt
requirements_test.txt
setup.cfg
setup.py
tox.ini
91 lines
2.5 KiB
Python
91 lines
2.5 KiB
Python
"""The tests for Home Assistant frontend."""
|
|
# pylint: disable=protected-access
|
|
import re
|
|
import unittest
|
|
|
|
import requests
|
|
|
|
import homeassistant.bootstrap as bootstrap
|
|
from homeassistant.components import frontend, http
|
|
from homeassistant.const import HTTP_HEADER_HA_AUTH
|
|
|
|
from tests.common import get_test_instance_port, get_test_home_assistant
|
|
|
|
API_PASSWORD = "test1234"
|
|
SERVER_PORT = get_test_instance_port()
|
|
HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT)
|
|
HA_HEADERS = {HTTP_HEADER_HA_AUTH: API_PASSWORD}
|
|
|
|
hass = None
|
|
|
|
|
|
def _url(path=""):
|
|
"""Helper method to generate URLs."""
|
|
return HTTP_BASE_URL + path
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
def setUpModule():
|
|
"""Initialize a Home Assistant server."""
|
|
global hass
|
|
|
|
hass = get_test_home_assistant()
|
|
|
|
assert bootstrap.setup_component(
|
|
hass, http.DOMAIN,
|
|
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
|
|
http.CONF_SERVER_PORT: SERVER_PORT}})
|
|
|
|
assert bootstrap.setup_component(hass, 'frontend')
|
|
|
|
hass.start()
|
|
|
|
|
|
# pylint: disable=invalid-name
|
|
def tearDownModule():
|
|
"""Stop everything that was started."""
|
|
hass.stop()
|
|
frontend.PANELS = {}
|
|
|
|
|
|
class TestFrontend(unittest.TestCase):
|
|
"""Test the frontend."""
|
|
|
|
def tearDown(self):
|
|
"""Stop everything that was started."""
|
|
hass.block_till_done()
|
|
|
|
def test_frontend_and_static(self):
|
|
"""Test if we can get the frontend."""
|
|
req = requests.get(_url(""))
|
|
self.assertEqual(200, req.status_code)
|
|
|
|
# Test we can retrieve frontend.js
|
|
frontendjs = re.search(
|
|
r'(?P<app>\/static\/frontend-[A-Za-z0-9]{32}.html)',
|
|
req.text)
|
|
|
|
self.assertIsNotNone(frontendjs)
|
|
req = requests.get(_url(frontendjs.groups(0)[0]))
|
|
self.assertEqual(200, req.status_code)
|
|
|
|
def test_404(self):
|
|
"""Test for HTTP 404 error."""
|
|
self.assertEqual(404, requests.get(_url("/not-existing")).status_code)
|
|
|
|
def test_we_cannot_POST_to_root(self):
|
|
"""Test that POST is not allow to root."""
|
|
self.assertEqual(405, requests.post(_url("")).status_code)
|
|
|
|
def test_states_routes(self):
|
|
"""All served by index."""
|
|
req = requests.get(_url("/states"))
|
|
self.assertEqual(200, req.status_code)
|
|
|
|
req = requests.get(_url("/states/group.non_existing"))
|
|
self.assertEqual(404, req.status_code)
|
|
|
|
hass.states.set('group.existing', 'on', {'view': True})
|
|
req = requests.get(_url("/states/group.existing"))
|
|
self.assertEqual(200, req.status_code)
|