@@ -406,6 +406,62 @@ def test_user_cannot_see_unpublished_entries(self):
406406 response = self .client .get (published_url )
407407 self .assertEqual (response .status_code , 200 )
408408
409+ def test_drafts_have_no_cache_headers (self ):
410+ """
411+ Test that unpublished entries have no-cache headers and that content
412+ changes are immediately visible (not cached).
413+ """
414+ user = User .objects .create (username = "staff" , is_staff = True )
415+ content_type = ContentType .objects .get_for_model (Entry )
416+ change_permission = Permission .objects .get (
417+ content_type = content_type , codename = "change_entry"
418+ )
419+ user .user_permissions .add (change_permission )
420+ self .client .force_login (user )
421+
422+ unpublished_entry = Entry .objects .create (
423+ pub_date = self .tomorrow ,
424+ is_active = True ,
425+ headline = "unpublished" ,
426+ slug = "unpublished" ,
427+ body = "draft 1" ,
428+ )
429+ unpublished_url = reverse (
430+ "weblog:entry" ,
431+ kwargs = {
432+ "year" : unpublished_entry .pub_date .year ,
433+ "month" : unpublished_entry .pub_date .strftime ("%b" ).lower (),
434+ "day" : unpublished_entry .pub_date .day ,
435+ "slug" : unpublished_entry .slug ,
436+ },
437+ )
438+
439+ response = self .client .get (unpublished_url )
440+
441+ self .assertEqual (response .status_code , 200 )
442+ self .assertIn ("Cache-Control" , response .headers )
443+ self .assertEqual (response .headers ["Cache-Control" ], "private, no-cache" )
444+
445+ def test_published_blogs_do_not_have_cache_control_headers (self ):
446+ """
447+ Test that published blog posts don't have explicit no-cache headers.
448+ """
449+ entry = Entry .objects .create (
450+ pub_date = self .yesterday , is_active = True , headline = "foo" , slug = "foo"
451+ )
452+ url = reverse (
453+ "weblog:entry" ,
454+ kwargs = {
455+ "year" : entry .pub_date .year ,
456+ "month" : entry .pub_date .strftime ("%b" ).lower (),
457+ "day" : entry .pub_date .day ,
458+ "slug" : entry .slug ,
459+ },
460+ )
461+ response = self .client .get (url )
462+ self .assertEqual (response .status_code , 200 )
463+ self .assertNotIn ("Cache-Control" , response .headers )
464+
409465
410466class SitemapTests (DateTimeMixin , TestCase ):
411467 def test_sitemap (self ):
0 commit comments