From c3116e36e4624d7054d1c403fc72af12533528ee Mon Sep 17 00:00:00 2001 From: ttuovinen Date: Wed, 7 Feb 2024 17:11:21 +0200 Subject: [PATCH] Fix a bug in authentication --- api/ekirjasto_authentication.py | 7 ++++--- tests/api/finland/test_ekirjasto.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/ekirjasto_authentication.py b/api/ekirjasto_authentication.py index aa549712a..0034a23f1 100644 --- a/api/ekirjasto_authentication.py +++ b/api/ekirjasto_authentication.py @@ -610,7 +610,7 @@ def local_patron_lookup( def ekirjasto_authenticate( self, _db: Session, ekirjasto_token: str - ) -> tuple[PatronData | Patron | ProblemDetail | None, bool]: + ) -> tuple[Patron | ProblemDetail | None, bool]: """Authenticate patron with remote ekirjasto API and if necessary, create authenticated patron if not in database. @@ -627,10 +627,11 @@ def ekirjasto_authenticate( if isinstance(auth_result, PatronData): # We didn't find the patron, but authentication to external truth was # successful, so we create a new patron with the information we have. - patron, is_new = auth_result.get_or_create_patron( + new_patron, is_new = auth_result.get_or_create_patron( _db, self.library_id, analytics=self.analytics ) - patron.last_external_sync = utc_now() + new_patron.last_external_sync = utc_now() + return new_patron, is_new return auth_result, is_new diff --git a/tests/api/finland/test_ekirjasto.py b/tests/api/finland/test_ekirjasto.py index 9441a29df..8c981b58c 100644 --- a/tests/api/finland/test_ekirjasto.py +++ b/tests/api/finland/test_ekirjasto.py @@ -687,7 +687,7 @@ def test_authenticated_patron_delegate_token_expired( assert patron is None - def test_authenticated_patron_ekirjasto_token_invald( + def test_authenticated_patron_ekirjasto_token_invalid( self, create_provider: Callable[..., MockEkirjastoAuthenticationAPI], controller_fixture: ControllerFixture,