Made token tests in auth_tests use assertIs() rather than assertTrue/False().

This commit is contained in:
Jon Dufresne 2020-01-29 00:01:18 -08:00 committed by GitHub
parent a69b6e006b
commit f791673537
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 12 deletions

View File

@ -31,15 +31,15 @@ class DeprecationTests(TestCase):
p0 = PasswordResetTokenGenerator()
tk1 = p0.make_token(user)
p1 = Mocked(datetime.now() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS))
self.assertTrue(p1.check_token(user, tk1))
self.assertIs(p1.check_token(user, tk1), True)
p2 = Mocked(datetime.now() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
self.assertFalse(p2.check_token(user, tk1))
self.assertIs(p2.check_token(user, tk1), False)
with self.settings(PASSWORD_RESET_TIMEOUT_DAYS=1):
self.assertEqual(settings.PASSWORD_RESET_TIMEOUT, 60 * 60 * 24)
p3 = Mocked(datetime.now() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS))
self.assertTrue(p3.check_token(user, tk1))
self.assertIs(p3.check_token(user, tk1), True)
p4 = Mocked(datetime.now() + timedelta(settings.PASSWORD_RESET_TIMEOUT_DAYS + 1))
self.assertFalse(p4.check_token(user, tk1))
self.assertIs(p4.check_token(user, tk1), False)
def test_override_settings_warning(self):
with self.assertRaisesMessage(RemovedInDjango40Warning, self.msg):

View File

@ -20,7 +20,7 @@ class TokenGeneratorTest(TestCase):
user = User.objects.create_user('tokentestuser', 'test2@example.com', 'testpw')
p0 = PasswordResetTokenGenerator()
tk1 = p0.make_token(user)
self.assertTrue(p0.check_token(user, tk1))
self.assertIs(p0.check_token(user, tk1), True)
def test_10265(self):
"""
@ -44,20 +44,20 @@ class TokenGeneratorTest(TestCase):
p1 = MockedPasswordResetTokenGenerator(
datetime.now() + timedelta(seconds=settings.PASSWORD_RESET_TIMEOUT)
)
self.assertTrue(p1.check_token(user, tk1))
self.assertIs(p1.check_token(user, tk1), True)
p2 = MockedPasswordResetTokenGenerator(
datetime.now() + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
)
self.assertFalse(p2.check_token(user, tk1))
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)
)
self.assertTrue(p3.check_token(user, tk1))
self.assertIs(p3.check_token(user, tk1), True)
p4 = MockedPasswordResetTokenGenerator(
datetime.now() + timedelta(seconds=(settings.PASSWORD_RESET_TIMEOUT + 1))
)
self.assertFalse(p4.check_token(user, tk1))
self.assertIs(p4.check_token(user, tk1), False)
def test_check_token_with_nonexistent_token_and_user(self):
user = User.objects.create_user('tokentestuser', 'test2@example.com', 'testpw')
@ -77,12 +77,12 @@ class TokenGeneratorTest(TestCase):
p0 = PasswordResetTokenGenerator()
p0.secret = new_secret
tk0 = p0.make_token(user)
self.assertTrue(p0.check_token(user, tk0))
self.assertIs(p0.check_token(user, tk0), True)
# Create and check a token with the default secret.
p1 = PasswordResetTokenGenerator()
self.assertEqual(p1.secret, settings.SECRET_KEY)
self.assertNotEqual(p1.secret, new_secret)
tk1 = p1.make_token(user)
# Tokens created with a different secret don't validate.
self.assertFalse(p0.check_token(user, tk1))
self.assertFalse(p1.check_token(user, tk0))
self.assertIs(p0.check_token(user, tk1), False)
self.assertIs(p1.check_token(user, tk0), False)