44from django .urls import resolve , reverse
55
66from debug_toolbar .forms import SignedDataForm
7- from debug_toolbar .toolbar import DebugToolbar
7+ from debug_toolbar .store import store
88
99from ..base import BaseTestCase , IntegrationTestCase
1010
@@ -83,29 +83,31 @@ class HistoryViewsTestCase(IntegrationTestCase):
8383
8484 def test_history_panel_integration_content (self ):
8585 """Verify the history panel's content renders properly.."""
86- self .assertEqual (len (DebugToolbar . _store ), 0 )
86+ self .assertEqual (len (store . all () ), 0 )
8787
8888 data = {"foo" : "bar" }
8989 self .client .get ("/json_view/" , data , content_type = "application/json" )
9090
9191 # Check the history panel's stats to verify the toolbar rendered properly.
92- self .assertEqual (len (DebugToolbar . _store ), 1 )
93- toolbar = list (DebugToolbar . _store . values ())[0 ]
92+ self .assertEqual (len (store . all () ), 1 )
93+ toolbar = list (store . all ())[0 ][ 1 ]
9494 content = toolbar .get_panel_by_id ("HistoryPanel" ).content
9595 self .assertIn ("bar" , content )
9696
9797 def test_history_sidebar_invalid (self ):
9898 response = self .client .get (reverse ("djdt:history_sidebar" ))
9999 self .assertEqual (response .status_code , 400 )
100100
101- data = {"signed" : SignedDataForm .sign ({"store_id" : "foo" }) + "invalid" }
101+ self .client .get ("/json_view/" )
102+ store_id = list (store .all ())[0 ][0 ]
103+ data = {"signed" : SignedDataForm .sign ({"store_id" : store_id }) + "invalid" }
102104 response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
103105 self .assertEqual (response .status_code , 400 )
104106
105- def test_history_sidebar (self ):
106- """Validate the history sidebar view ."""
107+ def test_history_sidebar_hash (self ):
108+ """Validate the hashing mechanism ."""
107109 self .client .get ("/json_view/" )
108- store_id = list (DebugToolbar . _store ) [0 ]
110+ store_id = list (store . all ())[ 0 ] [0 ]
109111 data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
110112 response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
111113 self .assertEqual (response .status_code , 200 )
@@ -120,7 +122,7 @@ def test_history_sidebar(self):
120122 def test_history_sidebar_expired_store_id (self ):
121123 """Validate the history sidebar view."""
122124 self .client .get ("/json_view/" )
123- store_id = list (DebugToolbar . _store ) [0 ]
125+ store_id = list (store . all ())[ 0 ] [0 ]
124126 data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
125127 response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
126128 self .assertEqual (response .status_code , 200 )
@@ -130,14 +132,18 @@ def test_history_sidebar_expired_store_id(self):
130132 )
131133 self .client .get ("/json_view/" )
132134
133- # Querying old store_id should return in empty response
135+ # Querying previous store_id should still work
134136 data = {"signed" : SignedDataForm .sign ({"store_id" : store_id })}
135137 response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
136138 self .assertEqual (response .status_code , 200 )
137- self .assertEqual (response .json (), {})
139+ self .assertEqual (
140+ set (response .json ()),
141+ self .PANEL_KEYS ,
142+ )
138143
139144 # Querying with latest store_id
140- latest_store_id = list (DebugToolbar ._store )[0 ]
145+ latest_store_id = list (store .all ())[- 1 ][0 ]
146+ self .assertNotEqual (latest_store_id , store_id )
141147 data = {"signed" : SignedDataForm .sign ({"store_id" : latest_store_id })}
142148 response = self .client .get (reverse ("djdt:history_sidebar" ), data = data )
143149 self .assertEqual (response .status_code , 200 )
@@ -157,15 +163,14 @@ def test_history_refresh_invalid_signature(self):
157163
158164 def test_history_refresh (self ):
159165 """Verify refresh history response has request variables."""
160- data = {"foo" : "bar" }
161- self .client .get ("/json_view/" , data , content_type = "application/json" )
166+ self .client .get ("/json_view/" , {"foo" : "bar" }, content_type = "application/json" )
162167 data = {"signed" : SignedDataForm .sign ({"store_id" : "foo" })}
163168 response = self .client .get (reverse ("djdt:history_refresh" ), data = data )
164169 self .assertEqual (response .status_code , 200 )
165170 data = response .json ()
166171 self .assertEqual (len (data ["requests" ]), 1 )
167172
168- store_id = list (DebugToolbar . _store ) [0 ]
173+ store_id = list (store . all ())[ 0 ] [0 ]
169174 signature = SignedDataForm .sign ({"store_id" : store_id })
170175 self .assertIn (html .escape (signature ), data ["requests" ][0 ]["content" ])
171176
0 commit comments