1
+ import html
2
+
1
3
from django .test import RequestFactory , override_settings
2
4
from django .urls import resolve , reverse
3
5
@@ -64,6 +66,21 @@ def test_urls(self):
64
66
65
67
@override_settings (DEBUG = True )
66
68
class HistoryViewsTestCase (IntegrationTestCase ):
69
+ PANEL_KEYS = {
70
+ "VersionsPanel" ,
71
+ "TimerPanel" ,
72
+ "SettingsPanel" ,
73
+ "HeadersPanel" ,
74
+ "RequestPanel" ,
75
+ "SQLPanel" ,
76
+ "StaticFilesPanel" ,
77
+ "TemplatesPanel" ,
78
+ "CachePanel" ,
79
+ "SignalsPanel" ,
80
+ "LoggingPanel" ,
81
+ "ProfilingPanel" ,
82
+ }
83
+
67
84
def test_history_panel_integration_content (self ):
68
85
"""Verify the history panel's content renders properly.."""
69
86
self .assertEqual (len (DebugToolbar ._store ), 0 )
@@ -88,26 +105,45 @@ def test_history_sidebar_invalid(self):
88
105
def test_history_sidebar (self ):
89
106
"""Validate the history sidebar view."""
90
107
self .client .get ("/json_view/" )
91
- store_id = list (DebugToolbar ._store .keys ())[0 ]
108
+ store_id = list (DebugToolbar ._store )[0 ]
109
+ data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
110
+ response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
111
+ self .assertEqual (response .status_code , 200 )
112
+ self .assertEqual (
113
+ set (response .json ()),
114
+ self .PANEL_KEYS ,
115
+ )
116
+
117
+ @override_settings (
118
+ DEBUG_TOOLBAR_CONFIG = {"RESULTS_CACHE_SIZE" : 1 , "RENDER_PANELS" : False }
119
+ )
120
+ def test_history_sidebar_expired_store_id (self ):
121
+ """Validate the history sidebar view."""
122
+ self .client .get ("/json_view/" )
123
+ store_id = list (DebugToolbar ._store )[0 ]
124
+ data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
125
+ response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
126
+ self .assertEqual (response .status_code , 200 )
127
+ self .assertEqual (
128
+ set (response .json ()),
129
+ self .PANEL_KEYS ,
130
+ )
131
+ self .client .get ("/json_view/" )
132
+
133
+ # Querying old store_id should return in empty response
92
134
data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
93
135
response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
94
136
self .assertEqual (response .status_code , 200 )
137
+ self .assertEqual (response .json (), {})
138
+
139
+ # Querying with latest store_id
140
+ latest_store_id = list (DebugToolbar ._store )[0 ]
141
+ data = {"signed" : SignedDataForm .sign ({"store_id" : latest_store_id })}
142
+ response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
143
+ self .assertEqual (response .status_code , 200 )
95
144
self .assertEqual (
96
- set (response .json ().keys ()),
97
- {
98
- "VersionsPanel" ,
99
- "TimerPanel" ,
100
- "SettingsPanel" ,
101
- "HeadersPanel" ,
102
- "RequestPanel" ,
103
- "SQLPanel" ,
104
- "StaticFilesPanel" ,
105
- "TemplatesPanel" ,
106
- "CachePanel" ,
107
- "SignalsPanel" ,
108
- "LoggingPanel" ,
109
- "ProfilingPanel" ,
110
- },
145
+ set (response .json ()),
146
+ self .PANEL_KEYS ,
111
147
)
112
148
113
149
def test_history_refresh_invalid_signature (self ):
@@ -128,5 +164,10 @@ def test_history_refresh(self):
128
164
self .assertEqual (response .status_code , 200 )
129
165
data = response .json ()
130
166
self .assertEqual (len (data ["requests" ]), 1 )
167
+
168
+ store_id = list (DebugToolbar ._store )[0 ]
169
+ signature = SignedDataForm .sign ({"store_id" : store_id })
170
+ self .assertIn (html .escape (signature ), data ["requests" ][0 ]["content" ])
171
+
131
172
for val in ["foo" , "bar" ]:
132
173
self .assertIn (val , data ["requests" ][0 ]["content" ])
0 commit comments