Use gather ipv wait to remove credentials to catch exceptions (#57596)

This commit is contained in:
Paulus Schoutsen 2021-10-13 08:34:57 -07:00 committed by GitHub
parent e130c8671b
commit 0ae1186554
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 10 deletions

View File

@ -286,7 +286,7 @@ class AuthManager:
]
if tasks:
await asyncio.wait(tasks)
await asyncio.gather(*tasks)
await self._store.async_remove_user(user)

View File

@ -17,7 +17,13 @@ from homeassistant.auth.const import MFA_SESSION_EXPIRATION
from homeassistant.core import callback
from homeassistant.util import dt as dt_util
from tests.common import CLIENT_ID, MockUser, ensure_auth_manager_loaded, flush_store
from tests.common import (
CLIENT_ID,
MockUser,
async_capture_events,
ensure_auth_manager_loaded,
flush_store,
)
@pytest.fixture
@ -931,14 +937,7 @@ async def test_enable_mfa_for_user(hass, hass_storage):
async def test_async_remove_user(hass):
"""Test removing a user."""
events = []
@callback
def user_removed(event):
events.append(event)
hass.bus.async_listen("user_removed", user_removed)
events = async_capture_events(hass, "user_removed")
manager = await auth.auth_manager_from_config(
hass,
[
@ -983,6 +982,18 @@ async def test_async_remove_user(hass):
assert events[0].data["user_id"] == user.id
async def test_async_remove_user_fail_if_remove_credential_fails(
hass, hass_admin_user, hass_admin_credential
):
"""Test removing a user."""
await hass.auth.async_link_user(hass_admin_user, hass_admin_credential)
with patch.object(
hass.auth, "async_remove_credentials", side_effect=ValueError
), pytest.raises(ValueError):
await hass.auth.async_remove_user(hass_admin_user)
async def test_new_users(mock_hass):
"""Test newly created users."""
manager = await auth.auth_manager_from_config(