mirror of
https://github.com/django/django.git
synced 2025-07-05 02:09:13 +00:00
[1.2.X] Modified the sitemaps tests to remove an assumption about the environment in which the tests are run. Thanks to Gabriel Hurley for the report and patch.
Backport of r14184 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14185 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9b077ee4b6
commit
23ecf3cf6c
@ -1,7 +1,6 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.flatpages.models import FlatPage
|
|
||||||
from django.contrib.sitemaps import Sitemap
|
from django.contrib.sitemaps import Sitemap
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
@ -52,40 +51,51 @@ class SitemapTests(TestCase):
|
|||||||
"A minimal generic sitemap can be rendered"
|
"A minimal generic sitemap can be rendered"
|
||||||
# Retrieve the sitemap.
|
# Retrieve the sitemap.
|
||||||
response = self.client.get('/generic/sitemap.xml')
|
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:
|
# Check for all the important bits:
|
||||||
self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
<url><loc>http://example.com/users/testuser/</loc></url>
|
%s
|
||||||
</urlset>
|
</urlset>
|
||||||
""")
|
""" %expected)
|
||||||
|
|
||||||
def test_flatpage_sitemap(self):
|
if "django.contrib.flatpages" in settings.INSTALLED_APPS:
|
||||||
"Basic FlatPage sitemap test"
|
def test_flatpage_sitemap(self):
|
||||||
public = FlatPage.objects.create(
|
"Basic FlatPage sitemap test"
|
||||||
url=u'/public/',
|
|
||||||
title=u'Public Page',
|
# Import FlatPage inside the test so that when django.contrib.flatpages
|
||||||
enable_comments=True,
|
# is not installed we don't get problems trying to delete Site
|
||||||
registration_required=False,
|
# objects (FlatPage has an M2M to Site, Site.delete() tries to
|
||||||
)
|
# delete related objects, but the M2M table doesn't exist.
|
||||||
public.sites.add(settings.SITE_ID)
|
from django.contrib.flatpages.models import FlatPage
|
||||||
private = FlatPage.objects.create(
|
|
||||||
url=u'/private/',
|
public = FlatPage.objects.create(
|
||||||
title=u'Private Page',
|
url=u'/public/',
|
||||||
enable_comments=True,
|
title=u'Public Page',
|
||||||
registration_required=True
|
enable_comments=True,
|
||||||
)
|
registration_required=False,
|
||||||
private.sites.add(settings.SITE_ID)
|
)
|
||||||
response = self.client.get('/flatpages/sitemap.xml')
|
public.sites.add(settings.SITE_ID)
|
||||||
# Public flatpage should be in the sitemap
|
private = FlatPage.objects.create(
|
||||||
self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url)
|
url=u'/private/',
|
||||||
# Private flatpage should not be in the sitemap
|
title=u'Private Page',
|
||||||
self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
|
enable_comments=True,
|
||||||
|
registration_required=True
|
||||||
|
)
|
||||||
|
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)
|
||||||
|
# Private flatpage should not be in the sitemap
|
||||||
|
self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
|
||||||
|
|
||||||
def test_requestsite_sitemap(self):
|
def test_requestsite_sitemap(self):
|
||||||
# Make sure hitting the flatpages sitemap without the sites framework
|
# Make sure hitting the flatpages sitemap without the sites framework
|
||||||
# installed doesn't raise an exception
|
# installed doesn't raise an exception
|
||||||
Site._meta.installed = False
|
Site._meta.installed = False
|
||||||
response = self.client.get('/flatpages/sitemap.xml')
|
|
||||||
# Retrieve the sitemap.
|
# Retrieve the sitemap.
|
||||||
response = self.client.get('/simple/sitemap.xml')
|
response = self.client.get('/simple/sitemap.xml')
|
||||||
# Check for all the important bits:
|
# Check for all the important bits:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user