From 011f21b4faddf40fdb84f2adbb75fc4c3fb94ce8 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Tue, 6 Jan 2015 08:48:01 +0100 Subject: [PATCH] Used None-related assertions in CSRF tests Thanks Markus Holtermann for spotting this. --- tests/csrf_tests/tests.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py index f22cddb58e..29d93389f3 100644 --- a/tests/csrf_tests/tests.py +++ b/tests/csrf_tests/tests.py @@ -166,7 +166,7 @@ class CsrfViewMiddlewareTest(TestCase): """ req = self._get_POST_request_with_token() req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) def test_process_request_csrf_cookie_no_token_exempt_view(self): """ @@ -175,7 +175,7 @@ class CsrfViewMiddlewareTest(TestCase): """ req = self._get_POST_csrf_cookie_request() req2 = CsrfViewMiddleware().process_view(req, csrf_exempt(post_form_view), (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) def test_csrf_token_in_header(self): """ @@ -184,7 +184,7 @@ class CsrfViewMiddlewareTest(TestCase): req = self._get_POST_csrf_cookie_request() req.META['HTTP_X_CSRFTOKEN'] = self._csrf_id req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) def test_put_and_delete_rejected(self): """ @@ -209,13 +209,13 @@ class CsrfViewMiddlewareTest(TestCase): req.method = 'PUT' req.META['HTTP_X_CSRFTOKEN'] = self._csrf_id req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) req = self._get_GET_csrf_cookie_request() req.method = 'DELETE' req.META['HTTP_X_CSRFTOKEN'] = self._csrf_id req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) # Tests for the template tag method def test_token_node_no_csrf_cookie(self): @@ -285,7 +285,7 @@ class CsrfViewMiddlewareTest(TestCase): req.META['HTTP_HOST'] = 'www.example.com' req.META['HTTP_REFERER'] = 'https://www.evil.org/somepage' req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertNotEqual(None, req2) + self.assertIsNotNone(req2) self.assertEqual(403, req2.status_code) @override_settings(ALLOWED_HOSTS=['www.example.com']) @@ -298,12 +298,12 @@ class CsrfViewMiddlewareTest(TestCase): req.META['HTTP_HOST'] = 'www.example.com' req.META['HTTP_REFERER'] = 'http://http://www.example.com/' req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertNotEqual(None, req2) + self.assertIsNotNone(req2) self.assertEqual(403, req2.status_code) # Non-ASCII req.META['HTTP_REFERER'] = b'\xd8B\xf6I\xdf' req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertNotEqual(None, req2) + self.assertIsNotNone(req2) self.assertEqual(403, req2.status_code) @override_settings(ALLOWED_HOSTS=['www.example.com']) @@ -316,7 +316,7 @@ class CsrfViewMiddlewareTest(TestCase): req.META['HTTP_HOST'] = 'www.example.com' req.META['HTTP_REFERER'] = 'https://www.example.com/somepage' req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) @override_settings(ALLOWED_HOSTS=['www.example.com']) def test_https_good_referer_2(self): @@ -330,7 +330,7 @@ class CsrfViewMiddlewareTest(TestCase): req.META['HTTP_HOST'] = 'www.example.com' req.META['HTTP_REFERER'] = 'https://www.example.com' req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(None, req2) + self.assertIsNone(req2) def test_ensures_csrf_cookie_no_middleware(self): """ @@ -469,7 +469,7 @@ class CsrfViewMiddlewareTest(TestCase): req = CsrfPostRequest(token, raise_error=False) resp = CsrfViewMiddleware().process_view(req, post_form_view, (), {}) - self.assertEqual(resp, None) + self.assertIsNone(resp) req = CsrfPostRequest(token, raise_error=True) resp = CsrfViewMiddleware().process_view(req, post_form_view, (), {})