|
|
@@ -1,6 +1,6 @@
|
|
|
from unittest import mock
|
|
|
|
|
|
-from django.test import TestCase
|
|
|
+from django.test import TestCase, override_settings
|
|
|
|
|
|
from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
|
|
|
from extras.cache import invalidate_config_context_for_objects
|
|
|
@@ -202,3 +202,34 @@ class CacheHelperTest(TestCase):
|
|
|
|
|
|
def test_invalidate_with_empty_args_is_noop(self):
|
|
|
invalidate_config_context_for_objects('dcim.device', [])
|
|
|
+
|
|
|
+
|
|
|
+@override_settings(CONFIGCONTEXT_CACHING=False)
|
|
|
+class ConfigContextCachingDisabledTest(TestCase):
|
|
|
+ """
|
|
|
+ With the CONFIGCONTEXT_CACHING feature flag off, reads must always render on demand (ignoring
|
|
|
+ any pre-rendered cache) and invalidation must be a no-op.
|
|
|
+ """
|
|
|
+
|
|
|
+ @classmethod
|
|
|
+ def setUpTestData(cls):
|
|
|
+ manufacturer = Manufacturer.objects.create(name='Mfr', slug='mfr')
|
|
|
+ devicetype = DeviceType.objects.create(manufacturer=manufacturer, model='DT', slug='dt')
|
|
|
+ role = DeviceRole.objects.create(name='Role', slug='role')
|
|
|
+ site = Site.objects.create(name='Site', slug='site')
|
|
|
+ cls.device = Device.objects.create(
|
|
|
+ name='Device', device_type=devicetype, role=role, site=site,
|
|
|
+ )
|
|
|
+ ConfigContext.objects.create(name='CC', weight=100, data={'rendered': True})
|
|
|
+
|
|
|
+ def test_read_ignores_cache_and_renders_on_demand(self):
|
|
|
+ # Even with a (stale) populated cache, the read path renders on demand.
|
|
|
+ _set_cache(self.device, {'stale': 'value'})
|
|
|
+ device = Device.objects.get(pk=self.device.pk)
|
|
|
+ self.assertEqual(device.get_config_context(), {'rendered': True})
|
|
|
+
|
|
|
+ def test_invalidation_is_noop(self):
|
|
|
+ _set_cache(self.device, {'cached': True})
|
|
|
+ invalidate_config_context_for_objects('dcim.device', [self.device.pk])
|
|
|
+ # Cache is left untouched; no background job machinery runs.
|
|
|
+ self.assertEqual(_get_cache(self.device), {'cached': True})
|