Debian Codegraph @

tests/sitemaps_tests/base.py

raw
1 from django.apps import apps
2 from django.contrib.sites.models import Site
3 from django.core.cache import cache
4 from django.test import TestCase, modify_settings, override_settings
5
6 from .models import I18nTestModel, TestModel
7
8
9 @modify_settings(INSTALLED_APPS={"append": "django.contrib.sitemaps"})
10 @override_settings(ROOT_URLCONF="sitemaps_tests.urls.http")
11 class SitemapTestsBase(TestCase):
12 protocol = "http"
13 sites_installed = apps.is_installed("django.contrib.sites")
14 domain = "example.com" if sites_installed else "testserver"
15
16 @classmethod
17 def setUpTestData(cls):
18 # Create an object for sitemap content.
19 TestModel.objects.create(name="Test Object")
20 cls.i18n_model = I18nTestModel.objects.create(name="Test Object")
21
22 def setUp(self):
23 self.base_url = "%s://%s" % (self.protocol, self.domain)
24 cache.clear()
25
26 @classmethod
27 def setUpClass(cls):
28 super().setUpClass()
29 # This cleanup is necessary because contrib.sites cache
30 # makes tests interfere with each other, see #11505
31 Site.objects.clear_cache()