Updater improvements to send option component information (#7720)
* Setup to send component data is option is enabled * testcases, as well as moved to a single boolean, passed to the function * fixed pep8 failures * Clarify config option.
This commit is contained in:
parent
a119bd0056
commit
437ddb8dea
2 changed files with 40 additions and 10 deletions
|
@ -19,6 +19,9 @@ MOCK_RESPONSE = {
|
|||
'version': '0.15',
|
||||
'release-notes': 'https://home-assistant.io'
|
||||
}
|
||||
MOCK_CONFIG = {updater.DOMAIN: {
|
||||
'reporting': True
|
||||
}}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -94,11 +97,30 @@ def test_disable_reporting(hass, mock_get_uuid, mock_get_newest_version):
|
|||
yield from hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(updater.ENTITY_ID) is None
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, MOCK_CONFIG)
|
||||
call = mock_get_newest_version.mock_calls[0][1]
|
||||
assert call[0] is hass
|
||||
assert call[1] is None
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_enabled_component_info(hass, mock_get_uuid):
|
||||
"""Test if new entity is created if new version is available."""
|
||||
with patch('homeassistant.components.updater.platform.system',
|
||||
Mock(return_value="junk")):
|
||||
res = yield from updater.get_system_info(hass, True)
|
||||
assert 'components' in res, 'Updater failed to generate component list'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_disable_component_info(hass, mock_get_uuid):
|
||||
"""Test if new entity is created if new version is available."""
|
||||
with patch('homeassistant.components.updater.platform.system',
|
||||
Mock(return_value="junk")):
|
||||
res = yield from updater.get_system_info(hass, False)
|
||||
assert 'components' not in res, 'Updater failed, components generate'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
|
||||
"""Test we do not gather analytics when no huuid is passed in."""
|
||||
|
@ -106,7 +128,7 @@ def test_get_newest_version_no_analytics_when_no_huuid(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
side_effect=Exception):
|
||||
res = yield from updater.get_newest_version(hass, None)
|
||||
res = yield from updater.get_newest_version(hass, None, False)
|
||||
assert res == (MOCK_RESPONSE['version'],
|
||||
MOCK_RESPONSE['release-notes'])
|
||||
|
||||
|
@ -118,7 +140,7 @@ def test_get_newest_version_analytics_when_huuid(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res == (MOCK_RESPONSE['version'],
|
||||
MOCK_RESPONSE['release-notes'])
|
||||
|
||||
|
@ -129,7 +151,7 @@ def test_error_fetching_new_version_timeout(hass):
|
|||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))), \
|
||||
patch('async_timeout.timeout', side_effect=asyncio.TimeoutError):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
||||
|
||||
|
@ -140,7 +162,7 @@ def test_error_fetching_new_version_bad_json(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
||||
|
||||
|
@ -154,5 +176,5 @@ def test_error_fetching_new_version_invalid_response(hass, aioclient_mock):
|
|||
|
||||
with patch('homeassistant.components.updater.get_system_info',
|
||||
Mock(return_value=mock_coro({'fake': 'bla'}))):
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID)
|
||||
res = yield from updater.get_newest_version(hass, MOCK_HUUID, False)
|
||||
assert res is None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue