diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py index b8a16a8c17..ea550f955d 100644 --- a/django/contrib/auth/tests/views.py +++ b/django/contrib/auth/tests/views.py @@ -114,8 +114,7 @@ class PasswordResetTest(AuthViewsTestCase): url, path = self._test_confirm_start() response = self.client.get(path) # redirect to a 'complete' page: - self.assertEqual(response.status_code, 200) - self.assertTrue("Please enter your new password" in response.content) + self.assertContains(response, "Please enter your new password") def test_confirm_invalid(self): url, path = self._test_confirm_start() @@ -124,20 +123,17 @@ class PasswordResetTest(AuthViewsTestCase): path = path[:-5] + ("0" * 4) + path[-1] response = self.client.get(path) - self.assertEqual(response.status_code, 200) - self.assertTrue("The password reset link was invalid" in response.content) + self.assertContains(response, "The password reset link was invalid") def test_confirm_invalid_user(self): # Ensure that we get a 200 response for a non-existant user, not a 404 response = self.client.get('/reset/123456-1-1/') - self.assertEqual(response.status_code, 200) - self.assertTrue("The password reset link was invalid" in response.content) + self.assertContains(response, "The password reset link was invalid") def test_confirm_overflow_user(self): # Ensure that we get a 200 response for a base36 user id that overflows int response = self.client.get('/reset/zzzzzzzzzzzzz-1-1/') - self.assertEqual(response.status_code, 200) - self.assertTrue("The password reset link was invalid" in response.content) + self.assertContains(response, "The password reset link was invalid") def test_confirm_invalid_post(self): # Same as test_confirm_invalid, but trying @@ -165,14 +161,12 @@ class PasswordResetTest(AuthViewsTestCase): # Check we can't use the link again response = self.client.get(path) - self.assertEqual(response.status_code, 200) - self.assertTrue("The password reset link was invalid" in response.content) + self.assertContains(response, "The password reset link was invalid") def test_confirm_different_passwords(self): url, path = self._test_confirm_start() response = self.client.post(path, {'new_password1': 'anewpassword', 'new_password2': 'x'}) - self.assertEqual(response.status_code, 200) self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch']) @@ -183,7 +177,6 @@ class ChangePasswordTest(AuthViewsTestCase): 'username': 'testclient', 'password': password, }) - self.assertEqual(response.status_code, 200) self.assertContainsEscaped(response, AuthenticationForm.error_messages['invalid_login']) def logout(self): @@ -196,7 +189,6 @@ class ChangePasswordTest(AuthViewsTestCase): 'new_password1': 'password1', 'new_password2': 'password1', }) - self.assertEqual(response.status_code, 200) self.assertContainsEscaped(response, PasswordChangeForm.error_messages['password_incorrect']) def test_password_change_fails_with_mismatched_passwords(self): @@ -206,7 +198,6 @@ class ChangePasswordTest(AuthViewsTestCase): 'new_password1': 'password1', 'new_password2': 'donuts', }) - self.assertEqual(response.status_code, 200) self.assertContainsEscaped(response, SetPasswordForm.error_messages['password_mismatch']) def test_password_change_succeeds(self): @@ -363,8 +354,7 @@ class LogoutTest(AuthViewsTestCase): "Logout without next_page option renders the default template" self.login() response = self.client.get('/logout/') - self.assertEqual(200, response.status_code) - self.assertTrue('Logged out' in response.content) + self.assertContains(response, 'Logged out') self.confirm_logged_out() def test_14377(self): diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index df872cd190..02666cef52 100644 --- a/tests/modeltests/test_client/models.py +++ b/tests/modeltests/test_client/models.py @@ -75,7 +75,7 @@ class ClientTest(TestCase): self.assertEqual(response.status_code, 200) self.assertEqual(response.context['data'], '37') self.assertEqual(response.templates[0].name, 'POST Template') - self.assertTrue('Data received' in response.content) + self.assertContains(response, 'Data received') def test_response_headers(self): "Check the value of HTTP headers returned in a response" diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py index 7a0a3bf868..55a2639028 100644 --- a/tests/regressiontests/admin_views/tests.py +++ b/tests/regressiontests/admin_views/tests.py @@ -92,9 +92,8 @@ class AdminViewBasicTest(TestCase): def testAddWithGETArgs(self): response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'}) self.assertEqual(response.status_code, 200) - self.assertTrue( - 'value="My Section"' in response.content, - "Couldn't find an input with the right value in the response." + self.assertContains(response, 'value="My Section"', + msg_prefix="Couldn't find an input with the right value in the response" ) def testBasicEditGet(self): @@ -393,13 +392,11 @@ class AdminViewBasicTest(TestCase): """ response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit) self.assertEqual(response.status_code, 200) - self.assertTrue( - '