Skip to content

Commit

Permalink
Add MyBMWCaptchaMissingError
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed Nov 1, 2024
1 parent 9a59e72 commit bf24684
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bimmer_connected/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
}
Expand Down
4 changes: 4 additions & 0 deletions bimmer_connected/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
10 changes: 8 additions & 2 deletions bimmer_connected/tests/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit bf24684

Please sign in to comment.