Ensure frontend is available if integrations fail to start - Part 1 of 2 (#36093)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
J. Nick KostonandPaulus Schoutsen authored and GitHub committed 2020-05-28 21:09:07 -07:00
1 parent 9c45115468
commit fbe7b4ddfa
13 files changed
+173 -63

No files matched your search

+4 -1
View File
@@ -60,6 +60,9 @@ async def test_hassio_discovery_startup(hass, aioclient_mock, hassio_client):
async def test_hassio_discovery_startup_done(hass, aioclient_mock, hassio_client):
"""Test startup and discovery with hass discovery."""
aioclient_mock.post(
"http://127.0.0.1/supervisor/options", json={"result": "ok", "data": {}},
)
aioclient_mock.get(
"http://127.0.0.1/discovery",
json={
@@ -101,7 +104,7 @@ async def test_hassio_discovery_startup_done(hass, aioclient_mock, hassio_client
await async_setup_component(hass, "hassio", {})
await hass.async_block_till_done()
assert aioclient_mock.call_count == 2
assert aioclient_mock.call_count == 3
assert mock_mqtt.called
mock_mqtt.assert_called_with(
{
+1 -1
View File
@@ -11,7 +11,7 @@ from tests.async_mock import Mock
async def get_client(aiohttp_client, validator):
"""Generate a client that hits a view decorated with validator."""
app = web.Application()
app["hass"] = Mock(is_running=True)
app["hass"] = Mock(is_stopping=False)
class TestView(HomeAssistantView):
url = "/"
+15 -1
View File
@@ -19,7 +19,13 @@ from tests.async_mock import AsyncMock, Mock
@pytest.fixture
def mock_request():
"""Mock a request."""
return Mock(app={"hass": Mock(is_running=True)}, match_info={})
return Mock(app={"hass": Mock(is_stopping=False)}, match_info={})
@pytest.fixture
def mock_request_with_stopping():
"""Mock a request."""
return Mock(app={"hass": Mock(is_stopping=True)}, match_info={})
async def test_invalid_json(caplog):
@@ -55,3 +61,11 @@ async def test_handling_service_not_found(mock_request):
Mock(requires_auth=False),
AsyncMock(side_effect=ServiceNotFound("test", "test")),
)(mock_request)
async def test_not_running(mock_request_with_stopping):
"""Test we get a 503 when not running."""
response = await request_handler_factory(
Mock(requires_auth=False), AsyncMock(side_effect=Unauthorized)
)(mock_request_with_stopping)
assert response.status == 503
+2 -1
View File
@@ -43,7 +43,8 @@ class TestComponentLogbook(unittest.TestCase):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
init_recorder_component(self.hass) # Force an in memory DB
assert setup_component(self.hass, logbook.DOMAIN, self.EMPTY_CONFIG)
with patch("homeassistant.components.http.start_http_server_and_save_config"):
assert setup_component(self.hass, logbook.DOMAIN, self.EMPTY_CONFIG)
def tearDown(self):
"""Stop everything that was started."""
+34 -29
View File
@@ -4,6 +4,7 @@ import unittest
from homeassistant import setup
from homeassistant.components import frontend
from tests.async_mock import patch
from tests.common import get_test_home_assistant
@@ -26,38 +27,42 @@ class TestPanelIframe(unittest.TestCase):
]
for conf in to_try:
assert not setup.setup_component(
self.hass, "panel_iframe", {"panel_iframe": conf}
)
with patch(
"homeassistant.components.http.start_http_server_and_save_config"
):
assert not setup.setup_component(
self.hass, "panel_iframe", {"panel_iframe": conf}
)
def test_correct_config(self):
"""Test correct config."""
assert setup.setup_component(
self.hass,
"panel_iframe",
{
"panel_iframe": {
"router": {
"icon": "mdi:network-wireless",
"title": "Router",
"url": "http://192.168.1.1",
"require_admin": True,
},
"weather": {
"icon": "mdi:weather",
"title": "Weather",
"url": "https://www.wunderground.com/us/ca/san-diego",
"require_admin": True,
},
"api": {"icon": "mdi:weather", "title": "Api", "url": "/api"},
"ftp": {
"icon": "mdi:weather",
"title": "FTP",
"url": "ftp://some/ftp",
},
}
},
)
with patch("homeassistant.components.http.start_http_server_and_save_config"):
assert setup.setup_component(
self.hass,
"panel_iframe",
{
"panel_iframe": {
"router": {
"icon": "mdi:network-wireless",
"title": "Router",
"url": "http://192.168.1.1",
"require_admin": True,
},
"weather": {
"icon": "mdi:weather",
"title": "Weather",
"url": "https://www.wunderground.com/us/ca/san-diego",
"require_admin": True,
},
"api": {"icon": "mdi:weather", "title": "Api", "url": "/api"},
"ftp": {
"icon": "mdi:weather",
"title": "FTP",
"url": "ftp://some/ftp",
},
}
},
)
panels = self.hass.data[frontend.DATA_PANELS]