2012-06-08 00:08:47 +08:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2012-01-30 03:24:32 +08:00
|
|
|
from django.conf import settings
|
|
|
|
from django.utils.unittest import skipUnless
|
|
|
|
|
|
|
|
from .base import SitemapTestsBase
|
|
|
|
|
|
|
|
class FlatpagesSitemapTests(SitemapTestsBase):
|
|
|
|
|
|
|
|
@skipUnless("django.contrib.flatpages" in settings.INSTALLED_APPS,
|
|
|
|
"django.contrib.flatpages app not installed.")
|
|
|
|
def test_flatpage_sitemap(self):
|
|
|
|
"Basic FlatPage sitemap test"
|
|
|
|
|
|
|
|
# Import FlatPage inside the test so that when django.contrib.flatpages
|
|
|
|
# is not installed we don't get problems trying to delete Site
|
|
|
|
# objects (FlatPage has an M2M to Site, Site.delete() tries to
|
|
|
|
# delete related objects, but the M2M table doesn't exist.
|
|
|
|
from django.contrib.flatpages.models import FlatPage
|
|
|
|
|
|
|
|
public = FlatPage.objects.create(
|
2012-06-08 00:08:47 +08:00
|
|
|
url='/public/',
|
|
|
|
title='Public Page',
|
2012-01-30 03:24:32 +08:00
|
|
|
enable_comments=True,
|
|
|
|
registration_required=False,
|
|
|
|
)
|
|
|
|
public.sites.add(settings.SITE_ID)
|
|
|
|
private = FlatPage.objects.create(
|
2012-06-08 00:08:47 +08:00
|
|
|
url='/private/',
|
|
|
|
title='Private Page',
|
2012-01-30 03:24:32 +08:00
|
|
|
enable_comments=True,
|
|
|
|
registration_required=True
|
|
|
|
)
|
|
|
|
private.sites.add(settings.SITE_ID)
|
|
|
|
response = self.client.get('/flatpages/sitemap.xml')
|
|
|
|
# Public flatpage should be in the sitemap
|
|
|
|
self.assertContains(response, '<loc>%s%s</loc>' % (self.base_url, public.url))
|
|
|
|
# Private flatpage should not be in the sitemap
|
|
|
|
self.assertNotContains(response, '<loc>%s%s</loc>' % (self.base_url, private.url))
|