2015-02-10 13:11:25 +00:00
|
|
|
from django.apps import apps
|
2015-02-16 13:02:49 +00:00
|
|
|
from django.contrib.sites.models import Site
|
2015-02-10 13:11:25 +00:00
|
|
|
from django.core.cache import cache
|
|
|
|
from django.test import TestCase, modify_settings, override_settings
|
|
|
|
|
|
|
|
from .models import I18nTestModel, TestModel
|
|
|
|
|
|
|
|
|
2022-02-03 19:24:19 +00:00
|
|
|
@modify_settings(INSTALLED_APPS={"append": "django.contrib.sitemaps"})
|
|
|
|
@override_settings(ROOT_URLCONF="sitemaps_tests.urls.http")
|
2015-02-10 13:11:25 +00:00
|
|
|
class SitemapTestsBase(TestCase):
|
2022-02-03 19:24:19 +00:00
|
|
|
protocol = "http"
|
|
|
|
sites_installed = apps.is_installed("django.contrib.sites")
|
|
|
|
domain = "example.com" if sites_installed else "testserver"
|
2015-02-10 13:11:25 +00:00
|
|
|
|
2018-11-24 01:59:38 +00:00
|
|
|
@classmethod
|
|
|
|
def setUpTestData(cls):
|
|
|
|
# Create an object for sitemap content.
|
2022-02-03 19:24:19 +00:00
|
|
|
TestModel.objects.create(name="Test Object")
|
|
|
|
cls.i18n_model = I18nTestModel.objects.create(name="Test Object")
|
2018-11-24 01:59:38 +00:00
|
|
|
|
2015-02-10 13:11:25 +00:00
|
|
|
def setUp(self):
|
2022-02-03 19:24:19 +00:00
|
|
|
self.base_url = "%s://%s" % (self.protocol, self.domain)
|
2015-02-10 13:11:25 +00:00
|
|
|
cache.clear()
|
2015-02-16 13:02:49 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2017-01-21 13:13:44 +00:00
|
|
|
super().setUpClass()
|
2015-02-16 13:02:49 +00:00
|
|
|
# This cleanup is necessary because contrib.sites cache
|
|
|
|
# makes tests interfere with each other, see #11505
|
|
|
|
Site.objects.clear_cache()
|