(self)
| 2266 | ) |
| 2267 | |
| 2268 | def test_patch_cache_control(self): |
| 2269 | tests = ( |
| 2270 | # Initial Cache-Control, kwargs to patch_cache_control, expected |
| 2271 | # Cache-Control parts. |
| 2272 | (None, {"private": True}, {"private"}), |
| 2273 | ("", {"private": True}, {"private"}), |
| 2274 | # no-cache. |
| 2275 | ("", {"no_cache": "Set-Cookie"}, {"no-cache=Set-Cookie"}), |
| 2276 | ("", {"no-cache": "Set-Cookie"}, {"no-cache=Set-Cookie"}), |
| 2277 | ("no-cache=Set-Cookie", {"no_cache": True}, {"no-cache"}), |
| 2278 | ("no-cache=Set-Cookie,no-cache=Link", {"no_cache": True}, {"no-cache"}), |
| 2279 | ( |
| 2280 | "no-cache=Set-Cookie", |
| 2281 | {"no_cache": "Link"}, |
| 2282 | {"no-cache=Set-Cookie", "no-cache=Link"}, |
| 2283 | ), |
| 2284 | ( |
| 2285 | "no-cache=Set-Cookie,no-cache=Link", |
| 2286 | {"no_cache": "Custom"}, |
| 2287 | {"no-cache=Set-Cookie", "no-cache=Link", "no-cache=Custom"}, |
| 2288 | ), |
| 2289 | # Test whether private/public attributes are mutually exclusive |
| 2290 | ("private", {"private": True}, {"private"}), |
| 2291 | ("private", {"public": True}, {"public"}), |
| 2292 | ("public", {"public": True}, {"public"}), |
| 2293 | ("public", {"private": True}, {"private"}), |
| 2294 | ( |
| 2295 | "must-revalidate,max-age=60,private", |
| 2296 | {"public": True}, |
| 2297 | {"must-revalidate", "max-age=60", "public"}, |
| 2298 | ), |
| 2299 | ( |
| 2300 | "must-revalidate,max-age=60,public", |
| 2301 | {"private": True}, |
| 2302 | {"must-revalidate", "max-age=60", "private"}, |
| 2303 | ), |
| 2304 | ( |
| 2305 | "must-revalidate,max-age=60", |
| 2306 | {"public": True}, |
| 2307 | {"must-revalidate", "max-age=60", "public"}, |
| 2308 | ), |
| 2309 | ) |
| 2310 | |
| 2311 | cc_delim_re = re.compile(r"\s*,\s*") |
| 2312 | |
| 2313 | for initial_cc, newheaders, expected_cc in tests: |
| 2314 | with self.subTest(initial_cc=initial_cc, newheaders=newheaders): |
| 2315 | response = HttpResponse() |
| 2316 | if initial_cc is not None: |
| 2317 | response.headers["Cache-Control"] = initial_cc |
| 2318 | patch_cache_control(response, **newheaders) |
| 2319 | parts = set(cc_delim_re.split(response.headers["Cache-Control"])) |
| 2320 | self.assertEqual(parts, expected_cc) |
| 2321 | |
| 2322 | |
| 2323 | @override_settings( |
nothing calls this directly
no test coverage detected