Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -8,17 +8,15 @@ from homeassistant.components.hassio.handler import HassioAPIError
|
||||
|
||||
async def test_api_ping(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API ping."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'})
|
||||
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "ok"})
|
||||
|
||||
assert (await hassio_handler.is_connected())
|
||||
assert await hassio_handler.is_connected()
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_ping_error(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API ping error."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/supervisor/ping", json={'result': 'error'})
|
||||
aioclient_mock.get("http://127.0.0.1/supervisor/ping", json={"result": "error"})
|
||||
|
||||
assert not (await hassio_handler.is_connected())
|
||||
assert aioclient_mock.call_count == 1
|
||||
@@ -26,8 +24,7 @@ async def test_api_ping_error(hassio_handler, aioclient_mock):
|
||||
|
||||
async def test_api_ping_exeption(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API ping exception."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/supervisor/ping", exc=aiohttp.ClientError())
|
||||
aioclient_mock.get("http://127.0.0.1/supervisor/ping", exc=aiohttp.ClientError())
|
||||
|
||||
assert not (await hassio_handler.is_connected())
|
||||
assert aioclient_mock.call_count == 1
|
||||
@@ -36,19 +33,20 @@ async def test_api_ping_exeption(hassio_handler, aioclient_mock):
|
||||
async def test_api_homeassistant_info(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API homeassistant info."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/homeassistant/info", json={
|
||||
'result': 'ok', 'data': {'last_version': '10.0'}})
|
||||
"http://127.0.0.1/homeassistant/info",
|
||||
json={"result": "ok", "data": {"last_version": "10.0"}},
|
||||
)
|
||||
|
||||
data = await hassio_handler.get_homeassistant_info()
|
||||
assert aioclient_mock.call_count == 1
|
||||
assert data['last_version'] == "10.0"
|
||||
assert data["last_version"] == "10.0"
|
||||
|
||||
|
||||
async def test_api_homeassistant_info_error(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API homeassistant info error."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/homeassistant/info", json={
|
||||
'result': 'error', 'message': None})
|
||||
"http://127.0.0.1/homeassistant/info", json={"result": "error", "message": None}
|
||||
)
|
||||
|
||||
with pytest.raises(HassioAPIError):
|
||||
await hassio_handler.get_homeassistant_info()
|
||||
@@ -58,70 +56,76 @@ async def test_api_homeassistant_info_error(hassio_handler, aioclient_mock):
|
||||
|
||||
async def test_api_homeassistant_stop(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API HomeAssistant stop."""
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/stop", json={'result': 'ok'})
|
||||
aioclient_mock.post("http://127.0.0.1/homeassistant/stop", json={"result": "ok"})
|
||||
|
||||
assert (await hassio_handler.stop_homeassistant())
|
||||
assert await hassio_handler.stop_homeassistant()
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_homeassistant_restart(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API HomeAssistant restart."""
|
||||
aioclient_mock.post(
|
||||
"http://127.0.0.1/homeassistant/restart", json={'result': 'ok'})
|
||||
aioclient_mock.post("http://127.0.0.1/homeassistant/restart", json={"result": "ok"})
|
||||
|
||||
assert (await hassio_handler.restart_homeassistant())
|
||||
assert await hassio_handler.restart_homeassistant()
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_addon_info(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API Add-on info."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/addons/test/info", json={
|
||||
'result': 'ok', 'data': {'name': 'bla'}})
|
||||
"http://127.0.0.1/addons/test/info",
|
||||
json={"result": "ok", "data": {"name": "bla"}},
|
||||
)
|
||||
|
||||
data = await hassio_handler.get_addon_info("test")
|
||||
assert data['name'] == 'bla'
|
||||
assert data["name"] == "bla"
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_discovery_message(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API discovery message."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/discovery/test", json={
|
||||
'result': 'ok', 'data': {"service": "mqtt"}})
|
||||
"http://127.0.0.1/discovery/test",
|
||||
json={"result": "ok", "data": {"service": "mqtt"}},
|
||||
)
|
||||
|
||||
data = await hassio_handler.get_discovery_message("test")
|
||||
assert data['service'] == "mqtt"
|
||||
assert data["service"] == "mqtt"
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_retrieve_discovery(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API discovery message."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/discovery", json={
|
||||
'result': 'ok', 'data': {'discovery': [{"service": "mqtt"}]}})
|
||||
"http://127.0.0.1/discovery",
|
||||
json={"result": "ok", "data": {"discovery": [{"service": "mqtt"}]}},
|
||||
)
|
||||
|
||||
data = await hassio_handler.retrieve_discovery_messages()
|
||||
assert data['discovery'][-1]['service'] == "mqtt"
|
||||
assert data["discovery"][-1]["service"] == "mqtt"
|
||||
assert aioclient_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_api_ingress_panels(hassio_handler, aioclient_mock):
|
||||
"""Test setup with API Ingress panels."""
|
||||
aioclient_mock.get(
|
||||
"http://127.0.0.1/ingress/panels", json={'result': 'ok', 'data': {
|
||||
"panels": {
|
||||
"slug": {
|
||||
"enable": True,
|
||||
"title": "Test",
|
||||
"icon": "mdi:test",
|
||||
"admin": False
|
||||
"http://127.0.0.1/ingress/panels",
|
||||
json={
|
||||
"result": "ok",
|
||||
"data": {
|
||||
"panels": {
|
||||
"slug": {
|
||||
"enable": True,
|
||||
"title": "Test",
|
||||
"icon": "mdi:test",
|
||||
"admin": False,
|
||||
}
|
||||
}
|
||||
}
|
||||
}})
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
data = await hassio_handler.get_ingress_panels()
|
||||
assert aioclient_mock.call_count == 1
|
||||
assert data['panels']
|
||||
assert "slug" in data['panels']
|
||||
assert data["panels"]
|
||||
assert "slug" in data["panels"]
|
||||
Reference in new issue
Block a user