-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hassio cleanup part2 #12588
Merged
Merged
Hassio cleanup part2 #12588
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0b052c9
Update handler.py
pvizeli 250925c
Update handler.py
pvizeli d22dc2a
Update __init__.py
pvizeli 4e7d551
Update handler.py
pvizeli 8b846f6
Update handler.py
pvizeli a4ece93
Update __init__.py
pvizeli 23f0379
Update tests
pvizeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
"""Tests for Hassio component.""" | ||
|
||
API_PASSWORD = 'pass1234' | ||
HASSIO_TOKEN = '123456' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,90 @@ | ||
"""The tests for the hassio component.""" | ||
import asyncio | ||
import os | ||
from unittest.mock import patch | ||
|
||
from homeassistant.setup import async_setup_component | ||
import aiohttp | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_ping(hass, aioclient_mock): | ||
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/homeassistant/info", json={ | ||
'result': 'ok', 'data': {'last_version': '10.0'}}) | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}): | ||
result = yield from async_setup_component(hass, 'hassio', {}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 2 | ||
assert hass.components.hassio.get_homeassistant_version() == "10.0" | ||
assert hass.components.hassio.is_hassio() | ||
assert (yield from hassio_handler.is_connected()) | ||
assert aioclient_mock.call_count == 1 | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_push_api_data(hass, aioclient_mock): | ||
"""Test setup with API push.""" | ||
aioclient_mock.get( | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'}) | ||
def test_api_ping_error(hassio_handler, aioclient_mock): | ||
"""Test setup with API ping error.""" | ||
aioclient_mock.get( | ||
"http://127.0.0.1/homeassistant/info", json={ | ||
'result': 'ok', 'data': {'last_version': '10.0'}}) | ||
aioclient_mock.post( | ||
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'}) | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'http': { | ||
'api_password': "123456", | ||
'server_port': 9999 | ||
}, | ||
'hassio': {} | ||
}) | ||
assert result | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'error'}) | ||
|
||
assert aioclient_mock.call_count == 3 | ||
assert not aioclient_mock.mock_calls[1][2]['ssl'] | ||
assert aioclient_mock.mock_calls[1][2]['password'] == "123456" | ||
assert aioclient_mock.mock_calls[1][2]['port'] == 9999 | ||
assert aioclient_mock.mock_calls[1][2]['watchdog'] | ||
assert not (yield from hassio_handler.is_connected()) | ||
assert aioclient_mock.call_count == 1 | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_push_api_data_server_host(hass, aioclient_mock): | ||
"""Test setup with API push with active server host.""" | ||
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", json={'result': 'ok'}) | ||
aioclient_mock.get( | ||
"http://127.0.0.1/homeassistant/info", json={ | ||
'result': 'ok', 'data': {'last_version': '10.0'}}) | ||
aioclient_mock.post( | ||
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'}) | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'http': { | ||
'api_password': "123456", | ||
'server_port': 9999, | ||
'server_host': "127.0.0.1" | ||
}, | ||
'hassio': {} | ||
}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 3 | ||
assert not aioclient_mock.mock_calls[1][2]['ssl'] | ||
assert aioclient_mock.mock_calls[1][2]['password'] == "123456" | ||
assert aioclient_mock.mock_calls[1][2]['port'] == 9999 | ||
assert not aioclient_mock.mock_calls[1][2]['watchdog'] | ||
"http://127.0.0.1/supervisor/ping", exc=aiohttp.ClientError()) | ||
|
||
assert not (yield from hassio_handler.is_connected()) | ||
assert aioclient_mock.call_count == 1 | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_push_api_data_default(hass, aioclient_mock): | ||
"""Test setup with API push default data.""" | ||
aioclient_mock.get( | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'}) | ||
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'}}) | ||
aioclient_mock.post( | ||
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'}) | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'http': {}, | ||
'hassio': {} | ||
}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 3 | ||
assert not aioclient_mock.mock_calls[1][2]['ssl'] | ||
assert aioclient_mock.mock_calls[1][2]['password'] is None | ||
assert aioclient_mock.mock_calls[1][2]['port'] == 8123 | ||
data = yield from hassio_handler.get_homeassistant_info() | ||
assert aioclient_mock.call_count == 1 | ||
assert data['last_version'] == "10.0" | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_core_push_timezone(hass, aioclient_mock): | ||
"""Test setup with API push default data.""" | ||
aioclient_mock.get( | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'}) | ||
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': 'ok', 'data': {'last_version': '10.0'}}) | ||
aioclient_mock.post( | ||
"http://127.0.0.1/supervisor/options", json={'result': 'ok'}) | ||
'result': 'error', 'message': None}) | ||
|
||
data = yield from hassio_handler.get_homeassistant_info() | ||
assert aioclient_mock.call_count == 1 | ||
assert data is None | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'hassio': {}, | ||
'homeassistant': { | ||
'time_zone': 'testzone', | ||
}, | ||
}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 3 | ||
assert aioclient_mock.mock_calls[1][2]['timezone'] == "testzone" | ||
@asyncio.coroutine | ||
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'}) | ||
|
||
assert (yield from hassio_handler.stop_homeassistant()) | ||
assert aioclient_mock.call_count == 1 | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_hassio_no_additional_data(hass, aioclient_mock): | ||
"""Test setup with API push default data.""" | ||
aioclient_mock.get( | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'}) | ||
aioclient_mock.get( | ||
"http://127.0.0.1/homeassistant/info", json={ | ||
'result': 'ok', 'data': {'last_version': '10.0'}}) | ||
aioclient_mock.get( | ||
"http://127.0.0.1/homeassistant/info", json={'result': 'ok'}) | ||
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'}) | ||
|
||
with patch.dict(os.environ, {'HASSIO': "127.0.0.1"}), \ | ||
patch.dict(os.environ, {'HASSIO_TOKEN': "123456"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'hassio': {}, | ||
}) | ||
assert result | ||
assert (yield from hassio_handler.restart_homeassistant()) | ||
assert aioclient_mock.call_count == 1 | ||
|
||
|
||
@asyncio.coroutine | ||
def test_api_homeassistant_config(hassio_handler, aioclient_mock): | ||
"""Test setup with API HomeAssistant restart.""" | ||
aioclient_mock.post( | ||
"http://127.0.0.1/homeassistant/check", json={ | ||
'result': 'ok', 'data': {'test': 'bla'}}) | ||
|
||
assert aioclient_mock.call_count == 2 | ||
assert aioclient_mock.mock_calls[-1][3]['X-HASSIO-KEY'] == "123456" | ||
data = yield from hassio_handler.check_homeassistant_config() | ||
assert data['data']['test'] == 'bla' | ||
assert aioclient_mock.call_count == 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this make you lose what's inside data if result != ok ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: https://github.com/home-assistant/hassio/blob/dev/API.md#hassio-restful-api there is only a data on 'ok'. On 'error' there is a message. Maybe we can log this message if available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great. I am not a fan of silent errors. I prefer raising.