~ubuntu-branches/ubuntu/quantal/python-django/quantal-security

« back to all changes in this revision

Viewing changes to django/contrib/sitemaps/tests/basic.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (1.2.7 upstream)
  • mto: This revision was merged to the branch mainline in revision 30.
  • Revision ID: james.westby@ubuntu.com-20101012113435-9lnsrh0i3mxozbt0
Tags: upstream-1.2.3
ImportĀ upstreamĀ versionĀ 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
7
 
 
8
 
 
9
class SitemapTests(TestCase):
 
10
    urls = 'django.contrib.sitemaps.tests.urls'
 
11
 
 
12
    def setUp(self):
 
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')
 
16
 
 
17
    def tearDown(self):
 
18
        settings.USE_L10N = self.old_USE_L10N
 
19
 
 
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>
 
28
</urlset>
 
29
""" % date.today().strftime('%Y-%m-%d'))
 
30
 
 
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
 
35
        activate('fr')
 
36
        self.assertEqual(u'0,3', localize(0.3))
 
37
 
 
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'))
 
43
 
 
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>
 
52
</urlset>
 
53
""")