Ticket #14447: fixes_1.2.X.diff

File fixes_1.2.X.diff, 3.9 KB (added by Gabriel Hurley, 14 years ago)
  • django/contrib/sitemaps/tests/basic.py

     
    11from datetime import date
    22from django.conf import settings
    33from django.contrib.auth.models import User
    4 from django.contrib.flatpages.models import FlatPage
    54from django.contrib.sitemaps import Sitemap
    65from django.contrib.sites.models import Site
    76from django.core.exceptions import ImproperlyConfigured
     
    5251        "A minimal generic sitemap can be rendered"
    5352        # Retrieve the sitemap.
    5453        response = self.client.get('/generic/sitemap.xml')
     54       
     55        expected = ''
     56        for username in User.objects.values_list("username", flat=True):
     57            expected += "<url><loc>http://example.com/users/%s/</loc></url>" %username
    5558        # Check for all the important bits:
    5659        self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
    5760<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    58 <url><loc>http://example.com/users/testuser/</loc></url>
     61%s
    5962</urlset>
    60 """)
     63""" %expected)
    6164
    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
    8374
     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
    8495    def test_requestsite_sitemap(self):
    8596        # Make sure hitting the flatpages sitemap without the sites framework
    8697        # installed doesn't raise an exception
    8798        Site._meta.installed = False
    88         response = self.client.get('/flatpages/sitemap.xml')
    8999        # Retrieve the sitemap.
    90100        response = self.client.get('/simple/sitemap.xml')
    91101        # Check for all the important bits:
Back to Top