diff --git a/aiogoogle/auth/utils.py b/aiogoogle/auth/utils.py index 3f15c92..be0f2cd 100644 --- a/aiogoogle/auth/utils.py +++ b/aiogoogle/auth/utils.py @@ -31,8 +31,9 @@ def _is_expired(expires_at): expires_at = _parse_isoformat(expires_at) else: expires_at = datetime.datetime.fromisoformat(expires_at) - utc_now = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) - if utc_now >= expires_at: + if expires_at.tzinfo is None: + expires_at = expires_at.replace(tzinfo=datetime.timezone.utc) + if datetime.datetime.now(datetime.timezone.utc) >= expires_at: return True else: return False diff --git a/tests/test_units/test_auth/test_utils.py b/tests/test_units/test_auth/test_utils.py index a7c910c..cd250c3 100644 --- a/tests/test_units/test_auth/test_utils.py +++ b/tests/test_units/test_auth/test_utils.py @@ -1,6 +1,6 @@ import datetime -from aiogoogle.auth.utils import _get_expires_at +from aiogoogle.auth.utils import _get_expires_at, _is_expired def test_get_expires_at(): @@ -9,3 +9,11 @@ def test_get_expires_at(): assert exp_dt.tzinfo is None delta = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) - exp_dt assert -1 < delta.seconds < 1 + + +def test_is_expired(): + # correctness not tested, but none of these should raise an exception + _is_expired("2024-10-01T14:26:21") + _is_expired("2024-10-01T14:26:21Z") + _is_expired(datetime.datetime.now()) + _is_expired(datetime.datetime.now(datetime.timezone.utc))