Legacy api fix (#18733)
* Set user for API password requests * Fix tests * Fix typing
This commit is contained in:
parent
9d7b1fc3a7
commit
c2f8dfcb9f
15 changed files with 148 additions and 74 deletions
|
@ -14,9 +14,9 @@ BASIC_CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
async def get_error_log(hass, aiohttp_client, expected_count):
|
||||
async def get_error_log(hass, hass_client, expected_count):
|
||||
"""Fetch all entries from system_log via the API."""
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
client = await hass_client()
|
||||
resp = await client.get('/api/error/all')
|
||||
assert resp.status == 200
|
||||
|
||||
|
@ -45,37 +45,37 @@ def get_frame(name):
|
|||
return (name, None, None, None)
|
||||
|
||||
|
||||
async def test_normal_logs(hass, aiohttp_client):
|
||||
async def test_normal_logs(hass, hass_client):
|
||||
"""Test that debug and info are not logged."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.debug('debug')
|
||||
_LOGGER.info('info')
|
||||
|
||||
# Assert done by get_error_log
|
||||
await get_error_log(hass, aiohttp_client, 0)
|
||||
await get_error_log(hass, hass_client, 0)
|
||||
|
||||
|
||||
async def test_exception(hass, aiohttp_client):
|
||||
async def test_exception(hass, hass_client):
|
||||
"""Test that exceptions are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_generate_and_log_exception('exception message', 'log message')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert_log(log, 'exception message', 'log message', 'ERROR')
|
||||
|
||||
|
||||
async def test_warning(hass, aiohttp_client):
|
||||
async def test_warning(hass, hass_client):
|
||||
"""Test that warning are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.warning('warning message')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert_log(log, '', 'warning message', 'WARNING')
|
||||
|
||||
|
||||
async def test_error(hass, aiohttp_client):
|
||||
async def test_error(hass, hass_client):
|
||||
"""Test that errors are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.error('error message')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert_log(log, '', 'error message', 'ERROR')
|
||||
|
||||
|
||||
|
@ -121,26 +121,26 @@ async def test_error_posted_as_event(hass):
|
|||
assert_log(events[0].data, '', 'error message', 'ERROR')
|
||||
|
||||
|
||||
async def test_critical(hass, aiohttp_client):
|
||||
async def test_critical(hass, hass_client):
|
||||
"""Test that critical are logged and retrieved correctly."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.critical('critical message')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert_log(log, '', 'critical message', 'CRITICAL')
|
||||
|
||||
|
||||
async def test_remove_older_logs(hass, aiohttp_client):
|
||||
async def test_remove_older_logs(hass, hass_client):
|
||||
"""Test that older logs are rotated out."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.error('error message 1')
|
||||
_LOGGER.error('error message 2')
|
||||
_LOGGER.error('error message 3')
|
||||
log = await get_error_log(hass, aiohttp_client, 2)
|
||||
log = await get_error_log(hass, hass_client, 2)
|
||||
assert_log(log[0], '', 'error message 3', 'ERROR')
|
||||
assert_log(log[1], '', 'error message 2', 'ERROR')
|
||||
|
||||
|
||||
async def test_clear_logs(hass, aiohttp_client):
|
||||
async def test_clear_logs(hass, hass_client):
|
||||
"""Test that the log can be cleared via a service call."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.error('error message')
|
||||
|
@ -151,7 +151,7 @@ async def test_clear_logs(hass, aiohttp_client):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
# Assert done by get_error_log
|
||||
await get_error_log(hass, aiohttp_client, 0)
|
||||
await get_error_log(hass, hass_client, 0)
|
||||
|
||||
|
||||
async def test_write_log(hass):
|
||||
|
@ -197,13 +197,13 @@ async def test_write_choose_level(hass):
|
|||
assert logger.method_calls[0] == ('debug', ('test_message',))
|
||||
|
||||
|
||||
async def test_unknown_path(hass, aiohttp_client):
|
||||
async def test_unknown_path(hass, hass_client):
|
||||
"""Test error logged from unknown path."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
_LOGGER.findCaller = MagicMock(
|
||||
return_value=('unknown_path', 0, None, None))
|
||||
_LOGGER.error('error message')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert log['source'] == 'unknown_path'
|
||||
|
||||
|
||||
|
@ -222,31 +222,31 @@ def log_error_from_test_path(path):
|
|||
_LOGGER.error('error message')
|
||||
|
||||
|
||||
async def test_homeassistant_path(hass, aiohttp_client):
|
||||
async def test_homeassistant_path(hass, hass_client):
|
||||
"""Test error logged from homeassistant path."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
with patch('homeassistant.components.system_log.HOMEASSISTANT_PATH',
|
||||
new=['venv_path/homeassistant']):
|
||||
log_error_from_test_path(
|
||||
'venv_path/homeassistant/component/component.py')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert log['source'] == 'component/component.py'
|
||||
|
||||
|
||||
async def test_config_path(hass, aiohttp_client):
|
||||
async def test_config_path(hass, hass_client):
|
||||
"""Test error logged from config path."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
with patch.object(hass.config, 'config_dir', new='config'):
|
||||
log_error_from_test_path('config/custom_component/test.py')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert log['source'] == 'custom_component/test.py'
|
||||
|
||||
|
||||
async def test_netdisco_path(hass, aiohttp_client):
|
||||
async def test_netdisco_path(hass, hass_client):
|
||||
"""Test error logged from netdisco path."""
|
||||
await async_setup_component(hass, system_log.DOMAIN, BASIC_CONFIG)
|
||||
with patch.dict('sys.modules',
|
||||
netdisco=MagicMock(__path__=['venv_path/netdisco'])):
|
||||
log_error_from_test_path('venv_path/netdisco/disco_component.py')
|
||||
log = (await get_error_log(hass, aiohttp_client, 1))[0]
|
||||
log = (await get_error_log(hass, hass_client, 1))[0]
|
||||
assert log['source'] == 'disco_component.py'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue