def test_cache_page_month_cache_enabled_false(self): """if no cache is enabled in the settings then no caching takes place""" # make the date d = datetime( year=2012, month=6, day=18, minute=2, hour=3, second=10) # request the page request = self.rf.get( reverse('omblog:month', args=[d.year, d.month])) response = views.month(request, d.year, d.month) self.assertNotContains(response, 'THISISATESTPOST') # now create a blog post p = Post() p.title = 'THISISATESTPOST' p.slug = 'slug' p.source_content = 'This is a test post' p.status = p.PUBLISHED p.description = 'test post' p.created = d p.save() # now it contains the content response = views.month(request, d.year, d.month) self.assertContains(response, 'THISISATESTPOST') # enabled it again settings.OMBLOG_CACHE_ENABLED = True reload(o_settings) # change the post to hidden and get view again p.status = p.HIDDEN p.save() # not contains response = views.month(request, d.year, d.month) self.assertNotContains(response, 'THISISATESTPOST') # change post status again and save p.status = p.PUBLISHED p.save() # not contains, because the page is cached response = views.month(request, d.year, d.month) self.assertNotContains(response, 'THISISATESTPOST')
def handle(self, *args, **kwargs): # # # kill all Post.objects.all().delete() Tag.objects.all().delete() # # # now import for mdfile in os.listdir(MDFILES): if mdfile == '.DS_Store': continue f = '%s/%s' % (MDFILES, mdfile) with codecs.open(f, encoding='UTF-8') as md: contents = md.read() parts = contents.split('---') header = yaml.load(parts[0]) # build the post try: # make post p = Post() # created p.created = header['created'] # title p.title = header['title'] # url slug = mdfile.split('/').pop().split('.')[0] if slug.startswith('201'): slug = slug[11:] p.slug = slug # description p.description = header['description'] # contents p.source_content = parts[1] # status p.status = p.PUBLISHED # save it p.save() # tags try: for tag in header['tags']: tag, created = Tag.objects.get_or_create(tag=tag) if created: tag.slug = slugify(tag) tag.save() p.tags.add(tag) except KeyError: pass except TypeError: # is an scrappy idea # make post if mdfile == 'index.html': continue p = Post() p.title = mdfile[11:] p.slug = slugify(p.title) p.contents = contents p.save()
def test_cache_page_index_cache_enabled_false(self): """if no cache is enabled in the settings then no caching takes place""" # request the page request = self.rf.get(reverse('omblog:index')) response = views.index(request) self.assertNotContains(response, 'THISISATESTPOST') # now create a blog post p = Post() p.title = 'THISISATESTPOST' p.slug = 'slug' p.source_content = 'This is a test post' p.status = p.PUBLISHED p.description = 'test post' p.save() # now it contains the content response = views.index(request) self.assertContains(response, 'THISISATESTPOST') # enabled it again settings.OMBLOG_CACHE_ENABLED = True reload(o_settings) # change the post to hidden and get view again p.status = p.HIDDEN p.save() # not contains response = views.index(request) self.assertNotContains(response, 'THISISATESTPOST') # change post status again and save p.status = p.PUBLISHED p.save() # not contains, because the page is cached response = views.index(request) self.assertNotContains(response, 'THISISATESTPOST')