Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #15111 -- Ensured that the auth, contenttypes and sitemaps test…

…s will run when the sites app isn't installed. Thanks to Waldemar Kornewald for the report and draft patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15418 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 7a60b411305bc363ec51a096b108fa909c1b352b 1 parent 2d7049c
Russell Keith-Magee authored February 05, 2011
11  django/contrib/auth/tests/views.py
@@ -5,7 +5,7 @@
5 5
 from django.conf import settings
6 6
 from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
7 7
 from django.contrib.auth.forms import AuthenticationForm
8  
-from django.contrib.sites.models import Site
  8
+from django.contrib.sites.models import Site, RequestSite
9 9
 from django.contrib.auth.models import User
10 10
 from django.test import TestCase
11 11
 from django.core import mail
@@ -198,9 +198,12 @@ class LoginTest(AuthViewsTestCase):
198 198
     def test_current_site_in_context_after_login(self):
199 199
         response = self.client.get(reverse('django.contrib.auth.views.login'))
200 200
         self.assertEquals(response.status_code, 200)
201  
-        site = Site.objects.get_current()
202  
-        self.assertEquals(response.context['site'], site)
203  
-        self.assertEquals(response.context['site_name'], site.name)
  201
+        if Site._meta.installed:
  202
+            site = Site.objects.get_current()
  203
+            self.assertEquals(response.context['site'], site)
  204
+            self.assertEquals(response.context['site_name'], site.name)
  205
+        else:
  206
+            self.assertIsInstance(response.context['site'], RequestSite)
204 207
         self.assert_(isinstance(response.context['form'], AuthenticationForm), 
205 208
                      'Login form is not an AuthenticationForm')
206 209
 
8  django/contrib/contenttypes/tests.py
@@ -61,9 +61,11 @@ def test_shortcut_view(self):
61 61
         from django.contrib.auth.models import User
62 62
         user_ct = ContentType.objects.get_for_model(User)
63 63
         obj = User.objects.create(username="john")
64  
-        Site._meta.installed = True
65  
-        response = shortcut(request, user_ct.id, obj.id)
66  
-        self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
  64
+
  65
+        if Site._meta.installed:
  66
+            response = shortcut(request, user_ct.id, obj.id)
  67
+            self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
  68
+
67 69
         Site._meta.installed = False
68 70
         response = shortcut(request, user_ct.id, obj.id)
69 71
         self.assertEqual("http://Example.com/users/john/", response._headers.get("location")[1])
33  django/contrib/sitemaps/tests/basic.py
@@ -15,9 +15,14 @@ class SitemapTests(TestCase):
15 15
     urls = 'django.contrib.sitemaps.tests.urls'
16 16
 
17 17
     def setUp(self):
  18
+        if Site._meta.installed:
  19
+            self.base_url = 'http://example.com'
  20
+        else:
  21
+            self.base_url = 'http://testserver'
18 22
         self.old_USE_L10N = settings.USE_L10N
19 23
         self.old_Site_meta_installed = Site._meta.installed
20 24
         self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
  25
+        self.old_Site_meta_installed = Site._meta.installed
21 26
         settings.TEMPLATE_DIRS = (
22 27
             os.path.join(os.path.dirname(__file__), 'templates'),
23 28
         )
@@ -28,6 +33,7 @@ def tearDown(self):
28 33
         settings.USE_L10N = self.old_USE_L10N
29 34
         Site._meta.installed = self.old_Site_meta_installed
30 35
         settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
  36
+        Site._meta.installed = self.old_Site_meta_installed
31 37
 
32 38
     def test_simple_sitemap_index(self):
33 39
         "A simple sitemap index can be rendered"
@@ -36,9 +42,9 @@ def test_simple_sitemap_index(self):
36 42
         # Check for all the important bits:
37 43
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
38 44
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
39  
-<sitemap><loc>http://example.com/simple/sitemap-simple.xml</loc></sitemap>
  45
+<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
40 46
 </sitemapindex>
41  
-""")
  47
+""" % self.base_url)
42 48
 
43 49
     def test_simple_sitemap_custom_index(self):
44 50
         "A simple sitemap index can be rendered with a custom template"
@@ -48,9 +54,9 @@ def test_simple_sitemap_custom_index(self):
48 54
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
49 55
 <!-- This is a customised template -->
50 56
 <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
51  
-<sitemap><loc>http://example.com/simple/sitemap-simple.xml</loc></sitemap>
  57
+<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
52 58
 </sitemapindex>
53  
-""")
  59
+""" % self.base_url)
54 60
 
55 61
     def test_simple_sitemap(self):
56 62
         "A simple sitemap can be rendered"
@@ -59,9 +65,9 @@ def test_simple_sitemap(self):
59 65
         # Check for all the important bits:
60 66
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
61 67
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
62  
-<url><loc>http://example.com/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
  68
+<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
63 69
 </urlset>
64  
-""" % date.today().strftime('%Y-%m-%d'))
  70
+""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
65 71
 
66 72
     def test_simple_custom_sitemap(self):
67 73
         "A simple sitemap can be rendered with a custom template"
@@ -71,9 +77,9 @@ def test_simple_custom_sitemap(self):
71 77
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
72 78
 <!-- This is a customised template -->
73 79
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
74  
-<url><loc>http://example.com/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
  80
+<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
75 81
 </urlset>
76  
-""" % date.today().strftime('%Y-%m-%d'))
  82
+""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
77 83
 
78 84
     @skipUnless(settings.USE_I18N, "Internationalization is not enabled")
79 85
     def test_localized_priority(self):
@@ -97,13 +103,13 @@ def test_generic_sitemap(self):
97 103
 
98 104
         expected = ''
99 105
         for username in User.objects.values_list("username", flat=True):
100  
-            expected += "<url><loc>http://example.com/users/%s/</loc></url>" %username
  106
+            expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_url, username)
101 107
         # Check for all the important bits:
102 108
         self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
103 109
 <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
104 110
 %s
105 111
 </urlset>
106  
-""" %expected)
  112
+""" % expected)
107 113
 
108 114
     @skipUnless("django.contrib.flatpages" in settings.INSTALLED_APPS, "django.contrib.flatpages app not installed.")
109 115
     def test_flatpage_sitemap(self):
@@ -131,9 +137,9 @@ def test_flatpage_sitemap(self):
131 137
         private.sites.add(settings.SITE_ID)
132 138
         response = self.client.get('/flatpages/sitemap.xml')
133 139
         # Public flatpage should be in the sitemap
134  
-        self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url)
  140
+        self.assertContains(response, '<loc>%s%s</loc>' % (self.base_url, public.url))
135 141
         # Private flatpage should not be in the sitemap
136  
-        self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
  142
+        self.assertNotContains(response, '<loc>%s%s</loc>' % (self.base_url, private.url))
137 143
 
138 144
     def test_requestsite_sitemap(self):
139 145
         # Make sure hitting the flatpages sitemap without the sites framework
@@ -148,12 +154,12 @@ def test_requestsite_sitemap(self):
148 154
 </urlset>
149 155
 """ % date.today().strftime('%Y-%m-%d'))
150 156
 
  157
+    @skipUnless("django.contrib.sites" in settings.INSTALLED_APPS, "django.contrib.sites app not installed.")
151 158
     def test_sitemap_get_urls_no_site_1(self):
152 159
         """
153 160
         Check we get ImproperlyConfigured if we don't pass a site object to
154 161
         Sitemap.get_urls and no Site objects exist
155 162
         """
156  
-        Site._meta.installed = True
157 163
         Site.objects.all().delete()
158 164
         self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
159 165
 
@@ -163,6 +169,5 @@ def test_sitemap_get_urls_no_site_2(self):
163 169
         Sitemap.get_urls if Site objects exists, but the sites framework is not
164 170
         actually installed.
165 171
         """
166  
-        Site.objects.get_current()
167 172
         Site._meta.installed = False
168 173
         self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)

0 notes on commit 7a60b41

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