diff --git a/custom_components/danish_libraries/api.py b/custom_components/danish_libraries/api.py index b4c3b7b..3860a1f 100644 --- a/custom_components/danish_libraries/api.py +++ b/custom_components/danish_libraries/api.py @@ -120,7 +120,9 @@ async def authenticate(self): token_text = token_response.text self.user_token = re.search(r"\"user\",\s*\"(.*?)\"", token_text).group(1) - self.library_token = re.search(r"\"library\",\s*\"(.*?)\"", token_text).group(1) + self.library_token = re.search( + r"\"library\",\s*\"(.*?)\"", token_text + ).group(1) except httpx.HTTPStatusError as e: if e.response.status_code >= 500: LOGGER.debug(e, exc_info=True) diff --git a/tests/test_api.py b/tests/test_api.py index 86932a1..5bd3541 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -10,56 +10,69 @@ import pytest from custom_components.danish_libraries.api import Library -from custom_components.danish_libraries.models import EreolenLoan, EreolenReservation, LibraryConfig, Loan, ProfileInfo, Reservation +from custom_components.danish_libraries.models import ( + EreolenLoan, + EreolenReservation, + LibraryConfig, + Loan, + ProfileInfo, + Reservation, +) dotenv.load_dotenv() + async def test_auth(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) await lib.authenticate() assert lib.user_bearer_token != None + async def test_loans(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) loans = await lib.get_loans() assert loans != None assert len(loans) > 0 assert isinstance(loans[0], Loan) + async def test_reservations(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) reservations = await lib.get_reservations() assert reservations != None assert len(reservations) > 0 assert isinstance(reservations[0], Reservation) + async def test_profile(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) profile = await lib.get_profile_info() assert profile != None assert isinstance(profile, ProfileInfo) assert "gmail.com" in profile.email_address + async def test_ereolen_loans(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) loans = await lib.get_ereolen_loans() assert loans != None assert len(loans) > 0 assert isinstance(loans[0], EreolenLoan) + async def test_ereolen_reservations(): - user = os.getenv('LIBRARY_USER_ID') - pin = os.getenv('LIBRARY_PIN') + user = os.getenv("LIBRARY_USER_ID") + pin = os.getenv("LIBRARY_PIN") lib = Library("Aalborg", user, pin) reservations = await lib.get_ereolen_reservations() assert reservations != None