From b547c426612354536ab884d59661b0d3ef70c0c1 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 23 May 2020 14:58:17 +0200 Subject: [PATCH] Improved HTTPSitemapTests.test_localized_priority. Override setting instead of skipping. Use translation override context manager to avoid language leaking. --- tests/sitemaps_tests/test_http.py | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index e757170241..67fc264e04 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -1,14 +1,12 @@ import os from datetime import date -from unittest import skipUnless -from django.conf import settings from django.contrib.sitemaps import Sitemap from django.contrib.sites.models import Site from django.core.exceptions import ImproperlyConfigured from django.test import modify_settings, override_settings +from django.utils import translation from django.utils.formats import localize -from django.utils.translation import activate, deactivate from .base import SitemapTestsBase from .models import TestModel @@ -177,18 +175,15 @@ class HTTPSitemapTests(SitemapTestsBase): response = self.client.get('/lastmod-sitemaps/descending.xml') self.assertEqual(response['Last-Modified'], 'Sat, 20 Apr 2013 05:00:00 GMT') - @skipUnless(settings.USE_I18N, "Internationalization is not enabled") - @override_settings(USE_L10N=True) + @override_settings(USE_I18N=True, USE_L10N=True) def test_localized_priority(self): - "The priority value should not be localized (Refs #14164)" - activate('fr') - self.assertEqual('0,3', localize(0.3)) - - # Priorities haven't been rendered in localized format. - response = self.client.get('/simple/sitemap.xml') - self.assertContains(response, '0.5') - self.assertContains(response, '%s' % date.today()) - deactivate() + """The priority value should not be localized.""" + with translation.override('fr'): + self.assertEqual('0,3', localize(0.3)) + # Priorities aren't rendered in localized format. + response = self.client.get('/simple/sitemap.xml') + self.assertContains(response, '0.5') + self.assertContains(response, '%s' % date.today()) @modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}) def test_requestsite_sitemap(self):