-
-
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
Hass.io sent token to supervisor #15536
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -3,8 +3,11 @@ | |
import os | ||
from unittest.mock import patch, Mock | ||
|
||
import pytest | ||
|
||
from homeassistant.setup import async_setup_component | ||
from homeassistant.components.hassio import async_check_config | ||
from homeassistant.components.hassio import ( | ||
STORAGE_KEY, async_check_config) | ||
|
||
from tests.common import mock_coro | ||
|
||
|
@@ -14,36 +17,34 @@ | |
'HASSIO_TOKEN': 'abcdefgh', | ||
} | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_ping(hass, aioclient_mock): | ||
"""Test setup with API ping.""" | ||
@pytest.fixture(autouse=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
def mock_all(aioclient_mock): | ||
"""Mock all setup requests.""" | ||
aioclient_mock.post( | ||
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'}) | ||
aioclient_mock.get( | ||
"http://127.0.0.1/supervisor/ping", json={'result': 'ok'}) | ||
aioclient_mock.post( | ||
"http://127.0.0.1/supervisor/options", json={'result': 'ok'}) | ||
aioclient_mock.get( | ||
"http://127.0.0.1/homeassistant/info", json={ | ||
'result': 'ok', 'data': {'last_version': '10.0'}}) | ||
|
||
@asyncio.coroutine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
def test_setup_api_ping(hass, aioclient_mock): | ||
"""Test setup with API ping.""" | ||
with patch.dict(os.environ, MOCK_ENVIRON): | ||
result = yield from async_setup_component(hass, 'hassio', {}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 2 | ||
assert aioclient_mock.call_count == 3 | ||
assert hass.components.hassio.get_homeassistant_version() == "10.0" | ||
assert hass.components.hassio.is_hassio() | ||
|
||
|
||
@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'}) | ||
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, MOCK_ENVIRON): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'http': { | ||
|
@@ -64,14 +65,6 @@ def test_setup_api_push_api_data(hass, aioclient_mock): | |
@asyncio.coroutine | ||
def test_setup_api_push_api_data_server_host(hass, aioclient_mock): | ||
"""Test setup with API push with active server host.""" | ||
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, MOCK_ENVIRON): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'http': { | ||
|
@@ -90,19 +83,61 @@ def test_setup_api_push_api_data_server_host(hass, aioclient_mock): | |
assert not aioclient_mock.mock_calls[1][2]['watchdog'] | ||
|
||
|
||
@asyncio.coroutine | ||
def test_setup_api_push_api_data_default(hass, aioclient_mock): | ||
async def test_setup_api_push_api_data_default(hass, aioclient_mock, | ||
hass_storage): | ||
"""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.post( | ||
"http://127.0.0.1/homeassistant/options", json={'result': 'ok'}) | ||
with patch.dict(os.environ, MOCK_ENVIRON), \ | ||
patch('homeassistant.auth.AuthManager.active', return_value=True): | ||
result = await 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 | ||
refresh_token = aioclient_mock.mock_calls[1][2]['refresh_token'] | ||
hassio_user = await hass.auth.async_get_user( | ||
hass_storage[STORAGE_KEY]['data']['hassio_user'] | ||
) | ||
assert hassio_user is not None | ||
assert hassio_user.system_generated | ||
assert refresh_token in hassio_user.refresh_tokens | ||
|
||
|
||
async def test_setup_api_push_api_data_no_auth(hass, aioclient_mock, | ||
hass_storage): | ||
"""Test setup with API push default data.""" | ||
with patch.dict(os.environ, MOCK_ENVIRON): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
result = await 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 | ||
assert aioclient_mock.mock_calls[1][2]['refresh_token'] is None | ||
|
||
|
||
async def test_setup_api_existing_hassio_user(hass, aioclient_mock, | ||
hass_storage): | ||
"""Test setup with API push default data.""" | ||
user = await hass.auth.async_create_system_user('Hass.io test') | ||
token = await hass.auth.async_create_refresh_token(user) | ||
hass_storage[STORAGE_KEY] = { | ||
'version': 1, | ||
'data': { | ||
'hassio_user': user.id | ||
} | ||
} | ||
with patch.dict(os.environ, MOCK_ENVIRON), \ | ||
patch('homeassistant.auth.AuthManager.active', return_value=True): | ||
result = await async_setup_component(hass, 'hassio', { | ||
'http': {}, | ||
'hassio': {} | ||
}) | ||
|
@@ -112,19 +147,12 @@ def test_setup_api_push_api_data_default(hass, aioclient_mock): | |
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 | ||
assert aioclient_mock.mock_calls[1][2]['refresh_token'] == token.token | ||
|
||
|
||
@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'}) | ||
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'}) | ||
|
||
with patch.dict(os.environ, MOCK_ENVIRON): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'hassio': {}, | ||
|
@@ -134,29 +162,21 @@ def test_setup_core_push_timezone(hass, aioclient_mock): | |
}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 3 | ||
assert aioclient_mock.mock_calls[1][2]['timezone'] == "testzone" | ||
assert aioclient_mock.call_count == 4 | ||
assert aioclient_mock.mock_calls[2][2]['timezone'] == "testzone" | ||
|
||
|
||
@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'}) | ||
|
||
with patch.dict(os.environ, MOCK_ENVIRON), \ | ||
patch.dict(os.environ, {'HASSIO_TOKEN': "123456"}): | ||
result = yield from async_setup_component(hass, 'hassio', { | ||
'hassio': {}, | ||
}) | ||
assert result | ||
|
||
assert aioclient_mock.call_count == 2 | ||
assert aioclient_mock.call_count == 3 | ||
assert aioclient_mock.mock_calls[-1][3]['X-HASSIO-KEY'] == "123456" | ||
|
||
|
||
|
@@ -234,14 +254,14 @@ def test_service_calls(hassio_env, hass, aioclient_mock): | |
'hassio', 'addon_stdin', {'addon': 'test', 'input': 'test'}) | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 4 | ||
assert aioclient_mock.call_count == 5 | ||
assert aioclient_mock.mock_calls[-1][2] == 'test' | ||
|
||
yield from hass.services.async_call('hassio', 'host_shutdown', {}) | ||
yield from hass.services.async_call('hassio', 'host_reboot', {}) | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 6 | ||
assert aioclient_mock.call_count == 7 | ||
|
||
yield from hass.services.async_call('hassio', 'snapshot_full', {}) | ||
yield from hass.services.async_call('hassio', 'snapshot_partial', { | ||
|
@@ -251,7 +271,7 @@ def test_service_calls(hassio_env, hass, aioclient_mock): | |
}) | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 8 | ||
assert aioclient_mock.call_count == 9 | ||
assert aioclient_mock.mock_calls[-1][2] == { | ||
'addons': ['test'], 'folders': ['ssl'], 'password': "123456"} | ||
|
||
|
@@ -267,7 +287,7 @@ def test_service_calls(hassio_env, hass, aioclient_mock): | |
}) | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 10 | ||
assert aioclient_mock.call_count == 11 | ||
assert aioclient_mock.mock_calls[-1][2] == { | ||
'addons': ['test'], 'folders': ['ssl'], 'homeassistant': False, | ||
'password': "123456" | ||
|
@@ -289,17 +309,17 @@ def test_service_calls_core(hassio_env, hass, aioclient_mock): | |
yield from hass.services.async_call('homeassistant', 'stop') | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 1 | ||
assert aioclient_mock.call_count == 2 | ||
|
||
yield from hass.services.async_call('homeassistant', 'check_config') | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 2 | ||
assert aioclient_mock.call_count == 3 | ||
|
||
yield from hass.services.async_call('homeassistant', 'restart') | ||
yield from hass.async_block_till_done() | ||
|
||
assert aioclient_mock.call_count == 4 | ||
assert aioclient_mock.call_count == 5 | ||
|
||
|
||
@asyncio.coroutine | ||
|
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.
Do we want migrate it to
await
?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.
In a different PR.