def test_sitemap_cache(self): page1, page2 = self.get_pages() page_ext = PageSitemapProperties.objects.create( extended_object=page1, priority='0.2', changefreq='never') page_ext_2 = PageSitemapProperties.objects.create( extended_object=page2, priority='0.8', changefreq='hourly') page1.publish('it') page1 = page1.get_public_object() page2.publish('it') page2 = page2.get_public_object() sitemap = ExtendedSitemap() self.assertEqual(len(sitemap.items()), 4) for item in sitemap.items(): if item.page.pk == page1.pk: self.assertEqual(sitemap.changefreq(item), 'never') ext_key = get_cache_key(item.page) self.assertEqual(cache.get(ext_key), item.page.pagesitemapproperties) if item.page.pk == page2.pk: self.assertEqual(sitemap.changefreq(item), 'hourly') ext_key = get_cache_key(page1) page1.pagesitemapproperties.save() self.assertEqual(cache.get(ext_key), None) ext_key = get_cache_key(page2) page2.delete() self.assertEqual(cache.get(ext_key), None)
def test_sitemap_exclude(self): page1, page2, page3 = self.get_pages() PageSitemapProperties.objects.create( extended_object=page3, priority='0.2', changefreq='never', include_in_sitemap=False ) sitemap = ExtendedSitemap() # unpublished since change, still in the sitemap self.assertEqual(len(sitemap.items()), 6) page3.publish('en') page3.publish('fr') sitemap = ExtendedSitemap() # published, then no longer in the sitemap self.assertEqual(len(sitemap.items()), 4)
def test_sitemap_cache(self): page1, page2, page3 = self.get_pages() PageSitemapProperties.objects.create(extended_object=page1, priority='0.2', changefreq='never') PageSitemapProperties.objects.create(extended_object=page3, priority='0.8', changefreq='hourly') page1.publish('fr') page1 = page1.get_public_object() page3.publish('fr') page3 = page3.get_public_object() sitemap = ExtendedSitemap() self.assertEqual(len(sitemap.items()), 6) for item in sitemap.items(): if item.page.pk == page1.pk: self.assertEqual(sitemap.changefreq(item), 'never') self.assertEqual(sitemap.priority(item), Decimal('0.2')) ext_key = get_cache_key(item.page) self.assertEqual(cache.get(ext_key), item.page.pagesitemapproperties) if item.page.pk == page3.pk: self.assertEqual(sitemap.changefreq(item), 'hourly') self.assertEqual(sitemap.priority(item), Decimal('0.8')) ext_key = get_cache_key(page1) page1.pagesitemapproperties.save() self.assertEqual(cache.get(ext_key), None) ext_key = get_cache_key(page3) page3.delete() self.assertEqual(cache.get(ext_key), None)
def test_sitemap_exclude(self): page1, page2, page3 = self.get_pages() PageSitemapProperties.objects.create(extended_object=page3, priority='0.2', changefreq='never', include_in_sitemap=False) sitemap = ExtendedSitemap() # unpublished since change, still in the sitemap self.assertEqual(len(sitemap.items()), 6) page3.publish('en') page3.publish('fr') sitemap = ExtendedSitemap() # published, then no longer in the sitemap self.assertEqual(len(sitemap.items()), 4)