Skip to content

Commit

Permalink
Allow city parameter to be blank/optional
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhed committed Jan 2, 2024
1 parent 62627a9 commit 7f1efc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/mijnbib/mijnbibliotheek.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,28 @@
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)
"""
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":
Expand Down
14 changes: 14 additions & 0 deletions tests/test_mijnbibliotheek.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit 7f1efc0

Please sign in to comment.