Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14447 -- Modified the auth and sitemaps tests to remove some a…

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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14184 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 03f00bcd4240f13e6ffe5d8b6688b8a289cb6f8f 1 parent 5506653
Russell Keith-Magee authored October 12, 2010
7  django/contrib/auth/tests/decorators.py
... ...
@@ -1,3 +1,4 @@
  1
+from django.conf import settings
1 2
 from django.contrib.auth.decorators import login_required
2 3
 from django.contrib.auth.tests.views import AuthViewsTestCase
3 4
 
@@ -15,7 +16,7 @@ class CallableView(object):
15 16
             def __call__(self, *args, **kwargs):
16 17
                 pass
17 18
         login_required(CallableView())
18  
-        
  19
+
19 20
     def testView(self):
20 21
         """
21 22
         Check that login_required is assignable to normal views.
@@ -24,7 +25,7 @@ def normal_view(request):
24 25
             pass
25 26
         login_required(normal_view)
26 27
 
27  
-    def testLoginRequired(self, view_url='/login_required/', login_url='/login/'):
  28
+    def testLoginRequired(self, view_url='/login_required/', login_url=settings.LOGIN_URL):
28 29
         """
29 30
         Check that login_required works on a simple view wrapped in a
30 31
         login_required decorator.
@@ -42,4 +43,4 @@ def testLoginRequiredNextUrl(self):
42 43
         login_required decorator with a login_url set.
43 44
         """
44 45
         self.testLoginRequired(view_url='/login_required_login_url/',
45  
-            login_url='/somewhere/')
  46
+            login_url='/somewhere/')
19  django/contrib/sitemaps/tests/basic.py
... ...
@@ -1,11 +1,11 @@
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
8 7
 from django.test import TestCase
  8
+from django.utils.unittest import skipUnless
9 9
 from django.utils.formats import localize
10 10
 from django.utils.translation import activate, deactivate
11 11
 
@@ -52,15 +52,27 @@ def test_generic_sitemap(self):
52 52
         "A minimal generic sitemap can be rendered"
53 53
         # Retrieve the sitemap.
54 54
         response = self.client.get('/generic/sitemap.xml')
  55
+
  56
+        expected = ''
  57
+        for username in User.objects.values_list("username", flat=True):
  58
+            expected += "<url><loc>http://example.com/users/%s/</loc></url>" %username
55 59
         # Check for all the important bits:
56 60
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
57 61
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
58  
-<url><loc>http://example.com/users/testuser/</loc></url>
  62
+%s
59 63
 </urlset>
60  
-""")
  64
+""" %expected)
61 65
 
  66
+    @skipUnless("django.contrib.flatpages" in settings.INSTALLED_APPS, "django.contrib.flatpages app not installed.")
62 67
     def test_flatpage_sitemap(self):
63 68
         "Basic FlatPage sitemap test"
  69
+
  70
+        # Import FlatPage inside the test so that when django.contrib.flatpages
  71
+        # is not installed we don't get problems trying to delete Site
  72
+        # objects (FlatPage has an M2M to Site, Site.delete() tries to
  73
+        # delete related objects, but the M2M table doesn't exist.
  74
+        from django.contrib.flatpages.models import FlatPage
  75
+
64 76
         public = FlatPage.objects.create(
65 77
             url=u'/public/',
66 78
             title=u'Public Page',
@@ -85,7 +97,6 @@ def test_requestsite_sitemap(self):
85 97
         # Make sure hitting the flatpages sitemap without the sites framework
86 98
         # installed doesn't raise an exception
87 99
         Site._meta.installed = False
88  
-        response = self.client.get('/flatpages/sitemap.xml')
89 100
         # Retrieve the sitemap.
90 101
         response = self.client.get('/simple/sitemap.xml')
91 102
         # Check for all the important bits:

0 notes on commit 03f00bc

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