Skip to content

Commit

Permalink
Fixed tests for 3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jun 2, 2013
1 parent f913bd2 commit 9ef8a00
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions itsdangerous.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
from itertools import izip
text_type = unicode
int_to_byte = chr
number_types = (int, long, float)
else:
from functools import reduce
izip = zip
text_type = str
int_to_byte = operator.methodcaller('to_bytes', 1, 'big')
number_types = (int, float)


try:
Expand Down Expand Up @@ -739,7 +741,7 @@ def loads(self, s, salt=None, return_header=False):
if 'exp' not in header:
raise BadSignature('Missing expiry date', payload=payload)

if not (isinstance(header['exp'], (int, long, float))
if not (isinstance(header['exp'], number_types)
and header['exp'] > 0):
raise BadSignature('expiry date is not an IntDate',
payload=payload)
Expand All @@ -763,8 +765,8 @@ def dumps(self, obj, salt=None, header_fields=None):

def get_issue_date(self, header):
rv = header.get('iat')
if isinstance(rv, (int, long)):
return datetime.utcfromtimestamp(rv)
if isinstance(rv, number_types):
return datetime.utcfromtimestamp(int(rv))

def now(self):
return int(time.time())
Expand Down
4 changes: 2 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ class TimedJSONWebSignatureSerializerTest(unittest.TestCase):
def test_token_contains_issue_date_and_expiry_time(self):
s = self.serializer_class('secret')
result = s.dumps({'es': 'geht'})
self.assert_('exp' in s.loads(result, return_header=True)[1])
self.assert_('iat' in s.loads(result, return_header=True)[1])
self.assertTrue('exp' in s.loads(result, return_header=True)[1])
self.assertTrue('iat' in s.loads(result, return_header=True)[1])

def test_token_expires_at_given_expiry_time(self):
s = self.serializer_class('secret')
Expand Down

0 comments on commit 9ef8a00

Please sign in to comment.