Commit f7969b09 authored by Berker Peksag's avatar Berker Peksag Committed by Tim Graham
Browse files

Fixed #23620 -- Used more specific assertions in the Django test suite.

parent c0c78f1b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -45,10 +45,10 @@ class PermWrapperTests(TestCase):
        """
        perms = PermWrapper(MockUser())
        # Works for modules and full permissions.
        self.assertTrue('mockapp' in perms)
        self.assertFalse('nonexisting' in perms)
        self.assertTrue('mockapp.someperm' in perms)
        self.assertFalse('mockapp.nonexisting' in perms)
        self.assertIn('mockapp', perms)
        self.assertNotIn('nonexisting', perms)
        self.assertIn('mockapp.someperm', perms)
        self.assertNotIn('mockapp.nonexisting', perms)

    def test_permlookupdict_in(self):
        """
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class LoginRequiredTestCase(AuthViewsTestCase):
            login_url = settings.LOGIN_URL
        response = self.client.get(view_url)
        self.assertEqual(response.status_code, 302)
        self.assertTrue(login_url in response.url)
        self.assertIn(login_url, response.url)
        self.login()
        response = self.client.get(view_url)
        self.assertEqual(response.status_code, 200)
+2 −2
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class ModWsgiHandlerTestCase(TransactionTestCase):
        User.objects.create_user('test', 'test@example.com', 'test')

        # User not in database
        self.assertTrue(check_password({}, 'unknown', '') is None)
        self.assertIsNone(check_password({}, 'unknown', ''))

        # Valid user with correct password
        self.assertTrue(check_password({}, 'test', 'test'))
@@ -53,7 +53,7 @@ class ModWsgiHandlerTestCase(TransactionTestCase):
        CustomUser._default_manager.create_user('test@example.com', '1990-01-01', 'test')

        # User not in database
        self.assertTrue(check_password({}, 'unknown', '') is None)
        self.assertIsNone(check_password({}, 'unknown', ''))

        # Valid user with correct password'
        self.assertTrue(check_password({}, 'test@example.com', 'test'))
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ class SignalTestCase(TestCase):
        self.assertEqual(len(self.login_failed), 1)
        self.assertEqual(self.login_failed[0]['username'], 'testclient')
        # verify the password is cleansed
        self.assertTrue('***' in self.login_failed[0]['password'])
        self.assertIn('***', self.login_failed[0]['password'])

        # Like this:
        self.client.login(username='testclient', password='password')
+14 −16
Original line number Diff line number Diff line
@@ -55,13 +55,13 @@ class AuthViewsTestCase(TestCase):
            'username': username,
            'password': password,
        })
        self.assertTrue(SESSION_KEY in self.client.session)
        self.assertIn(SESSION_KEY, self.client.session)
        return response

    def logout(self):
        response = self.client.get('/admin/logout/')
        self.assertEqual(response.status_code, 200)
        self.assertTrue(SESSION_KEY not in self.client.session)
        self.assertNotIn(SESSION_KEY, self.client.session)

    def assertFormError(self, response, error):
        """Assert that error is found in response.context['form'] errors"""
@@ -129,7 +129,7 @@ class PasswordResetTest(AuthViewsTestCase):
        response = self.client.post('/password_reset/', {'email': 'staffmember@example.com'})
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue("http://" in mail.outbox[0].body)
        self.assertIn("http://", mail.outbox[0].body)
        self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)
        # optional multipart text/html email has been added.  Make sure original,
        # default functionality is 100% the same
@@ -148,8 +148,8 @@ class PasswordResetTest(AuthViewsTestCase):
        self.assertTrue(message.is_multipart())
        self.assertEqual(message.get_payload(0).get_content_type(), 'text/plain')
        self.assertEqual(message.get_payload(1).get_content_type(), 'text/html')
        self.assertTrue('<html>' not in message.get_payload(0).get_payload())
        self.assertTrue('<html>' in message.get_payload(1).get_payload())
        self.assertNotIn('<html>', message.get_payload(0).get_payload())
        self.assertIn('<html>', message.get_payload(1).get_payload())

    def test_email_found_custom_from(self):
        "Email is sent if a valid email address is provided for password reset when a custom from_email is provided."
@@ -169,7 +169,7 @@ class PasswordResetTest(AuthViewsTestCase):
            )
        self.assertEqual(response.status_code, 302)
        self.assertEqual(len(mail.outbox), 1)
        self.assertTrue("http://adminsite.com" in mail.outbox[0].body)
        self.assertIn("http://adminsite.com", mail.outbox[0].body)
        self.assertEqual(settings.DEFAULT_FROM_EMAIL, mail.outbox[0].from_email)

    # Skip any 500 handler action (like sending more mail...)
@@ -215,7 +215,7 @@ class PasswordResetTest(AuthViewsTestCase):

    def _read_signup_email(self, email):
        urlmatch = re.search(r"https?://[^/]*(/.*reset/\S*)", email.body)
        self.assertTrue(urlmatch is not None, "No URL found in sent email")
        self.assertIsNotNone(urlmatch, "No URL found in sent email")
        return urlmatch.group(), urlmatch.groups()[0]

    def test_confirm_valid(self):
@@ -346,7 +346,7 @@ class CustomUserPasswordResetTest(AuthViewsTestCase):

    def _read_signup_email(self, email):
        urlmatch = re.search(r"https?://[^/]*(/.*reset/\S*)", email.body)
        self.assertTrue(urlmatch is not None, "No URL found in sent email")
        self.assertIsNotNone(urlmatch, "No URL found in sent email")
        return urlmatch.group(), urlmatch.groups()[0]

    def test_confirm_valid_custom_user(self):
@@ -502,7 +502,7 @@ class LoginTest(AuthViewsTestCase):
                'password': password,
            })
            self.assertEqual(response.status_code, 302)
            self.assertFalse(bad_url in response.url,
            self.assertNotIn(bad_url, response.url,
                             "%s should be blocked" % bad_url)

        # These URLs *should* still pass the security check
@@ -524,8 +524,7 @@ class LoginTest(AuthViewsTestCase):
                'password': password,
            })
            self.assertEqual(response.status_code, 302)
            self.assertTrue(good_url in response.url,
                            "%s should be allowed" % good_url)
            self.assertIn(good_url, response.url, "%s should be allowed" % good_url)

    def test_login_form_contains_request(self):
        # 15198
@@ -683,7 +682,7 @@ class LoginRedirectUrlTest(AuthViewsTestCase):
class LogoutTest(AuthViewsTestCase):

    def confirm_logged_out(self):
        self.assertTrue(SESSION_KEY not in self.client.session)
        self.assertNotIn(SESSION_KEY, self.client.session)

    def test_logout_default(self):
        "Logout without next_page option renders the default template"
@@ -696,7 +695,7 @@ class LogoutTest(AuthViewsTestCase):
        # Bug 14377
        self.login()
        response = self.client.get('/logout/')
        self.assertTrue('site' in response.context)
        self.assertIn('site', response.context)

    def test_logout_with_overridden_redirect_url(self):
        # Bug 11223
@@ -762,7 +761,7 @@ class LogoutTest(AuthViewsTestCase):
            self.login()
            response = self.client.get(nasty_url)
            self.assertEqual(response.status_code, 302)
            self.assertFalse(bad_url in response.url,
            self.assertNotIn(bad_url, response.url,
                             "%s should be blocked" % bad_url)
            self.confirm_logged_out()

@@ -783,8 +782,7 @@ class LogoutTest(AuthViewsTestCase):
            self.login()
            response = self.client.get(safe_url)
            self.assertEqual(response.status_code, 302)
            self.assertTrue(good_url in response.url,
                            "%s should be allowed" % good_url)
            self.assertIn(good_url, response.url, "%s should be allowed" % good_url)
            self.confirm_logged_out()

    def test_logout_preserve_language(self):
Loading