From 46fab8983e65955129ea24549c9341fd8c486ce0 Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Fri, 27 Aug 2010 15:16:04 +0000 Subject: [PATCH] Fixed #14164 -- Ensure that sitemap priorities aren't rendered with localized numerical formats. Thanks to dokterbob for the report, and vung for the draft patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@13644 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/sitemaps/__init__.py | 2 +- django/contrib/sitemaps/tests/__init__.py | 1 + django/contrib/sitemaps/tests/basic.py | 39 +++++++++++++++++++++++ django/contrib/sitemaps/tests/urls.py | 20 ++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 django/contrib/sitemaps/tests/__init__.py create mode 100644 django/contrib/sitemaps/tests/basic.py create mode 100644 django/contrib/sitemaps/tests/urls.py diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index f877317f16..45b85c81d0 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -69,7 +69,7 @@ class Sitemap(object): 'location': loc, 'lastmod': self.__get('lastmod', item, None), 'changefreq': self.__get('changefreq', item, None), - 'priority': self.__get('priority', item, None) + 'priority': str(self.__get('priority', item, '')) } urls.append(url_info) return urls diff --git a/django/contrib/sitemaps/tests/__init__.py b/django/contrib/sitemaps/tests/__init__.py new file mode 100644 index 0000000000..c5b483cde2 --- /dev/null +++ b/django/contrib/sitemaps/tests/__init__.py @@ -0,0 +1 @@ +from django.contrib.sitemaps.tests.basic import * diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py new file mode 100644 index 0000000000..695b84a0ae --- /dev/null +++ b/django/contrib/sitemaps/tests/basic.py @@ -0,0 +1,39 @@ +from datetime import date +from django.conf import settings +from django.test import TestCase +from django.utils.formats import localize +from django.utils.translation import activate + + +class SitemapTests(TestCase): + urls = 'django.contrib.sitemaps.tests.urls' + + def setUp(self): + self.old_USE_L10N = settings.USE_L10N + + def tearDown(self): + settings.USE_L10N = self.old_USE_L10N + + def test_simple_sitemap(self): + "A simple sitemap can be rendered" + # Retrieve the sitemap. + response = self.client.get('/sitemaps/sitemap.xml') + # Check for all the important bits: + self.assertEquals(response.content, """ + +http://example.com/ticket14164%snever0.5 + +""" % date.today().strftime('%Y-%m-%d')) + + def test_localized_priority(self): + "The priority value should not be localized (Refs #14164)" + # Localization should be active + settings.USE_L10N = True + activate('fr') + self.assertEqual(u'0,3', localize(0.3)) + + # Retrieve the sitemap. Check that priorities + # haven't been rendered in localized format + response = self.client.get('/sitemaps/sitemap.xml') + self.assertContains(response, '0.5') + self.assertContains(response, '%s' % date.today().strftime('%Y-%m-%d')) diff --git a/django/contrib/sitemaps/tests/urls.py b/django/contrib/sitemaps/tests/urls.py new file mode 100644 index 0000000000..b29b5a6a49 --- /dev/null +++ b/django/contrib/sitemaps/tests/urls.py @@ -0,0 +1,20 @@ +from datetime import datetime +from django.conf.urls.defaults import * +from django.contrib.sitemaps import Sitemap + +class SimpleSitemap(Sitemap): + changefreq = "never" + priority = 0.5 + location = '/ticket14164' + lastmod = datetime.now() + + def items(self): + return [object()] + +sitemaps = { + 'simple': SimpleSitemap, +} + +urlpatterns = patterns('django.contrib.sitemaps.views', + (r'^sitemaps/sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}), +)