From 03f00bcd4240f13e6ffe5d8b6688b8a289cb6f8f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 12 Oct 2010 07:15:47 +0000 Subject: [PATCH] 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 --- django/contrib/auth/tests/decorators.py | 7 ++++--- django/contrib/sitemaps/tests/basic.py | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/django/contrib/auth/tests/decorators.py b/django/contrib/auth/tests/decorators.py index 0240a76eb79..2aafeaac162 100644 --- a/django/contrib/auth/tests/decorators.py +++ b/django/contrib/auth/tests/decorators.py @@ -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/') \ No newline at end of file + login_url='/somewhere/') diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py index b2de75f0983..34541c2c972 100644 --- a/django/contrib/sitemaps/tests/basic.py +++ b/django/contrib/sitemaps/tests/basic.py @@ -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 += "http://example.com/users/%s/" %username # Check for all the important bits: self.assertEquals(response.content, """ -http://example.com/users/testuser/ +%s -""") +""" %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: