From bf246840ca6dbb0bb6884cecc04cdacaa13ca967 Mon Sep 17 00:00:00 2001 From: Richard <42204099+rikroe@users.noreply.github.com> Date: Fri, 1 Nov 2024 17:08:41 +0100 Subject: [PATCH] Add MyBMWCaptchaMissingError --- bimmer_connected/api/authentication.py | 4 ++-- bimmer_connected/models.py | 4 ++++ bimmer_connected/tests/test_account.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bimmer_connected/api/authentication.py b/bimmer_connected/api/authentication.py index 882db9f..55037e3 100644 --- a/bimmer_connected/api/authentication.py +++ b/bimmer_connected/api/authentication.py @@ -34,7 +34,7 @@ OAUTH_CONFIG_URL, X_USER_AGENT, ) -from bimmer_connected.models import MyBMWAPIError +from bimmer_connected.models import MyBMWAPIError, MyBMWCaptchaMissingError EXPIRES_AT_OFFSET = datetime.timedelta(seconds=HTTPX_TIMEOUT * 2) @@ -188,7 +188,7 @@ async def _login_row_na(self): authenticate_headers = {} if self.region == Regions.NORTH_AMERICA: if not self.hcaptcha_token: - raise MyBMWAPIError("Missing hCaptcha token for North America login") + raise MyBMWCaptchaMissingError("Missing hCaptcha token for North America login") authenticate_headers = { "hcaptchatoken": self.hcaptcha_token, } diff --git a/bimmer_connected/models.py b/bimmer_connected/models.py index b0b78b6..d2f8bf7 100644 --- a/bimmer_connected/models.py +++ b/bimmer_connected/models.py @@ -201,6 +201,10 @@ class MyBMWAuthError(MyBMWAPIError): """Auth-related error from BMW API (HTTP status codes 401 and 403).""" +class MyBMWCaptchaMissingError(MyBMWAPIError): + """Indicate missing captcha for login.""" + + class MyBMWQuotaError(MyBMWAPIError): """Quota exceeded on BMW API.""" diff --git a/bimmer_connected/tests/test_account.py b/bimmer_connected/tests/test_account.py index 784976b..69b73de 100644 --- a/bimmer_connected/tests/test_account.py +++ b/bimmer_connected/tests/test_account.py @@ -14,7 +14,13 @@ from bimmer_connected.api.client import MyBMWClient from bimmer_connected.api.regions import get_region_from_name from bimmer_connected.const import ATTR_CAPABILITIES, VEHICLES_URL, CarBrands, Regions -from bimmer_connected.models import GPSPosition, MyBMWAPIError, MyBMWAuthError, MyBMWQuotaError +from bimmer_connected.models import ( + GPSPosition, + MyBMWAPIError, + MyBMWAuthError, + MyBMWCaptchaMissingError, + MyBMWQuotaError, +) from . import ( RESPONSE_DIR, @@ -50,7 +56,7 @@ async def test_login_na(bmw_fixture: respx.Router): @pytest.mark.asyncio async def test_login_na_without_hcaptcha(bmw_fixture: respx.Router): """Test the login flow.""" - with pytest.raises(MyBMWAPIError): + with pytest.raises(MyBMWCaptchaMissingError): account = MyBMWAccount(TEST_USERNAME, TEST_PASSWORD, Regions.NORTH_AMERICA) await account.get_vehicles()