Skip to content

Commit 5554686

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into dev
2 parents 267909f + 630edd8 commit 5554686

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

blinkpy/auth.py

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ async def login(self, login_url=LOGIN_ENDPOINT, refresh=False):
114114
try:
115115
if response.status == 200:
116116
return await response.json()
117+
if response.status == 401:
118+
_LOGGER.error(
119+
"Unable to refresh token. "
120+
"Invalid refresh token or invalid credentials."
121+
)
122+
raise UnauthorizedError
117123
if response.status == 412:
118124
raise BlinkTwoFARequiredError
119125
raise LoginError
@@ -263,23 +269,6 @@ async def query(
263269
code,
264270
reason,
265271
)
266-
except UnauthorizedError:
267-
try:
268-
if not is_retry:
269-
await self.refresh_tokens()
270-
return await self.query(
271-
url=url,
272-
data=data,
273-
headers=self.header,
274-
reqtype=reqtype,
275-
stream=stream,
276-
json_resp=json_resp,
277-
is_retry=True,
278-
timeout=timeout,
279-
)
280-
_LOGGER.error("Unable to access %s after token refresh.", url)
281-
except TokenRefreshFailed:
282-
_LOGGER.error("Unable to refresh token.")
283272
return None
284273

285274

tests/test_auth.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,16 @@ async def test_query_retry(self): # , mock_refresh, mock_validate):
225225
@mock.patch("blinkpy.auth.Auth.validate_response")
226226
@mock.patch("blinkpy.auth.Auth.refresh_tokens")
227227
async def test_query_retry_failed(self, mock_refresh, mock_validate):
228-
"""Check handling of failed retry request."""
228+
"""Check authorization failure is thrown."""
229229
self.auth.session = MockSession()
230230
mock_validate.side_effect = [
231231
BlinkBadResponse,
232232
UnauthorizedError,
233-
TokenRefreshFailed,
234233
]
235234
mock_refresh.return_value = True
236235
self.assertEqual(await self.auth.query(url="http://example.com"), None)
237-
self.assertEqual(await self.auth.query(url="http://example.com"), None)
236+
with self.assertRaises(UnauthorizedError):
237+
await self.auth.query(url="http://example.com")
238238

239239
@mock.patch("blinkpy.auth.Auth.validate_response")
240240
async def test_query(self, mock_validate):
@@ -250,8 +250,8 @@ async def test_query(self, mock_validate):
250250
self.assertIsNone(await self.auth.query("URL", "data", "headers", "post"))
251251

252252
mock_validate.side_effect = UnauthorizedError
253-
self.auth.refresh_tokens = mock.AsyncMock()
254-
self.assertIsNone(await self.auth.query("URL", "data", "headers", "post"))
253+
with self.assertRaises(UnauthorizedError):
254+
await self.auth.query("URL", "data", "headers", "post")
255255

256256
@mock.patch("blinkpy.auth.Auth.validate_response")
257257
@mock.patch("blinkpy.auth.Auth.validate_login")

0 commit comments

Comments
 (0)