Made sitemaps tests use override_settings. Refs #14478
This commit is contained in:
parent
566ac30eb9
commit
7676d6e764
|
@ -1,6 +1,3 @@
|
||||||
import os
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
@ -13,16 +10,9 @@ class SitemapTestsBase(TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.base_url = '%s://%s' % (self.protocol, self.domain)
|
self.base_url = '%s://%s' % (self.protocol, self.domain)
|
||||||
self.old_USE_L10N = settings.USE_L10N
|
|
||||||
self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
|
|
||||||
settings.TEMPLATE_DIRS = (
|
|
||||||
os.path.join(os.path.dirname(__file__), 'templates'),
|
|
||||||
)
|
|
||||||
self.old_Site_meta_installed = Site._meta.installed
|
self.old_Site_meta_installed = Site._meta.installed
|
||||||
# Create a user that will double as sitemap content
|
# Create a user that will double as sitemap content
|
||||||
User.objects.create_user('testuser', 'test@example.com', 's3krit')
|
User.objects.create_user('testuser', 'test@example.com', 's3krit')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
settings.USE_L10N = self.old_USE_L10N
|
|
||||||
settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS
|
|
||||||
Site._meta.installed = self.old_Site_meta_installed
|
Site._meta.installed = self.old_Site_meta_installed
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
|
import os
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.sitemaps import Sitemap, GenericSitemap
|
from django.contrib.sitemaps import Sitemap, GenericSitemap
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
|
from django.test.utils import override_settings
|
||||||
from django.utils.unittest import skipUnless
|
from django.utils.unittest import skipUnless
|
||||||
from django.utils.formats import localize
|
from django.utils.formats import localize
|
||||||
from django.utils.translation import activate, deactivate
|
from django.utils.translation import activate, deactivate
|
||||||
|
|
||||||
from .base import SitemapTestsBase
|
from .base import SitemapTestsBase
|
||||||
|
|
||||||
|
|
||||||
class HTTPSitemapTests(SitemapTestsBase):
|
class HTTPSitemapTests(SitemapTestsBase):
|
||||||
|
|
||||||
def test_simple_sitemap_index(self):
|
def test_simple_sitemap_index(self):
|
||||||
|
@ -21,6 +25,9 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
""" % self.base_url)
|
""" % self.base_url)
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
||||||
|
)
|
||||||
def test_simple_sitemap_custom_index(self):
|
def test_simple_sitemap_custom_index(self):
|
||||||
"A simple sitemap index can be rendered with a custom template"
|
"A simple sitemap index can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-index.xml')
|
response = self.client.get('/simple/custom-index.xml')
|
||||||
|
@ -49,6 +56,9 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
</urlset>
|
</urlset>
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today()))
|
||||||
|
|
||||||
|
@override_settings(
|
||||||
|
TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
|
||||||
|
)
|
||||||
def test_simple_custom_sitemap(self):
|
def test_simple_custom_sitemap(self):
|
||||||
"A simple sitemap can be rendered with a custom template"
|
"A simple sitemap can be rendered with a custom template"
|
||||||
response = self.client.get('/simple/custom-sitemap.xml')
|
response = self.client.get('/simple/custom-sitemap.xml')
|
||||||
|
@ -60,10 +70,9 @@ class HTTPSitemapTests(SitemapTestsBase):
|
||||||
""" % (self.base_url, date.today()))
|
""" % (self.base_url, date.today()))
|
||||||
|
|
||||||
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
|
@skipUnless(settings.USE_I18N, "Internationalization is not enabled")
|
||||||
|
@override_settings(USE_L10N=True)
|
||||||
def test_localized_priority(self):
|
def test_localized_priority(self):
|
||||||
"The priority value should not be localized (Refs #14164)"
|
"The priority value should not be localized (Refs #14164)"
|
||||||
# Localization should be active
|
|
||||||
settings.USE_L10N = True
|
|
||||||
activate('fr')
|
activate('fr')
|
||||||
self.assertEqual(u'0,3', localize(0.3))
|
self.assertEqual(u'0,3', localize(0.3))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue