Bugfix/frontend group urls (#4185)

* Remove unnecessary sleeps

* Frontend: fix serving index when refreshing view page.
This commit is contained in:
Paulus Schoutsen 2016-11-02 21:15:23 -07:00 committed by GitHub
parent a3ae96440b
commit 1d100dcac9
9 changed files with 22 additions and 25 deletions

View File

@ -8,8 +8,8 @@ import os
from aiohttp import web
from homeassistant.core import callback
from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.components import api
from homeassistant.const import EVENT_HOMEASSISTANT_START, HTTP_NOT_FOUND
from homeassistant.components import api, group
from homeassistant.components.http import HomeAssistantView
from .version import FINGERPRINTS
@ -184,7 +184,7 @@ class IndexView(HomeAssistantView):
url = '/'
name = "frontend:index"
requires_auth = False
extra_urls = ['/states', '/states/<entity:entity_id>']
extra_urls = ['/states', '/states/{entity_id}']
def __init__(self, hass, extra_urls):
"""Initialize the frontend view."""
@ -202,6 +202,13 @@ class IndexView(HomeAssistantView):
@asyncio.coroutine
def get(self, request, entity_id=None):
"""Serve the index view."""
if entity_id is not None:
state = self.hass.states.get(entity_id)
if (not state or state.domain != 'group' or
not state.attributes.get(group.ATTR_VIEW)):
return self.json_message('Entity not found', HTTP_NOT_FOUND)
if self.hass.http.development:
core_url = '/static/home-assistant-polymer/build/core.js'
ui_url = '/static/home-assistant-polymer/src/home-assistant.html'

View File

@ -1,5 +1,4 @@
"""The tests the for Locative device tracker platform."""
import time
import unittest
from unittest.mock import patch
@ -46,7 +45,6 @@ def setUpModule():
})
hass.start()
time.sleep(0.05)
def tearDownModule(): # pylint: disable=invalid-name

View File

@ -9,7 +9,6 @@ import homeassistant.components.media_player as mp
import homeassistant.components.http as http
import requests
import time
from tests.common import get_test_home_assistant, get_test_instance_port
@ -254,7 +253,6 @@ class TestMediaPlayerWeb(unittest.TestCase):
})
self.hass.start()
time.sleep(0.05)
def tearDown(self):
"""Stop everything that was started."""

View File

@ -1,7 +1,6 @@
"""The tests for the Alexa component."""
# pylint: disable=protected-access
import json
import time
import datetime
import unittest
@ -115,7 +114,6 @@ def setUpModule():
})
hass.start()
time.sleep(0.05)
# pylint: disable=invalid-name

View File

@ -3,7 +3,6 @@
import asyncio
from contextlib import closing
import json
import time
import unittest
from unittest.mock import Mock, patch
@ -50,7 +49,6 @@ def setUpModule():
bootstrap.setup_component(hass, 'api')
hass.start()
time.sleep(0.05)
# pylint: disable=invalid-name

View File

@ -1,5 +1,4 @@
"""The tests for the emulated Hue component."""
import time
import json
import unittest
@ -43,7 +42,6 @@ def setup_hass_instance(emulated_hue_config):
def start_hass_instance(hass):
"""Start the Home Assistant instance to test."""
hass.start()
time.sleep(0.05)
class TestEmulatedHue(unittest.TestCase):

View File

@ -1,7 +1,6 @@
"""The tests for Home Assistant frontend."""
# pylint: disable=protected-access
import re
import time
import unittest
import requests
@ -32,9 +31,6 @@ def setUpModule():
hass = get_test_home_assistant()
hass.bus.listen('test_event', lambda _: _)
hass.states.set('test.test', 'a_state')
assert bootstrap.setup_component(
hass, http.DOMAIN,
{http.DOMAIN: {http.CONF_API_PASSWORD: API_PASSWORD,
@ -43,7 +39,6 @@ def setUpModule():
assert bootstrap.setup_component(hass, 'frontend')
hass.start()
time.sleep(0.05)
# pylint: disable=invalid-name
@ -63,7 +58,6 @@ class TestFrontend(unittest.TestCase):
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
@ -72,9 +66,7 @@ class TestFrontend(unittest.TestCase):
req.text)
self.assertIsNotNone(frontendjs)
req = requests.get(_url(frontendjs.groups(0)[0]))
self.assertEqual(200, req.status_code)
def test_404(self):
@ -84,3 +76,15 @@ class TestFrontend(unittest.TestCase):
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)

View File

@ -1,7 +1,6 @@
"""The tests for the Home Assistant HTTP component."""
# pylint: disable=protected-access
import logging
import time
from ipaddress import ip_network
from unittest.mock import patch
@ -61,7 +60,6 @@ def setUpModule():
for trusted_network in TRUSTED_NETWORKS]
hass.start()
time.sleep(0.05)
# pylint: disable=invalid-name

View File

@ -2,7 +2,6 @@
# pylint: disable=protected-access
import asyncio
import threading
import time
import unittest
from unittest.mock import patch
@ -51,7 +50,6 @@ def setUpModule():
bootstrap.setup_component(hass, 'api')
hass.start()
time.sleep(0.05)
master_api = remote.API('127.0.0.1', API_PASSWORD, MASTER_PORT)