diff --git a/gazu/client.py b/gazu/client.py index 25fbcf4..51379e7 100644 --- a/gazu/client.py +++ b/gazu/client.py @@ -65,6 +65,10 @@ def refresh_token(self): @property def access_token_has_expired(self): """ Returns: Whether this client's access token needs to be refreshed. """ + # Python 2 is too deprecated to support this feature. (Lack of datetime.timestamp()) + if sys.version_info.major == 2: + return False + if not self.access_token: # No access token is present, refresh only when able with a refresh token. return True if self.refresh_token else False diff --git a/tests/test_client.py b/tests/test_client.py index 178fd76..e904b6b 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -1,3 +1,4 @@ +import sys import datetime import json import random @@ -256,15 +257,23 @@ def test_version(self): self.assertEqual(raw.get_api_version(), "0.2.0") def test_make_auth_token(self): - tokens = {"access_token": jwt.encode( - payload={'exp': (datetime.datetime.now() + datetime.timedelta(days=30)).timestamp()}, - key='secretkey')} + if sys.version_info.major == 2: + tokens = {"access_token": "secretaccesstoken"} + else: + tokens = {"access_token": jwt.encode( + payload={'exp': (datetime.datetime.now() + datetime.timedelta(days=30)).timestamp()}, + key='secretkey')} + raw.set_tokens(tokens) self.assertEqual(raw.make_auth_header(), {"Authorization": "Bearer " + tokens["access_token"], "User-Agent": "CGWire Gazu " + __version__}) def test_access_token_has_expired(self): + # Automatic token refresh is not supported in Python 2. + if sys.version_info.major == 2: + return True + client = raw.KitsuClient(host='http://localhost') test_cases = {'fresh': (datetime.timedelta(days=30), False), 'expired': (datetime.timedelta(days=-1), True)} @@ -285,6 +294,10 @@ def test_access_token_has_expired(self): self.assertEqual(first=client.access_token_has_expired, second=True) def test_automatic_token_refresh(self): + # Automatic token refresh is not supported in Python 2. + if sys.version_info.major == 2: + return True + def encode(timestamp): return jwt.encode(payload={'exp': timestamp}, key='secretkey')