Fix timestamps computing in tokens

The timestamp of timezone-aware datetimes was offset by the value of their timezone.
This commit is contained in:
Brice Gelineau 2016-11-30 15:22:58 +01:00
parent 11ef97fdbb
commit 975eb0163f
3 changed files with 40 additions and 7 deletions

View file

@ -1,6 +1,10 @@
from django.test import TestCase
import datetime
from oidc_provider.lib.utils.common import get_issuer
from django.test import TestCase
from django.utils import timezone
from django.utils import six
from oidc_provider.lib.utils.common import get_issuer, to_timestamp
class Request(object):
@ -42,3 +46,13 @@ class CommonTest(TestCase):
self.assertEqual(get_issuer(site_url='http://127.0.0.1:9000',
request=request),
'http://127.0.0.1:9000/openid')
def test_to_timestamp(self):
if not six.PY2:
naive_dt = datetime.datetime.now()
self.assertEqual(to_timestamp(naive_dt), int(naive_dt.timestamp()))
aware_dt = datetime.datetime(2016, 3, 2, 14, 2, 6, 123, timezone.utc)
self.assertEqual(to_timestamp(aware_dt), 1456927326)
if not six.PY2:
self.assertEqual(to_timestamp(aware_dt), int(aware_dt.timestamp()))