Skip to content

Commit 089e262

Browse files
nijeloffbyone
andauthored
Modify the dummy tests to be timezone-safe (#953)
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. Co-authored-by: Chris Rose <[email protected]>
1 parent c9e4b6b commit 089e262

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

social_core/storage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import base64
44
import re
5-
import time
65
import uuid
76
import warnings
87
from datetime import datetime, timedelta, timezone
@@ -71,9 +70,10 @@ def expiration_timedelta(self):
7170
now = datetime.now(timezone.utc)
7271

7372
# Detect if expires is a timestamp
74-
if expires > time.mktime(now.timetuple()):
73+
if expires > now.timestamp():
7574
# expires is a datetime, return the remaining difference
76-
return datetime.fromtimestamp(expires, tz=timezone.utc) - now
75+
expiry_time = datetime.fromtimestamp(expires, tz=timezone.utc)
76+
return expiry_time - now
7777
else:
7878
# expires is the time to live seconds since creation,
7979
# check against auth_time if present, otherwise return

social_core/tests/backends/test_dummy.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import datetime
22
import json
3-
import time
43

54
from httpretty import HTTPretty
65

@@ -121,9 +120,7 @@ class ExpirationTimeTest(DummyOAuth2Test):
121120
"first_name": "Foo",
122121
"last_name": "Bar",
123122
"email": "[email protected]",
124-
"expires": time.mktime(
125-
(datetime.datetime.now(datetime.timezone.utc) + DELTA).timetuple()
126-
),
123+
"expires": (datetime.datetime.now() + DELTA).timestamp(),
127124
}
128125
)
129126

0 commit comments

Comments
 (0)