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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14184 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5506653b77
commit
03f00bcd42
|
@ -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 @@ class LoginRequiredTestCase(AuthViewsTestCase):
|
|||
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 @@ class LoginRequiredTestCase(AuthViewsTestCase):
|
|||
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 @@ class LoginRequiredTestCase(AuthViewsTestCase):
|
|||
login_required decorator with a login_url set.
|
||||
"""
|
||||
self.testLoginRequired(view_url='/login_required_login_url/',
|
||||
login_url='/somewhere/')
|
||||
login_url='/somewhere/')
|
||||
|
|
|
@ -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 @@ class SitemapTests(TestCase):
|
|||
"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 @@ class SitemapTests(TestCase):
|
|||
# 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:
|
||||
|
|
Loading…
Reference in New Issue