From f791673537014c00b4b74d6449063e2a66986c1f Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 29 Jan 2020 00:01:18 -0800 Subject: [PATCH] Made token tests in auth_tests use assertIs() rather than assertTrue/False(). --- .../test_password_reset_timeout_days.py | 8 ++++---- tests/auth_tests/test_tokens.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/auth_tests/test_password_reset_timeout_days.py b/tests/auth_tests/test_password_reset_timeout_days.py index db9aa627267..4bd5410f127 100644 --- a/tests/auth_tests/test_password_reset_timeout_days.py +++ b/tests/auth_tests/test_password_reset_timeout_days.py @@ -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): diff --git a/tests/auth_tests/test_tokens.py b/tests/auth_tests/test_tokens.py index 806abd3efef..937fb7f598e 100644 --- a/tests/auth_tests/test_tokens.py +++ b/tests/auth_tests/test_tokens.py @@ -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)