Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed Jan 1, 2024
1 parent 5e5daa3 commit e0d73c0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ytmusicapi/auth/oauth/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e0d73c0

Please sign in to comment.