Author: russellm
Date: 2010-10-12 02:15:47 -0500 (Tue, 12 Oct 2010)
New Revision: 14184

Modified:
   django/trunk/django/contrib/auth/tests/decorators.py
   django/trunk/django/contrib/sitemaps/tests/basic.py
Log:
Fixed #14447 -- Modified the auth and sitemaps tests to remove some assumptions 
about the environment in which the tests are run. Thanks to Gabriel Hurley for 
the report and patch.

Modified: django/trunk/django/contrib/auth/tests/decorators.py
===================================================================
--- django/trunk/django/contrib/auth/tests/decorators.py        2010-10-12 
03:33:19 UTC (rev 14183)
+++ django/trunk/django/contrib/auth/tests/decorators.py        2010-10-12 
07:15:47 UTC (rev 14184)
@@ -1,3 +1,4 @@
+from django.conf import settings
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth.tests.views import AuthViewsTestCase
 
@@ -15,7 +16,7 @@
             def __call__(self, *args, **kwargs):
                 pass
         login_required(CallableView())
-        
+
     def testView(self):
         """
         Check that login_required is assignable to normal views.
@@ -24,7 +25,7 @@
             pass
         login_required(normal_view)
 
-    def testLoginRequired(self, view_url='/login_required/', 
login_url='/login/'):
+    def testLoginRequired(self, view_url='/login_required/', 
login_url=settings.LOGIN_URL):
         """
         Check that login_required works on a simple view wrapped in a
         login_required decorator.
@@ -42,4 +43,4 @@
         login_required decorator with a login_url set.
         """
         self.testLoginRequired(view_url='/login_required_login_url/',
-            login_url='/somewhere/')
\ No newline at end of file
+            login_url='/somewhere/')

Modified: django/trunk/django/contrib/sitemaps/tests/basic.py
===================================================================
--- django/trunk/django/contrib/sitemaps/tests/basic.py 2010-10-12 03:33:19 UTC 
(rev 14183)
+++ django/trunk/django/contrib/sitemaps/tests/basic.py 2010-10-12 07:15:47 UTC 
(rev 14184)
@@ -1,11 +1,11 @@
 from datetime import date
 from django.conf import settings
 from django.contrib.auth.models import User
-from django.contrib.flatpages.models import FlatPage
 from django.contrib.sitemaps import Sitemap
 from django.contrib.sites.models import Site
 from django.core.exceptions import ImproperlyConfigured
 from django.test import TestCase
+from django.utils.unittest import skipUnless
 from django.utils.formats import localize
 from django.utils.translation import activate, deactivate
 
@@ -52,15 +52,27 @@
         "A minimal generic sitemap can be rendered"
         # Retrieve the sitemap.
         response = self.client.get('/generic/sitemap.xml')
+
+        expected = ''
+        for username in User.objects.values_list("username", flat=True):
+            expected += "<url><loc>http://example.com/users/%s/</loc></url>" 
%username
         # Check for all the important bits:
         self.assertEquals(response.content, """<?xml version="1.0" 
encoding="UTF-8"?>
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9";>
-<url><loc>http://example.com/users/testuser/</loc></url>
+%s
 </urlset>
-""")
+""" %expected)
 
+    @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(
             url=u'/public/',
             title=u'Public Page',
@@ -85,7 +97,6 @@
         # Make sure hitting the flatpages sitemap without the sites framework
         # installed doesn't raise an exception
         Site._meta.installed = False
-        response = self.client.get('/flatpages/sitemap.xml')
         # Retrieve the sitemap.
         response = self.client.get('/simple/sitemap.xml')
         # Check for all the important bits:

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to