1
from datetime import date
2
from django.conf import settings
3
from django.contrib.auth.models import User
4
from django.test import TestCase
5
from django.utils.formats import localize
6
from django.utils.translation import activate
9
class SitemapTests(TestCase):
10
urls = 'django.contrib.sitemaps.tests.urls'
13
self.old_USE_L10N = settings.USE_L10N
14
# Create a user that will double as sitemap content
15
User.objects.create_user('testuser', 'test@example.com', 's3krit')
18
settings.USE_L10N = self.old_USE_L10N
20
def test_simple_sitemap(self):
21
"A simple sitemap can be rendered"
22
# Retrieve the sitemap.
23
response = self.client.get('/simple/sitemap.xml')
24
# Check for all the important bits:
25
self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
26
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
27
<url><loc>http://example.com/location/</loc><lastmod>%s</lastmod><changefreq>never</changefreq><priority>0.5</priority></url>
29
""" % date.today().strftime('%Y-%m-%d'))
31
def test_localized_priority(self):
32
"The priority value should not be localized (Refs #14164)"
33
# Localization should be active
34
settings.USE_L10N = True
36
self.assertEqual(u'0,3', localize(0.3))
38
# Retrieve the sitemap. Check that priorities
39
# haven't been rendered in localized format
40
response = self.client.get('/simple/sitemap.xml')
41
self.assertContains(response, '<priority>0.5</priority>')
42
self.assertContains(response, '<lastmod>%s</lastmod>' % date.today().strftime('%Y-%m-%d'))
44
def test_generic_sitemap(self):
45
"A minimal generic sitemap can be rendered"
46
# Retrieve the sitemap.
47
response = self.client.get('/generic/sitemap.xml')
48
# Check for all the important bits:
49
self.assertEquals(response.content, """<?xml version="1.0" encoding="UTF-8"?>
50
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
51
<url><loc>http://example.com/users/testuser/</loc></url>