Ticket #14164: 14164_l10n_sitemaps.diff

File 14164_l10n_sitemaps.diff, 3.9 KB (added by vung, 14 years ago)

Convert priority to str

  • django/contrib/sitemaps/__init__.py

     
    6969                'location':   loc,
    7070                'lastmod':    self.__get('lastmod', item, None),
    7171                'changefreq': self.__get('changefreq', item, None),
    72                 'priority':   self.__get('priority', item, None)
     72                'priority':   str(self.__get('priority', item, ''))
    7373            }
    7474            urls.append(url_info)
    7575        return urls
  • tests/regressiontests/sitemaps/tests.py

     
     1from xml.dom.minidom import parseString
     2
     3from django.conf import settings
     4from django.test import TestCase
     5from django.utils.formats import localize
     6from django.utils.translation import activate
     7
     8
     9class LocalizationTests(TestCase):
     10
     11    def setUp(self):
     12        self.orig_use_l10n = settings.USE_L10N
     13
     14    def tearDown(self):
     15        settings.USE_L10N = self.orig_use_l10n
     16
     17    def test_localized_priority(self):
     18        """The priority value should not be localized (#14164)"""
     19        settings.USE_L10N = True
     20        activate('fr')
     21        # Localization should be active now:
     22        self.assertEqual(u'0,3', localize(0.3))
     23        # Retrieve an item with a known priority and check it:
     24        response = self.client.get('/sitemaps/sitemap.xml')
     25        doc = parseString(response.content)
     26        priority = None
     27        for elt in doc.getElementsByTagName('url'):
     28            loc = elt.childNodes[0].childNodes[0].nodeValue
     29            if loc.endswith('/ticket14164'):
     30                priority = elt.childNodes[3].childNodes[0].nodeValue
     31                break
     32        self.assertEqual(u'0.5', priority)
  • tests/regressiontests/sitemaps/urls.py

     
     1from django.conf.urls.defaults import *
     2
     3from sitemaps import SimpleSitemap
     4
     5
     6sitemaps = {
     7    'simple': SimpleSitemap,
     8}
     9
     10
     11urlpatterns = patterns('django.contrib.sitemaps.views',
     12    (r'^sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
     13)
  • tests/regressiontests/sitemaps/sitemaps.py

     
     1from datetime import datetime
     2from django.contrib.sitemaps import Sitemap
     3
     4
     5class SimpleSitemap(Sitemap):
     6    changefreq = "never"
     7    priority = 0.5
     8    location = '/ticket14164'
     9    lastmod = datetime.now()
     10
     11    def items(self):
     12        return [object()]
  • tests/urls.py

     
    4141
    4242    # special headers views
    4343    (r'special_headers/', include('regressiontests.special_headers.urls')),
     44
     45    # sitemaps
     46    (r'^sitemaps/', include('regressiontests.sitemaps.urls')),
    4447)
  • tests/runtests.py

     
    2828    'django.contrib.comments',
    2929    'django.contrib.admin',
    3030    'django.contrib.admindocs',
     31    'django.contrib.sitemaps',
    3132]
    3233
    3334def get_test_models():
Back to Top