diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
index b4f93cefc3..a9bcd95434 100644
--- a/django/contrib/auth/tests/views.py
+++ b/django/contrib/auth/tests/views.py
@@ -5,7 +5,7 @@ import urllib
from django.conf import settings
from django.contrib.auth import SESSION_KEY, REDIRECT_FIELD_NAME
from django.contrib.auth.forms import AuthenticationForm
-from django.contrib.sites.models import Site
+from django.contrib.sites.models import Site, RequestSite
from django.contrib.auth.models import User
from django.test import TestCase
from django.core import mail
@@ -198,9 +198,12 @@ 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)
+ 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.assertIsInstance(response.context['site'], RequestSite)
self.assert_(isinstance(response.context['form'], AuthenticationForm),
'Login form is not an AuthenticationForm')
diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py
index a846b07790..7a1ca99d33 100644
--- a/django/contrib/contenttypes/tests.py
+++ b/django/contrib/contenttypes/tests.py
@@ -61,9 +61,11 @@ class ContentTypesTests(TestCase):
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])
diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py
index 3874ac740f..39d02262e9 100644
--- a/django/contrib/sitemaps/tests/basic.py
+++ b/django/contrib/sitemaps/tests/basic.py
@@ -15,9 +15,14 @@ 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
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
+ self.old_Site_meta_installed = Site._meta.installed
settings.TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), 'templates'),
)
@@ -28,6 +33,7 @@ class SitemapTests(TestCase):
settings.USE_L10N = self.old_USE_L10N
Site._meta.installed = self.old_Site_meta_installed
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
+ Site._meta.installed = self.old_Site_meta_installed
def test_simple_sitemap_index(self):
"A simple sitemap index can be rendered"
@@ -36,9 +42,9 @@ class SitemapTests(TestCase):
# Check for all the important bits:
self.assertEquals(response.content, """
-http://example.com/simple/sitemap-simple.xml
+%s/simple/sitemap-simple.xml
-""")
+""" % self.base_url)
def test_simple_sitemap_custom_index(self):
"A simple sitemap index can be rendered with a custom template"
@@ -48,9 +54,9 @@ class SitemapTests(TestCase):
self.assertEquals(response.content, """
-http://example.com/simple/sitemap-simple.xml
+%s/simple/sitemap-simple.xml
-""")
+""" % self.base_url)
def test_simple_sitemap(self):
"A simple sitemap can be rendered"
@@ -59,9 +65,9 @@ class SitemapTests(TestCase):
# Check for all the important bits:
self.assertEquals(response.content, """
-http://example.com/location/%snever0.5
+%s/location/%snever0.5
-""" % date.today().strftime('%Y-%m-%d'))
+""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
def test_simple_custom_sitemap(self):
"A simple sitemap can be rendered with a custom template"
@@ -71,9 +77,9 @@ class SitemapTests(TestCase):
self.assertEquals(response.content, """
-http://example.com/location/%snever0.5
+%s/location/%snever0.5
-""" % date.today().strftime('%Y-%m-%d'))
+""" % (self.base_url, date.today().strftime('%Y-%m-%d')))
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
def test_localized_priority(self):
@@ -97,13 +103,13 @@ class SitemapTests(TestCase):
expected = ''
for username in User.objects.values_list("username", flat=True):
- expected += "http://example.com/users/%s/" %username
+ expected += "%s/users/%s/" % (self.base_url, username)
# Check for all the important bits:
self.assertEquals(response.content, """
%s
-""" %expected)
+""" % expected)
@skipUnless("django.contrib.flatpages" in settings.INSTALLED_APPS, "django.contrib.flatpages app not installed.")
def test_flatpage_sitemap(self):
@@ -131,9 +137,9 @@ class SitemapTests(TestCase):
private.sites.add(settings.SITE_ID)
response = self.client.get('/flatpages/sitemap.xml')
# Public flatpage should be in the sitemap
- self.assertContains(response, 'http://example.com%s' % public.url)
+ self.assertContains(response, '%s%s' % (self.base_url, public.url))
# Private flatpage should not be in the sitemap
- self.assertNotContains(response, 'http://example.com%s' % private.url)
+ self.assertNotContains(response, '%s%s' % (self.base_url, private.url))
def test_requestsite_sitemap(self):
# Make sure hitting the flatpages sitemap without the sites framework
@@ -148,12 +154,12 @@ class SitemapTests(TestCase):
""" % date.today().strftime('%Y-%m-%d'))
+ @skipUnless("django.contrib.sites" in settings.INSTALLED_APPS, "django.contrib.sites app not installed.")
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)
@@ -163,6 +169,5 @@ class SitemapTests(TestCase):
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)