mirror of
https://github.com/Electric-Special/ha-core.git
synced 2026-03-21 05:06:13 +01:00
Improve OAuth error handling in configuration flows (#103157)
* Improve OAuth error handling in configuration flows * Update strings for all integrations that use oauth2 config flow * Remove invalid_auth strings * Revert change to release * Revert close change in aiohttp mock
This commit is contained in:
@@ -7,7 +7,11 @@ from unittest import mock
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
from aiohttp import ClientSession
|
||||
from aiohttp.client_exceptions import ClientError, ClientResponseError
|
||||
from aiohttp.client_exceptions import (
|
||||
ClientConnectionError,
|
||||
ClientError,
|
||||
ClientResponseError,
|
||||
)
|
||||
from aiohttp.streams import StreamReader
|
||||
from multidict import CIMultiDict
|
||||
from yarl import URL
|
||||
@@ -53,6 +57,7 @@ class AiohttpClientMocker:
|
||||
exc=None,
|
||||
cookies=None,
|
||||
side_effect=None,
|
||||
closing=None,
|
||||
):
|
||||
"""Mock a request."""
|
||||
if not isinstance(url, RETYPE):
|
||||
@@ -72,6 +77,7 @@ class AiohttpClientMocker:
|
||||
exc=exc,
|
||||
headers=headers,
|
||||
side_effect=side_effect,
|
||||
closing=closing,
|
||||
)
|
||||
)
|
||||
|
||||
@@ -165,6 +171,7 @@ class AiohttpClientMockResponse:
|
||||
exc=None,
|
||||
headers=None,
|
||||
side_effect=None,
|
||||
closing=None,
|
||||
):
|
||||
"""Initialize a fake response."""
|
||||
if json is not None:
|
||||
@@ -178,9 +185,10 @@ class AiohttpClientMockResponse:
|
||||
self.method = method
|
||||
self._url = url
|
||||
self.status = status
|
||||
self.response = response
|
||||
self._response = response
|
||||
self.exc = exc
|
||||
self.side_effect = side_effect
|
||||
self.closing = closing
|
||||
self._headers = CIMultiDict(headers or {})
|
||||
self._cookies = {}
|
||||
|
||||
@@ -272,6 +280,13 @@ class AiohttpClientMockResponse:
|
||||
def close(self):
|
||||
"""Mock close."""
|
||||
|
||||
@property
|
||||
def response(self):
|
||||
"""Property method to expose the response to other read methods."""
|
||||
if self.closing:
|
||||
raise ClientConnectionError("Connection closed")
|
||||
return self._response
|
||||
|
||||
|
||||
@contextmanager
|
||||
def mock_aiohttp_client():
|
||||
|
||||
Reference in New Issue
Block a user