diff --git a/src/mijnbib/login_handlers.py b/src/mijnbib/login_handlers.py index 5b37814..c4e5a4f 100644 --- a/src/mijnbib/login_handlers.py +++ b/src/mijnbib/login_handlers.py @@ -45,6 +45,8 @@ def _log_in(self): _log.debug("Opening login page ... ") response = self._br.open(self._url, timeout=TIMEOUT) html_string_start_page = response.read().decode("utf-8") # type:ignore + # TODO Workaround for mechanize.BrowserStateError: not viewing HTML + self._br._factory.is_html = True self._br.select_form(nr=0) self._br["email"] = self._username self._br["password"] = self._pwd diff --git a/tests/test_mijnbibliotheek.py b/tests/test_mijnbibliotheek.py index 588d084..5fd0304 100644 --- a/tests/test_mijnbibliotheek.py +++ b/tests/test_mijnbibliotheek.py @@ -19,9 +19,16 @@ def creds_config(scope="module"): yield dict(**config.defaults()) +class X(str): + pass + + class FakeMechanizeBrowser: def __init__(self, form_response: str) -> None: self._form_response = form_response.encode("utf8") + # trick for nested prop, from https://stackoverflow.com/a/35190607/50899 + self._factory = X("_factory") + self._factory.is_html = None # can be whatever def __setitem__(self, key, value): pass