Skip to content

Commit 3803724

Browse files
committed
Use request toolbar for cache integration tests
For integration tests using the cache panel, check the panel associated with the toolbar created for the request, rather than the toolbar created for the test case.
1 parent 7366d2b commit 3803724

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

tests/test_integration.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,28 @@ def test_cache_page(self):
109109
# Clear the cache before testing the views. Other tests that use cached_view
110110
# may run earlier and cause fewer cache calls.
111111
cache.clear()
112-
self.client.get("/cached_view/")
113-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 3)
114-
self.client.get("/cached_view/")
115-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 5)
112+
response = self.client.get("/cached_view/")
113+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 3)
114+
response = self.client.get("/cached_view/")
115+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 2)
116116

117117
@override_settings(ROOT_URLCONF="tests.urls_use_package_urls")
118118
def test_include_package_urls(self):
119119
"""Test urlsconf that uses the debug_toolbar.urls in the include call"""
120120
# Clear the cache before testing the views. Other tests that use cached_view
121121
# may run earlier and cause fewer cache calls.
122122
cache.clear()
123-
self.client.get("/cached_view/")
124-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 3)
125-
self.client.get("/cached_view/")
126-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 5)
123+
response = self.client.get("/cached_view/")
124+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 3)
125+
response = self.client.get("/cached_view/")
126+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 2)
127127

128128
def test_low_level_cache_view(self):
129129
"""Test cases when low level caching API is used within a request."""
130-
self.client.get("/cached_low_level_view/")
131-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 2)
132-
self.client.get("/cached_low_level_view/")
133-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 3)
130+
response = self.client.get("/cached_low_level_view/")
131+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 2)
132+
response = self.client.get("/cached_low_level_view/")
133+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 1)
134134

135135
def test_cache_disable_instrumentation(self):
136136
"""
@@ -139,10 +139,10 @@ def test_cache_disable_instrumentation(self):
139139
"""
140140
self.assertIsNone(cache.set("UseCacheAfterToolbar.before", None))
141141
self.assertIsNone(cache.set("UseCacheAfterToolbar.after", None))
142-
self.client.get("/execute_sql/")
142+
response = self.client.get("/execute_sql/")
143143
self.assertEqual(cache.get("UseCacheAfterToolbar.before"), 1)
144144
self.assertEqual(cache.get("UseCacheAfterToolbar.after"), 1)
145-
self.assertEqual(len(self.toolbar.get_panel_by_id("CachePanel").calls), 0)
145+
self.assertEqual(len(response.toolbar.get_panel_by_id("CachePanel").calls), 0)
146146

147147
def test_is_toolbar_request(self):
148148
self.request.path = "/__debug__/render_panel/"

0 commit comments

Comments
 (0)