Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Modified the sitemaps tests to remove an assumption about the…

… environment in which the tests are run. Thanks to Gabriel Hurley for the report and patch.

Backport of r14184 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 23ecf3cf6c6c1b426a5a192cee8f14ed8a7860c0 1 parent 9b077ee
Russell Keith-Magee authored October 12, 2010

Showing 1 changed file with 35 additions and 25 deletions. Show diff stats Hide diff stats

  1. 60  django/contrib/sitemaps/tests/basic.py
60  django/contrib/sitemaps/tests/basic.py
... ...
@@ -1,7 +1,6 @@
1 1
 from datetime import date
2 2
 from django.conf import settings
3 3
 from django.contrib.auth.models import User
4  
-from django.contrib.flatpages.models import FlatPage
5 4
 from django.contrib.sitemaps import Sitemap
6 5
 from django.contrib.sites.models import Site
7 6
 from django.core.exceptions import ImproperlyConfigured
@@ -52,40 +51,51 @@ def test_generic_sitemap(self):
52 51
         "A minimal generic sitemap can be rendered"
53 52
         # Retrieve the sitemap.
54 53
         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
55 58
         # Check for all the important bits:
56 59
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
57 60
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
58  
-<url><loc>http://example.com/users/testuser/</loc></url>
  61
+%s
59 62
 </urlset>
60  
-""")
  63
+""" %expected)
  64
+
  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
61 74
 
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)
  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)
83 94
 
84 95
     def test_requestsite_sitemap(self):
85 96
         # Make sure hitting the flatpages sitemap without the sites framework
86 97
         # installed doesn't raise an exception
87 98
         Site._meta.installed = False
88  
-        response = self.client.get('/flatpages/sitemap.xml')
89 99
         # Retrieve the sitemap.
90 100
         response = self.client.get('/simple/sitemap.xml')
91 101
         # Check for all the important bits:

0 notes on commit 23ecf3c

Please sign in to comment.
Something went wrong with that request. Please try again.