Skip to content

Commit c90b3ac

Browse files
committed
Add test to verify no self cache tracking
1 parent 9e53a6c commit c90b3ac

1 file changed

Lines changed: 39 additions & 3 deletions

File tree

tests/test_store.py

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import uuid
22

3-
from django.test import TestCase
3+
from django.http import HttpResponse
4+
from django.test import RequestFactory, TestCase
45
from django.test.utils import override_settings
56
from django.utils.safestring import SafeData, mark_safe
67

78
from debug_toolbar import store
9+
from debug_toolbar.toolbar import DebugToolbar
810

911

1012
class SerializationTestCase(TestCase):
@@ -30,7 +32,9 @@ def test_deserialize(self):
3032
class BaseStoreTestCase(TestCase):
3133
def test_methods_are_not_implemented(self):
3234
# Find all the non-private and dunder class methods
33-
methods = [member for member in vars(store.BaseStore) if not member.startswith("_")]
35+
methods = [
36+
member for member in vars(store.BaseStore) if not member.startswith("_")
37+
]
3438
self.assertEqual(len(methods), 7)
3539
with self.assertRaises(NotImplementedError):
3640
store.BaseStore.request_ids()
@@ -123,7 +127,9 @@ class GetStoreTestCase(TestCase):
123127
def test_get_store(self):
124128
self.assertIs(store.get_store(), store.MemoryStore)
125129

126-
@override_settings(DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "tests.test_store.StubStore"})
130+
@override_settings(
131+
DEBUG_TOOLBAR_CONFIG={"TOOLBAR_STORE_CLASS": "tests.test_store.StubStore"}
132+
)
127133
def test_get_store_with_setting(self):
128134
self.assertIs(store.get_store(), StubStore)
129135

@@ -344,3 +350,33 @@ def test_custom_key_prefix(self):
344350
self.assertEqual(self.store._key_prefix(), "custom:")
345351
self.assertEqual(self.store._request_ids_key(), "custom:request_ids")
346352
self.assertEqual(self.store._request_key("test"), "custom:req:test")
353+
354+
def test_cache_store_operations_not_tracked_by_cache_panel(self):
355+
"""Verify that CacheStore operations don't appear in CachePanel data."""
356+
# Set up a toolbar with CachePanel
357+
request = RequestFactory().get("/")
358+
toolbar = DebugToolbar(request, lambda req: HttpResponse())
359+
panel = toolbar.get_panel_by_id("CachePanel")
360+
panel.enable_instrumentation()
361+
362+
try:
363+
# Record the initial number of cache calls
364+
initial_call_count = len(panel.calls)
365+
366+
# Perform various CacheStore operations
367+
self.store.set("test_req")
368+
self.store.save_panel("test_req", "test.panel", {"data": "value"})
369+
self.store.exists("test_req")
370+
self.store.panel("test_req", "test.panel")
371+
self.store.panels("test_req")
372+
self.store.delete("test_req")
373+
374+
# Verify that no cache operations were recorded
375+
# All CacheStore operations should be invisible to the CachePanel
376+
self.assertEqual(
377+
len(panel.calls),
378+
initial_call_count,
379+
"CacheStore operations should not be tracked by CachePanel",
380+
)
381+
finally:
382+
panel.disable_instrumentation()

0 commit comments

Comments
 (0)