Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.2.X] Fixed #15111 -- Ensured that the auth, contenttypes and sitem…

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

Backport of r15418 from trunk.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15419 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6987048561a6bd77315d5aeb5025c8edcb9a2658 1 parent 6935066
@freakboy3742 freakboy3742 authored
View
15 django/contrib/auth/tests/views.py
@@ -191,10 +191,13 @@ class LoginTest(AuthViewsTestCase):
def test_current_site_in_context_after_login(self):
response = self.client.get(reverse('django.contrib.auth.views.login'))
self.assertEquals(response.status_code, 200)
- site = Site.objects.get_current()
- self.assertEquals(response.context['site'], site)
- self.assertEquals(response.context['site_name'], site.name)
- self.assert_(isinstance(response.context['form'], AuthenticationForm),
+ if Site._meta.installed:
+ site = Site.objects.get_current()
+ self.assertEquals(response.context['site'], site)
+ self.assertEquals(response.context['site_name'], site.name)
+ else:
+ self.assertTrue(isinstance(response.context['site'], RequestSite))
+ self.assert_(isinstance(response.context['form'], AuthenticationForm),
'Login form is not an AuthenticationForm')
def test_security_check(self, password='password'):
@@ -236,7 +239,7 @@ def test_security_check(self, password='password'):
self.assertEquals(response.status_code, 302)
self.assertTrue('/view/?param=%s' % url_ in response['Location'], "/view/?param=%s should be allowed" % url_)
-
+
class LogoutTest(AuthViewsTestCase):
urls = 'django.contrib.auth.tests.urls'
@@ -267,7 +270,7 @@ def test_14377(self):
response = self.client.get('/logout/')
self.assertTrue('site' in response.context)
- def test_logout_with_next_page_specified(self):
+ def test_logout_with_next_page_specified(self):
"Logout with next_page option given redirects to specified resource"
self.login()
response = self.client.get('/logout/next_page/')
View
8 django/contrib/contenttypes/tests.py
@@ -61,9 +61,11 @@ def test_shortcut_view(self):
from django.contrib.auth.models import User
user_ct = ContentType.objects.get_for_model(User)
obj = User.objects.create(username="john")
- Site._meta.installed = True
- response = shortcut(request, user_ct.id, obj.id)
- self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
+
+ if Site._meta.installed:
+ response = shortcut(request, user_ct.id, obj.id)
+ self.assertEqual("http://example.com/users/john/", response._headers.get("location")[1])
+
Site._meta.installed = False
response = shortcut(request, user_ct.id, obj.id)
self.assertEqual("http://Example.com/users/john/", response._headers.get("location")[1])
View
33 django/contrib/sitemaps/tests/basic.py
@@ -13,6 +13,10 @@ class SitemapTests(TestCase):
urls = 'django.contrib.sitemaps.tests.urls'
def setUp(self):
+ if Site._meta.installed:
+ self.base_url = 'http://example.com'
+ else:
+ self.base_url = 'http://testserver'
self.old_USE_L10N = settings.USE_L10N
self.old_Site_meta_installed = Site._meta.installed
# Create a user that will double as sitemap content
@@ -29,9 +33,9 @@ def test_simple_sitemap(self):
# 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/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
+<url><loc>%s/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
</urlset>
-""" % date.today().strftime('%Y-%m-%d'))
+""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
if settings.USE_I18N:
def test_localized_priority(self):
@@ -55,13 +59,13 @@ def test_generic_sitemap(self):
expected = ''
for username in User.objects.values_list("username", flat=True):
- expected += "<url><loc>http://example.com/users/%s/</loc></url>" %username
+ expected += "<url><loc>%s/users/%s/</loc></url>" % (self.base_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">
%s
</urlset>
-""" %expected)
+""" % expected)
if "django.contrib.flatpages" in settings.INSTALLED_APPS:
def test_flatpage_sitemap(self):
@@ -89,9 +93,9 @@ def test_flatpage_sitemap(self):
private.sites.add(settings.SITE_ID)
response = self.client.get('/flatpages/sitemap.xml')
# Public flatpage should be in the sitemap
- self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url)
+ self.assertContains(response, '<loc>http://%s%s</loc>' % (self.base_url, public.url))
# Private flatpage should not be in the sitemap
- self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
+ self.assertNotContains(response, '<loc>http://%s%s</loc>' % (self.base_url, private.url))
def test_requestsite_sitemap(self):
# Make sure hitting the flatpages sitemap without the sites framework
@@ -106,14 +110,14 @@ def test_requestsite_sitemap(self):
</urlset>
""" % date.today().strftime('%Y-%m-%d'))
- def test_sitemap_get_urls_no_site_1(self):
- """
- Check we get ImproperlyConfigured if we don't pass a site object to
- Sitemap.get_urls and no Site objects exist
- """
- Site._meta.installed = True
- Site.objects.all().delete()
- self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
+ if "django.contrib.sites" in settings.INSTALLED_APPS:
+ def test_sitemap_get_urls_no_site_1(self):
+ """
+ Check we get ImproperlyConfigured if we don't pass a site object to
+ Sitemap.get_urls and no Site objects exist
+ """
+ Site.objects.all().delete()
+ self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
def test_sitemap_get_urls_no_site_2(self):
"""
@@ -121,6 +125,5 @@ def test_sitemap_get_urls_no_site_2(self):
Sitemap.get_urls if Site objects exists, but the sites framework is not
actually installed.
"""
- Site.objects.get_current()
Site._meta.installed = False
self.assertRaises(ImproperlyConfigured, Sitemap().get_urls)
Please sign in to comment.
Something went wrong with that request. Please try again.