From 3f1bdf776eefd3fa7e91d2d1257eb83d3403dec9 Mon Sep 17 00:00:00 2001 From: Chris Rose Date: Thu, 2 Jan 2025 12:57:12 -0800 Subject: [PATCH 1/2] Modify the dummy tests to be timezone-safe The dummy tests were failing on my non-UTC development machine, because the timestamps were generated with mktime(), which uses the locale settings from the host. Changing this to use the timezone-aware `now` sorted it. --- social_core/storage.py | 5 +++-- social_core/tests/backends/test_dummy.py | 4 +--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/social_core/storage.py b/social_core/storage.py index ee3019ff8..680ab2054 100644 --- a/social_core/storage.py +++ b/social_core/storage.py @@ -71,9 +71,10 @@ def expiration_timedelta(self): now = datetime.now(timezone.utc) # Detect if expires is a timestamp - if expires > time.mktime(now.timetuple()): + if expires > now.timestamp(): # expires is a datetime, return the remaining difference - return datetime.fromtimestamp(expires, tz=timezone.utc) - now + expiry_time = datetime.fromtimestamp(expires, tz=timezone.utc) + return expiry_time - now else: # expires is the time to live seconds since creation, # check against auth_time if present, otherwise return diff --git a/social_core/tests/backends/test_dummy.py b/social_core/tests/backends/test_dummy.py index cb16f5094..70f41c731 100644 --- a/social_core/tests/backends/test_dummy.py +++ b/social_core/tests/backends/test_dummy.py @@ -121,9 +121,7 @@ class ExpirationTimeTest(DummyOAuth2Test): "first_name": "Foo", "last_name": "Bar", "email": "foo@bar.com", - "expires": time.mktime( - (datetime.datetime.now(datetime.timezone.utc) + DELTA).timetuple() - ), + "expires": (datetime.datetime.now() + DELTA).timestamp(), } ) From 4f1507ab3cba7f62519105bb5dab16753ec53fe2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:41:44 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- social_core/storage.py | 1 - social_core/tests/backends/test_dummy.py | 1 - 2 files changed, 2 deletions(-) diff --git a/social_core/storage.py b/social_core/storage.py index 680ab2054..392b98003 100644 --- a/social_core/storage.py +++ b/social_core/storage.py @@ -2,7 +2,6 @@ import base64 import re -import time import uuid import warnings from datetime import datetime, timedelta, timezone diff --git a/social_core/tests/backends/test_dummy.py b/social_core/tests/backends/test_dummy.py index 70f41c731..49e59923a 100644 --- a/social_core/tests/backends/test_dummy.py +++ b/social_core/tests/backends/test_dummy.py @@ -1,6 +1,5 @@ import datetime import json -import time from httpretty import HTTPretty