|
2 | 2 | import re |
3 | 3 | import time |
4 | 4 | import unittest |
| 5 | +import warnings |
5 | 6 | from unittest.mock import patch |
6 | 7 |
|
7 | 8 | import html5lib |
8 | 9 | from django.contrib.staticfiles.testing import StaticLiveServerTestCase |
9 | 10 | from django.core import signing |
10 | 11 | from django.core.cache import cache |
| 12 | +from django.core.cache.backends.base import CacheKeyWarning |
11 | 13 | from django.db import connection |
12 | 14 | from django.http import HttpResponse |
13 | 15 | from django.template.loader import get_template |
@@ -209,6 +211,23 @@ def test_low_level_cache_view(self): |
209 | 211 | len(response.toolbar.get_panel_by_id(CachePanel.panel_id).calls), 1 |
210 | 212 | ) |
211 | 213 |
|
| 214 | + def test_cache_panel_store_skips_non_json_keys(self): |
| 215 | + cache.clear() |
| 216 | + with warnings.catch_warnings(): |
| 217 | + warnings.simplefilter("ignore", CacheKeyWarning) |
| 218 | + response = self.client.get("/cache_with_non_json_key/") |
| 219 | + |
| 220 | + self.assertEqual(response.status_code, 200) |
| 221 | + self.assertEqual( |
| 222 | + len(response.toolbar.get_panel_by_id(CachePanel.panel_id).calls), 1 |
| 223 | + ) |
| 224 | + |
| 225 | + request_id = list(get_store().request_ids())[-1] |
| 226 | + toolbar = DebugToolbar.fetch(request_id, CachePanel.panel_id) |
| 227 | + stats = toolbar.get_panel_by_id(CachePanel.panel_id).get_stats() |
| 228 | + self.assertEqual(stats["calls"][0]["name"], "set_many") |
| 229 | + self.assertEqual(stats["calls"][0]["args"], [{"foo": "bar"}]) |
| 230 | + |
212 | 231 | def test_cache_disable_instrumentation(self): |
213 | 232 | """ |
214 | 233 | Verify that middleware cache usages before and after |
|
0 commit comments