1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +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:
Mariusz Felisiak 2020-03-12 10:56:38 +01:00 committed by GitHub
parent ccf32aca44
commit 8725d04764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)