aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAymeric Augustin2013-11-22 19:55:11 +0100
committerAymeric Augustin2013-11-22 20:42:21 +0100
commitf4666321048d04514a4900b7301d61a918082bfd (patch)
treefbbb87f42412814080ab9a2f3b87e997c4e4c146 /tests
parentc5e6a8550ea744df886a93b2749c7a33571ca11c (diff)
downloaddjango-debug-toolbar-f4666321048d04514a4900b7301d61a918082bfd.tar.bz2
Add tests for redirects panel.
Also simplify the implementation.
Diffstat (limited to 'tests')
-rw-r--r--tests/panels/test_profiling.py1
-rw-r--r--tests/panels/test_redirects.py46
-rw-r--r--tests/tests.py1
3 files changed, 47 insertions, 1 deletions
diff --git a/tests/panels/test_profiling.py b/tests/panels/test_profiling.py
index 4e01073..f6bb7d3 100644
--- a/tests/panels/test_profiling.py
+++ b/tests/panels/test_profiling.py
@@ -43,7 +43,6 @@ class ProfilingPanelTestCase(BaseTestCase):
profiling.DJ_PROFILE_USE_LINE_PROFILER = _use_line_profiler
-
@override_settings(DEBUG=True,
DEBUG_TOOLBAR_PANELS=['debug_toolbar.panels.profiling.ProfilingDebugPanel'])
class ProfilingPanelIntegrationTestCase(TestCase):
diff --git a/tests/panels/test_redirects.py b/tests/panels/test_redirects.py
new file mode 100644
index 0000000..400cdcc
--- /dev/null
+++ b/tests/panels/test_redirects.py
@@ -0,0 +1,46 @@
+from __future__ import unicode_literals
+
+import django
+from django.http import HttpResponse
+from django.test.utils import override_settings
+from django.utils import unittest
+
+from ..base import BaseTestCase
+
+
+@override_settings(DEBUG_TOOLBAR_CONFIG={'INTERCEPT_REDIRECTS': True})
+class RedirectsPanelTestCase(BaseTestCase):
+
+ def setUp(self):
+ super(RedirectsPanelTestCase, self).setUp()
+ self.panel = self.toolbar.get_panel_by_id('InterceptRedirectsPanel')
+
+ def test_regular_response(self):
+ response = self.panel.process_response(self.request, self.response)
+ self.assertTrue(response is self.response)
+
+ def test_not_a_redirect(self):
+ redirect = HttpResponse(status=304) # not modified
+ response = self.panel.process_response(self.request, redirect)
+ self.assertTrue(response is redirect)
+
+ def test_redirect(self):
+ redirect = HttpResponse(status=302)
+ redirect['Location'] = 'http://somewhere/else/'
+ response = self.panel.process_response(self.request, redirect)
+ self.assertFalse(response is redirect)
+ self.assertContains(response, '302 FOUND')
+ self.assertContains(response, 'http://somewhere/else/')
+
+ def test_unknown_status_code(self):
+ redirect = HttpResponse(status=369)
+ redirect['Location'] = 'http://somewhere/else/'
+ response = self.panel.process_response(self.request, redirect)
+ self.assertContains(response, '369 UNKNOWN STATUS CODE')
+
+ @unittest.skipIf(django.VERSION[:2] < (1, 6), "reason isn't supported")
+ def test_unknown_status_code_with_reason(self):
+ redirect = HttpResponse(status=369, reason='Look Ma!')
+ redirect['Location'] = 'http://somewhere/else/'
+ response = self.panel.process_response(self.request, redirect)
+ self.assertContains(response, '369 Look Ma!')
diff --git a/tests/tests.py b/tests/tests.py
index b926895..b08ac1c 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -5,6 +5,7 @@ if django.VERSION[:2] < (1, 6): # unittest-style discovery isn't available
from .panels.test_cache import * # noqa
from .panels.test_logger import * # noqa
from .panels.test_profiling import * # noqa
+ from .panels.test_redirects import * # noqa
from .panels.test_request_vars import * # noqa
from .panels.test_sql import * # noqa
from .panels.test_template import * # noqa