Add current user WS command (#15485)

This commit is contained in:
Paulus Schoutsen 2018-07-17 09:24:51 +02:00 committed by GitHub
parent 7eb5cd1267
commit 8797cb78a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 1 deletions

View file

@ -2,6 +2,7 @@
from datetime import timedelta
from unittest.mock import patch
from homeassistant.setup import async_setup_component
from homeassistant.util.dt import utcnow
from homeassistant.components import auth
@ -66,3 +67,29 @@ def test_credential_store_expiration():
with patch('homeassistant.util.dt.utcnow',
return_value=now + timedelta(minutes=9, seconds=59)):
assert retrieve(client_id, code) == credentials
async def test_ws_current_user(hass, hass_ws_client, hass_access_token):
"""Test the current user command."""
assert await async_setup_component(hass, 'auth', {
'http': {
'api_password': 'bla'
}
})
with patch('homeassistant.auth.AuthManager.active', return_value=True):
client = await hass_ws_client(hass, hass_access_token)
await client.send_json({
'id': 5,
'type': auth.WS_TYPE_CURRENT_USER,
})
result = await client.receive_json()
assert result['success'], result
user = hass_access_token.refresh_token.user
user_dict = result['result']
assert user_dict['name'] == user.name
assert user_dict['id'] == user.id
assert user_dict['is_owner'] == user.is_owner