mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed random auth_tests.test_tokens.TokenGeneratorTest.test_timeout failures.
Random failures depended on the current timestamp. Thanks Matthijs Kooijman for the review.
This commit is contained in:
parent
ccf32aca44
commit
8725d04764
@ -39,23 +39,24 @@ class TokenGeneratorTest(TestCase):
|
||||
# Uses a mocked version of PasswordResetTokenGenerator so we can change
|
||||
# the value of 'now'.
|
||||
user = User.objects.create_user('tokentestuser', 'test2@example.com', 'testpw')
|
||||
p0 = PasswordResetTokenGenerator()
|
||||
now = datetime.now()
|
||||
p0 = MockedPasswordResetTokenGenerator(now)
|
||||
tk1 = p0.make_token(user)
|
||||
p1 = MockedPasswordResetTokenGenerator(
|
||||
datetime.now() + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
|
||||
now + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
|
||||
)
|
||||
self.assertIs(p1.check_token(user, tk1), True)
|
||||
p2 = MockedPasswordResetTokenGenerator(
|
||||
datetime.now() + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
|
||||
now + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
|
||||
)
|
||||
self.assertIs(p2.check_token(user, tk1), False)
|
||||
with self.settings(PASSWORD_RESET_TIMEOUT=60 * 60):
|
||||
p3 = MockedPasswordResetTokenGenerator(
|
||||
datetime.now() + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
|
||||
now + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
|
||||
)
|
||||
self.assertIs(p3.check_token(user, tk1), True)
|
||||
p4 = MockedPasswordResetTokenGenerator(
|
||||
datetime.now() + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
|
||||
now + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
|
||||
)
|
||||
self.assertIs(p4.check_token(user, tk1), False)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user