|
1 | 1 | import os |
2 | 2 | import shutil |
3 | 3 | import tempfile |
| 4 | +from unittest import mock |
4 | 5 |
|
5 | 6 | from django.conf import settings as django_settings |
6 | 7 | from django.core.cache.backends.base import BaseCache |
@@ -151,3 +152,24 @@ def test_check_template_syntax(self): |
151 | 152 | def test_get_cache_name(self): |
152 | 153 | self.assertEqual(get_cache_key('name with spaces'), |
153 | 154 | 'dbtemplates::name-with-spaces::1') |
| 155 | + |
| 156 | + def test_cache_invalidation(self): |
| 157 | + # Add t1 into the cache of site2 |
| 158 | + self.t1.sites.add(self.site2) |
| 159 | + with mock.patch('django.contrib.sites.models.SiteManager.get_current', |
| 160 | + return_value=self.site2): |
| 161 | + result = loader.get_template("base.html").render() |
| 162 | + self.assertEqual(result, 'base') |
| 163 | + |
| 164 | + # Update content |
| 165 | + self.t1.content = 'new content' |
| 166 | + self.t1.save() |
| 167 | + result = loader.get_template("base.html").render() |
| 168 | + self.assertEqual(result, 'new content') |
| 169 | + |
| 170 | + # Cache invalidation should work across sites. |
| 171 | + # Site2 should see the new content. |
| 172 | + with mock.patch('django.contrib.sites.models.SiteManager.get_current', |
| 173 | + return_value=self.site2): |
| 174 | + result = loader.get_template("base.html").render() |
| 175 | + self.assertEqual(result, 'new content') |
0 commit comments