Skip to content

Commit f92dee7

Browse files
authored
Merge pull request #1412 from folt/fix-1406
fix for #1406
2 parents 621019c + d58f408 commit f92dee7

File tree

3 files changed

+69
-6
lines changed

3 files changed

+69
-6
lines changed

debug_toolbar/panels/request.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.utils.translation import gettext_lazy as _
44

55
from debug_toolbar.panels import Panel
6-
from debug_toolbar.utils import get_name_from_obj
6+
from debug_toolbar.utils import get_name_from_obj, get_sorted_request_variable
77

88

99
class RequestPanel(Panel):
@@ -26,13 +26,12 @@ def nav_subtitle(self):
2626
def generate_stats(self, request, response):
2727
self.record_stats(
2828
{
29-
"get": [(k, request.GET.getlist(k)) for k in sorted(request.GET)],
30-
"post": [(k, request.POST.getlist(k)) for k in sorted(request.POST)],
31-
"cookies": [
32-
(k, request.COOKIES.get(k)) for k in sorted(request.COOKIES)
33-
],
29+
"get": get_sorted_request_variable(request.GET),
30+
"post": get_sorted_request_variable(request.POST),
31+
"cookies": get_sorted_request_variable(request.COOKIES),
3432
}
3533
)
34+
3635
view_info = {
3736
"view_func": _("<no view>"),
3837
"view_args": "None",

debug_toolbar/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,16 @@ def getframeinfo(frame, context=1):
210210
return (filename, lineno, frame.f_code.co_name, lines, index)
211211

212212

213+
def get_sorted_request_variable(variable):
214+
"""
215+
Get a sorted list of variables from the request data.
216+
"""
217+
if isinstance(variable, dict):
218+
return [(k, variable.get(k)) for k in sorted(variable)]
219+
else:
220+
return [(k, variable.getlist(k)) for k in sorted(variable)]
221+
222+
213223
def get_stack(context=1):
214224
"""
215225
Get a list of records for a frame and all higher (calling) frames.

tests/panels/test_request.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from django.http import QueryDict
2+
13
from ..base import BaseTestCase
24

35

@@ -30,3 +32,55 @@ def test_insert_content(self):
3032
content = self.panel.content
3133
self.assertIn("nôt åscíì", content)
3234
self.assertValidHTML(content)
35+
36+
def test_query_dict_for_request_in_method_get(self):
37+
"""
38+
Test verifies the correctness of the statistics generation method
39+
in the case when the GET request is class QueryDict
40+
"""
41+
self.request.GET = QueryDict("foo=bar")
42+
response = self.panel.process_request(self.request)
43+
self.panel.generate_stats(self.request, response)
44+
# ensure the panel GET request data is processed correctly.
45+
content = self.panel.content
46+
self.assertIn("foo", content)
47+
self.assertIn("bar", content)
48+
49+
def test_dict_for_request_in_method_get(self):
50+
"""
51+
Test verifies the correctness of the statistics generation method
52+
in the case when the GET request is class Dict
53+
"""
54+
self.request.GET = {"foo": "bar"}
55+
response = self.panel.process_request(self.request)
56+
self.panel.generate_stats(self.request, response)
57+
# ensure the panel GET request data is processed correctly.
58+
content = self.panel.content
59+
self.assertIn("foo", content)
60+
self.assertIn("bar", content)
61+
62+
def test_query_dict_for_request_in_method_post(self):
63+
"""
64+
Test verifies the correctness of the statistics generation method
65+
in the case when the POST request is class QueryDict
66+
"""
67+
self.request.GET = QueryDict("foo=bar")
68+
response = self.panel.process_request(self.request)
69+
self.panel.generate_stats(self.request, response)
70+
# ensure the panel POST request data is processed correctly.
71+
content = self.panel.content
72+
self.assertIn("foo", content)
73+
self.assertIn("bar", content)
74+
75+
def test_dict_for_request_in_method_post(self):
76+
"""
77+
Test verifies the correctness of the statistics generation method
78+
in the case when the POST request is class Dict
79+
"""
80+
self.request.GET = {"foo": "bar"}
81+
response = self.panel.process_request(self.request)
82+
self.panel.generate_stats(self.request, response)
83+
# ensure the panel POST request data is processed correctly.
84+
content = self.panel.content
85+
self.assertIn("foo", content)
86+
self.assertIn("bar", content)

0 commit comments

Comments
 (0)