authentik.admin.tests.test_system_settings_cache

 1from django.test import TestCase
 2
 3from authentik.admin.models import SystemSettings
 4from authentik.admin.utils import get_system_settings
 5
 6
 7class TestSystemSettingsCache(TestCase):
 8    def test_cached(self):
 9        """Settings are cached across calls"""
10        self.assertIs(get_system_settings(), get_system_settings())
11
12    def test_cleared_on_save(self):
13        """Saving the settings drops the cached instance"""
14        first = get_system_settings()
15        settings = SystemSettings.objects.get(pk=True)
16        settings.avatars = "none"
17        settings.save()
18        second = get_system_settings()
19        self.assertIsNot(first, second)
20        self.assertEqual(second.avatars, "none")
class TestSystemSettingsCache(django.test.testcases.TestCase):
 8class TestSystemSettingsCache(TestCase):
 9    def test_cached(self):
10        """Settings are cached across calls"""
11        self.assertIs(get_system_settings(), get_system_settings())
12
13    def test_cleared_on_save(self):
14        """Saving the settings drops the cached instance"""
15        first = get_system_settings()
16        settings = SystemSettings.objects.get(pk=True)
17        settings.avatars = "none"
18        settings.save()
19        second = get_system_settings()
20        self.assertIsNot(first, second)
21        self.assertEqual(second.avatars, "none")

Similar to TransactionTestCase, but use transaction.atomic() to achieve test isolation.

In most situations, TestCase should be preferred to TransactionTestCase as it allows faster execution. However, there are some situations where using TransactionTestCase might be necessary (e.g. testing some transactional behavior).

On database backends with no transaction support, TestCase behaves as TransactionTestCase.

def test_cached(self):
 9    def test_cached(self):
10        """Settings are cached across calls"""
11        self.assertIs(get_system_settings(), get_system_settings())

Settings are cached across calls

def test_cleared_on_save(self):
13    def test_cleared_on_save(self):
14        """Saving the settings drops the cached instance"""
15        first = get_system_settings()
16        settings = SystemSettings.objects.get(pk=True)
17        settings.avatars = "none"
18        settings.save()
19        second = get_system_settings()
20        self.assertIsNot(first, second)
21        self.assertEqual(second.avatars, "none")

Saving the settings drops the cached instance