|
1 | 1 | import copy |
2 | | -import warnings |
3 | 2 |
|
4 | 3 | from django.conf import settings |
5 | 4 | from django.http import HttpResponse |
6 | 5 | from django.test import AsyncRequestFactory |
7 | 6 |
|
8 | 7 | from debug_toolbar.panels.redirects import RedirectsPanel |
9 | | -from debug_toolbar.toolbar import DebugToolbar |
10 | 8 |
|
11 | 9 | from ..base import BaseTestCase |
12 | 10 |
|
13 | 11 |
|
14 | 12 | class RedirectsPanelTestCase(BaseTestCase): |
15 | 13 | panel_id = RedirectsPanel.panel_id |
16 | 14 |
|
17 | | - def setUp(self): |
18 | | - # Suppress the deprecation warning during setup |
19 | | - with warnings.catch_warnings(): |
20 | | - warnings.simplefilter("ignore", DeprecationWarning) |
21 | | - super().setUp() |
22 | | - |
23 | 15 | def test_regular_response(self): |
24 | 16 | not_redirect = HttpResponse() |
25 | 17 | self._get_response = lambda request: not_redirect |
@@ -70,18 +62,6 @@ def test_unknown_status_code_with_reason(self): |
70 | 62 | response = self.panel.process_request(self.request) |
71 | 63 | self.assertContains(response, "369 Look Ma!") |
72 | 64 |
|
73 | | - def test_insert_content(self): |
74 | | - """ |
75 | | - Test that the panel only inserts content after generate_stats and |
76 | | - not the process_request. |
77 | | - """ |
78 | | - redirect = HttpResponse(status=304) |
79 | | - self._get_response = lambda request: redirect |
80 | | - response = self.panel.process_request(self.request) |
81 | | - self.assertIsNotNone(response) |
82 | | - response = self.panel.generate_stats(self.request, redirect) |
83 | | - self.assertIsNone(response) |
84 | | - |
85 | 65 | async def test_async_compatibility(self): |
86 | 66 | redirect = HttpResponse(status=302) |
87 | 67 |
|
@@ -110,11 +90,13 @@ def test_original_response_preserved(self): |
110 | 90 | ) |
111 | 91 |
|
112 | 92 | def test_deprecation_warning(self): |
113 | | - """Test that a deprecation warning is shown when RedirectsPanel is instantiated.""" |
| 93 | + """Test that a deprecation warning is shown when RedirectsPanel used.""" |
| 94 | + redirect = HttpResponse(status=304) |
| 95 | + redirect["Location"] = "http://somewhere/else/" |
| 96 | + self._get_response = lambda request: redirect |
114 | 97 |
|
115 | 98 | with self.assertWarns(DeprecationWarning) as cm: |
116 | | - toolbar = DebugToolbar(self.request, self._get_response) |
117 | | - toolbar.get_panel_by_id(RedirectsPanel.panel_id) |
| 99 | + self.panel.process_request(self.request) |
118 | 100 |
|
119 | 101 | self.assertIn("RedirectsPanel is deprecated", str(cm.warning)) |
120 | 102 | self.assertIn("HistoryPanel", str(cm.warning)) |
0 commit comments