1 from django
.conf
import settings
2 from django
.utils
.unittest
import skipUnless
4 from .base
import SitemapTestsBase
6 class FlatpagesSitemapTests(SitemapTestsBase
):
8 @skipUnless("django.contrib.flatpages" in settings
.INSTALLED_APPS
,
9 "django.contrib.flatpages app not installed.")
10 def test_flatpage_sitemap(self
):
11 "Basic FlatPage sitemap test"
13 # Import FlatPage inside the test so that when django.contrib.flatpages
14 # is not installed we don't get problems trying to delete Site
15 # objects (FlatPage has an M2M to Site, Site.delete() tries to
16 # delete related objects, but the M2M table doesn't exist.
17 from django
.contrib
.flatpages
.models
import FlatPage
19 public
= FlatPage
.objects
.create(
23 registration_required
=False,
25 public
.sites
.add(settings
.SITE_ID
)
26 private
= FlatPage
.objects
.create(
28 title
=u
'Private Page',
30 registration_required
=True
32 private
.sites
.add(settings
.SITE_ID
)
33 response
= self
.client
.get('/flatpages/sitemap.xml')
34 # Public flatpage should be in the sitemap
35 self
.assertContains(response
, '<loc>%s%s</loc>' % (self
.base_url
, public
.url
))
36 # Private flatpage should not be in the sitemap
37 self
.assertNotContains(response
, '<loc>%s%s</loc>' % (self
.base_url
, private
.url
))