1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add check_connection parameter to cloud login methods and handle AlreadyConnectedError (#138699)

This commit is contained in:
Joakim Sørensen
2025-02-19 11:19:03 +01:00
committed by GitHub
parent 38efe94def
commit 618bdba4d3
3 changed files with 65 additions and 8 deletions

View File

@@ -11,7 +11,7 @@ from unittest.mock import AsyncMock, MagicMock, Mock, PropertyMock, patch
import aiohttp
from freezegun.api import FrozenDateTimeFactory
from hass_nabucasa import thingtalk
from hass_nabucasa import AlreadyConnectedError, thingtalk
from hass_nabucasa.auth import (
InvalidTotpCode,
MFARequired,
@@ -373,9 +373,40 @@ async def test_login_view_request_timeout(
"/api/cloud/login", json={"email": "my_username", "password": "my_password"}
)
assert cloud.login.call_args[1]["check_connection"] is False
assert req.status == HTTPStatus.BAD_GATEWAY
async def test_login_view_with_already_existing_connection(
cloud: MagicMock,
setup_cloud: None,
hass_client: ClientSessionGenerator,
) -> None:
"""Test request timeout while trying to log in."""
cloud_client = await hass_client()
cloud.login.side_effect = AlreadyConnectedError(
details={"remote_ip_address": "127.0.0.1", "connected_at": "1"}
)
req = await cloud_client.post(
"/api/cloud/login",
json={
"email": "my_username",
"password": "my_password",
"check_connection": True,
},
)
assert cloud.login.call_args[1]["check_connection"] is True
assert req.status == HTTPStatus.CONFLICT
resp = await req.json()
assert resp == {
"code": "alreadyconnectederror",
"message": '{"remote_ip_address": "127.0.0.1", "connected_at": "1"}',
}
async def test_login_view_invalid_credentials(
cloud: MagicMock,
setup_cloud: None,