Permalink
Browse files

Fixed #14447 -- Modified the auth and sitemaps tests to remove some a…

…ssumptions 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
  • Loading branch information...
freakboy3742 committed Oct 12, 2010
1 parent 5506653 commit 03f00bcd4240f13e6ffe5d8b6688b8a289cb6f8f
Showing with 19 additions and 7 deletions.
  1. +4 −3 django/contrib/auth/tests/decorators.py
  2. +15 −4 django/contrib/sitemaps/tests/basic.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 CallableView(object):
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 @@ def normal_view(request):
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 @@ def testLoginRequiredNextUrl(self):
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 @@ def test_generic_sitemap(self):
"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 @@ def test_requestsite_sitemap(self):
# 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:

0 comments on commit 03f00bc

Please sign in to comment.