62 | | def test_flatpage_sitemap(self): |
63 | | "Basic FlatPage sitemap test" |
64 | | public = FlatPage.objects.create( |
65 | | url=u'/public/', |
66 | | title=u'Public Page', |
67 | | enable_comments=True, |
68 | | registration_required=False, |
69 | | ) |
70 | | public.sites.add(settings.SITE_ID) |
71 | | private = FlatPage.objects.create( |
72 | | url=u'/private/', |
73 | | title=u'Private Page', |
74 | | enable_comments=True, |
75 | | registration_required=True |
76 | | ) |
77 | | private.sites.add(settings.SITE_ID) |
78 | | response = self.client.get('/flatpages/sitemap.xml') |
79 | | # Public flatpage should be in the sitemap |
80 | | self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url) |
81 | | # Private flatpage should not be in the sitemap |
82 | | self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url) |
| 65 | if "django.contrib.flatpages" in settings.INSTALLED_APPS: |
| 66 | def test_flatpage_sitemap(self): |
| 67 | "Basic FlatPage sitemap test" |
| 68 | |
| 69 | # Import FlatPage inside the test so that when django.contrib.flatpages |
| 70 | # is not installed we don't get problems trying to delete Site |
| 71 | # objects (FlatPage has an M2M to Site, Site.delete() tries to |
| 72 | # delete related objects, but the M2M table doesn't exist. |
| 73 | from django.contrib.flatpages.models import FlatPage |
| 75 | public = FlatPage.objects.create( |
| 76 | url=u'/public/', |
| 77 | title=u'Public Page', |
| 78 | enable_comments=True, |
| 79 | registration_required=False, |
| 80 | ) |
| 81 | public.sites.add(settings.SITE_ID) |
| 82 | private = FlatPage.objects.create( |
| 83 | url=u'/private/', |
| 84 | title=u'Private Page', |
| 85 | enable_comments=True, |
| 86 | registration_required=True |
| 87 | ) |
| 88 | private.sites.add(settings.SITE_ID) |
| 89 | response = self.client.get('/flatpages/sitemap.xml') |
| 90 | # Public flatpage should be in the sitemap |
| 91 | self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url) |
| 92 | # Private flatpage should not be in the sitemap |
| 93 | self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url) |
| 94 | |