From 7f1efc02850da875d9e7a2a898cbed631bc0050a Mon Sep 17 00:00:00 2001 From: Ward Van Heddeghem Date: Tue, 2 Jan 2024 20:34:24 +0100 Subject: [PATCH] Allow city parameter to be blank/optional --- src/mijnbib/mijnbibliotheek.py | 13 ++++++++++--- tests/test_mijnbibliotheek.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/mijnbib/mijnbibliotheek.py b/src/mijnbib/mijnbibliotheek.py index 97c409a..3e48341 100644 --- a/src/mijnbib/mijnbibliotheek.py +++ b/src/mijnbib/mijnbibliotheek.py @@ -35,13 +35,15 @@ class MijnBibliotheek: BASE_DOMAIN = "bibliotheek.be" - def __init__(self, username: str, password: str, city: str, login_by="form"): + def __init__(self, username: str, password: str, city: str | None = None, login_by="form"): """API for interacting with the mijn.bibliotheek.be website. Args: username: username or email address password: password - city : subdomain for the bibliotheek.be website, typically your city + city : Optional. Subdomain for the bibliotheek.be website, + typically your city. Used to be required, but can be + blank, since January 2024. login_by: Optional. Either `form` (default) or `oauth`. Specfies whether authentication happens via a web-based login form (slow), or via OAauth (2x faster, but more complex flow) @@ -49,7 +51,12 @@ def __init__(self, username: str, password: str, city: str, login_by="form"): self._username = username self._pwd = password - self.BASE_URL = f"https://{city.lower().strip()}.{self.BASE_DOMAIN}" + subdomain = "" + if city is not None and city != "": + subdomain = city.lower().strip() + "." + _log.warning("The 'city' parameter is no longer required. You can leave it blank.") + self.BASE_URL = f"https://{subdomain}{self.BASE_DOMAIN}" + if login_by == "oauth": self._login_handler_class = LoginByOAuth elif login_by == "form": diff --git a/tests/test_mijnbibliotheek.py b/tests/test_mijnbibliotheek.py index 9d17084..167ea13 100644 --- a/tests/test_mijnbibliotheek.py +++ b/tests/test_mijnbibliotheek.py @@ -94,6 +94,13 @@ def test_login_by_form_ok(self, creds_config): assert mb._logged_in + def test_login_by_form_ok_no_city(self, creds_config): + d = creds_config + mb = MijnBibliotheek(d["username"], d["password"], login_by="form") + mb.login() + + assert mb._logged_in + def test_login_by_form_wrong_creds(self, creds_config): d = creds_config mb = MijnBibliotheek(d["username"], "wrongpassword", d["city"], login_by="form") @@ -108,6 +115,13 @@ def test_login_by_oauth_ok(self, creds_config): assert mb._logged_in + def test_login_by_oauth_ok_no_city(self, creds_config): + d = creds_config + mb = MijnBibliotheek(d["username"], d["password"], login_by="oauth") + mb.login() + + assert mb._logged_in + def test_login_by_oauth_wrong_creds(self, creds_config): d = creds_config mb = MijnBibliotheek(d["username"], "wrongpassword", d["city"], login_by="oauth")