Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -9,10 +9,10 @@ from homeassistant.auth import auth_store
|
||||
async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"""Test we correctly load old data without any groups."""
|
||||
hass_storage[auth_store.STORAGE_KEY] = {
|
||||
'version': 1,
|
||||
'data': {
|
||||
'credentials': [],
|
||||
'users': [
|
||||
"version": 1,
|
||||
"data": {
|
||||
"credentials": [],
|
||||
"users": [
|
||||
{
|
||||
"id": "user-id",
|
||||
"is_active": True,
|
||||
@@ -26,7 +26,7 @@ async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"is_owner": True,
|
||||
"name": "Hass.io",
|
||||
"system_generated": True,
|
||||
}
|
||||
},
|
||||
],
|
||||
"refresh_tokens": [
|
||||
{
|
||||
@@ -37,7 +37,7 @@ async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"jwt_key": "some-key",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "user-id"
|
||||
"user_id": "user-id",
|
||||
},
|
||||
{
|
||||
"access_token_expiration": 1800.0,
|
||||
@@ -47,7 +47,7 @@ async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"jwt_key": "some-key",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "system-id"
|
||||
"user_id": "system-id",
|
||||
},
|
||||
{
|
||||
"access_token_expiration": 1800.0,
|
||||
@@ -56,10 +56,10 @@ async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
"id": "hidden-because-no-jwt-id",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "user-id"
|
||||
"user_id": "user-id",
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
store = auth_store.AuthStore(hass)
|
||||
@@ -87,29 +87,29 @@ async def test_loading_no_group_data_format(hass, hass_storage):
|
||||
assert owner.groups == [admin_group]
|
||||
assert len(owner.refresh_tokens) == 1
|
||||
owner_token = list(owner.refresh_tokens.values())[0]
|
||||
assert owner_token.id == 'user-token-id'
|
||||
assert owner_token.id == "user-token-id"
|
||||
|
||||
assert system.system_generated is True
|
||||
assert system.groups == []
|
||||
assert len(system.refresh_tokens) == 1
|
||||
system_token = list(system.refresh_tokens.values())[0]
|
||||
assert system_token.id == 'system-token-id'
|
||||
assert system_token.id == "system-token-id"
|
||||
|
||||
|
||||
async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
"""Test we correctly load old data with single group."""
|
||||
hass_storage[auth_store.STORAGE_KEY] = {
|
||||
'version': 1,
|
||||
'data': {
|
||||
'credentials': [],
|
||||
'users': [
|
||||
"version": 1,
|
||||
"data": {
|
||||
"credentials": [],
|
||||
"users": [
|
||||
{
|
||||
"id": "user-id",
|
||||
"is_active": True,
|
||||
"is_owner": True,
|
||||
"name": "Paulus",
|
||||
"system_generated": False,
|
||||
'group_ids': ['abcd-all-access']
|
||||
"group_ids": ["abcd-all-access"],
|
||||
},
|
||||
{
|
||||
"id": "system-id",
|
||||
@@ -117,14 +117,9 @@ async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
"is_owner": True,
|
||||
"name": "Hass.io",
|
||||
"system_generated": True,
|
||||
}
|
||||
],
|
||||
"groups": [
|
||||
{
|
||||
"id": "abcd-all-access",
|
||||
"name": "All Access",
|
||||
}
|
||||
},
|
||||
],
|
||||
"groups": [{"id": "abcd-all-access", "name": "All Access"}],
|
||||
"refresh_tokens": [
|
||||
{
|
||||
"access_token_expiration": 1800.0,
|
||||
@@ -134,7 +129,7 @@ async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
"jwt_key": "some-key",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "user-id"
|
||||
"user_id": "user-id",
|
||||
},
|
||||
{
|
||||
"access_token_expiration": 1800.0,
|
||||
@@ -144,7 +139,7 @@ async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
"jwt_key": "some-key",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "system-id"
|
||||
"user_id": "system-id",
|
||||
},
|
||||
{
|
||||
"access_token_expiration": 1800.0,
|
||||
@@ -153,10 +148,10 @@ async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
"id": "hidden-because-no-jwt-id",
|
||||
"last_used_at": "2018-10-03T13:43:19.774712+00:00",
|
||||
"token": "some-token",
|
||||
"user_id": "user-id"
|
||||
"user_id": "user-id",
|
||||
},
|
||||
]
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
store = auth_store.AuthStore(hass)
|
||||
@@ -184,13 +179,13 @@ async def test_loading_all_access_group_data_format(hass, hass_storage):
|
||||
assert owner.groups == [admin_group]
|
||||
assert len(owner.refresh_tokens) == 1
|
||||
owner_token = list(owner.refresh_tokens.values())[0]
|
||||
assert owner_token.id == 'user-token-id'
|
||||
assert owner_token.id == "user-token-id"
|
||||
|
||||
assert system.system_generated is True
|
||||
assert system.groups == []
|
||||
assert len(system.refresh_tokens) == 1
|
||||
system_token = list(system.refresh_tokens.values())[0]
|
||||
assert system_token.id == 'system-token-id'
|
||||
assert system_token.id == "system-token-id"
|
||||
|
||||
|
||||
async def test_loading_empty_data(hass, hass_storage):
|
||||
@@ -223,20 +218,11 @@ async def test_system_groups_store_id_and_name(hass, hass_storage):
|
||||
store = auth_store.AuthStore(hass)
|
||||
await store._async_load()
|
||||
data = store._data_to_save()
|
||||
assert len(data['users']) == 0
|
||||
assert data['groups'] == [
|
||||
{
|
||||
'id': auth_store.GROUP_ID_ADMIN,
|
||||
'name': auth_store.GROUP_NAME_ADMIN,
|
||||
},
|
||||
{
|
||||
'id': auth_store.GROUP_ID_USER,
|
||||
'name': auth_store.GROUP_NAME_USER,
|
||||
},
|
||||
{
|
||||
'id': auth_store.GROUP_ID_READ_ONLY,
|
||||
'name': auth_store.GROUP_NAME_READ_ONLY,
|
||||
},
|
||||
assert len(data["users"]) == 0
|
||||
assert data["groups"] == [
|
||||
{"id": auth_store.GROUP_ID_ADMIN, "name": auth_store.GROUP_NAME_ADMIN},
|
||||
{"id": auth_store.GROUP_ID_USER, "name": auth_store.GROUP_NAME_USER},
|
||||
{"id": auth_store.GROUP_ID_READ_ONLY, "name": auth_store.GROUP_NAME_READ_ONLY},
|
||||
]
|
||||
|
||||
|
||||
@@ -244,16 +230,13 @@ async def test_loading_race_condition(hass):
|
||||
"""Test only one storage load called when concurrent loading occurred ."""
|
||||
store = auth_store.AuthStore(hass)
|
||||
with asynctest.patch(
|
||||
'homeassistant.helpers.entity_registry.async_get_registry',
|
||||
"homeassistant.helpers.entity_registry.async_get_registry"
|
||||
) as mock_ent_registry, asynctest.patch(
|
||||
'homeassistant.helpers.device_registry.async_get_registry',
|
||||
"homeassistant.helpers.device_registry.async_get_registry"
|
||||
) as mock_dev_registry, asynctest.patch(
|
||||
'homeassistant.helpers.storage.Store.async_load',
|
||||
"homeassistant.helpers.storage.Store.async_load"
|
||||
) as mock_load:
|
||||
results = await asyncio.gather(
|
||||
store.async_get_users(),
|
||||
store.async_get_users(),
|
||||
)
|
||||
results = await asyncio.gather(store.async_get_users(), store.async_get_users())
|
||||
|
||||
mock_ent_registry.assert_called_once_with(hass)
|
||||
mock_dev_registry.assert_called_once_with(hass)
|
||||
|
||||
Reference in new issue
Block a user