From e0d73c02b22132a030398f6472b44d6f34df97e7 Mon Sep 17 00:00:00 2001 From: sigma67 Date: Mon, 1 Jan 2024 14:21:53 +0100 Subject: [PATCH] fix tests --- tests/test.py | 13 ++++++------- ytmusicapi/auth/oauth/token.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/tests/test.py b/tests/test.py index 9ed20d8e..f25836b4 100644 --- a/tests/test.py +++ b/tests/test.py @@ -80,7 +80,6 @@ def test_setup_oauth(self, session_mock, json_mock): ############### # OAUTH ############### - # 000 so test is run first and fresh token is available to others def test_oauth_tokens(self): # ensure instance initialized token self.assertIsNotNone(self.yt_oauth._token) @@ -90,16 +89,16 @@ def test_oauth_tokens(self): first_json = json.load(f) # pull reference values from underlying token - first_token = self.yt_oauth._token.token.access_token - first_expire = self.yt_oauth._token.token.expires_at + first_token = self.yt_oauth._token.access_token + first_expire = self.yt_oauth._token.expires_at # make token expire - self.yt_oauth._token.token._expires_at = time.time() + self.yt_oauth._token.expires_at = time.time() # check - self.assertTrue(self.yt_oauth._token.token.is_expiring) + self.assertTrue(self.yt_oauth._token.is_expiring) # pull new values, assuming token will be refreshed on access second_token = self.yt_oauth._token.access_token - second_expire = self.yt_oauth._token.token.expires_at - second_token_inner = self.yt_oauth._token.token.access_token + second_expire = self.yt_oauth._token.expires_at + second_token_inner = self.yt_oauth._token.access_token # check it was refreshed self.assertNotEqual(first_token, second_token) # check expiration timestamps to confirm diff --git a/ytmusicapi/auth/oauth/token.py b/ytmusicapi/auth/oauth/token.py index 563c3fff..35804aa8 100644 --- a/ytmusicapi/auth/oauth/token.py +++ b/ytmusicapi/auth/oauth/token.py @@ -100,7 +100,7 @@ class RefreshingToken(OAuthToken): #: protected/property attribute enables auto writing token values to new file location via setter _local_cache: Optional[str] = None - def __getattr__(self, item): + def __getattribute__(self, item): """access token setter to auto-refresh if it is expiring""" if item == "access_token" and self.is_expiring: fresh = self.credentials.refresh_token(self.refresh_token)