summaryrefslogtreecommitdiff
path: root/tests/cache/tests.py
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-03-21 18:48:57 +0100
committerTim Graham <timograham@gmail.com>2014-07-24 19:27:15 -0400
commit83098dccdf3172302cde54e11c36050c1d83f996 (patch)
treed605ddda1af05413142d854ad23af46ab344a835 /tests/cache/tests.py
parent290e389fe9f8321babc2dfa55fcb7ac4ceb9524b (diff)
[1.6.x] Fixed #23089 -- Fixed transaction handling in two management commands.
Previously, when createcachetable and flush operated on non-default databases, they weren't atomic. Also avoided transactional DDL and transactional truncates on databases that don't support them (refs #22308). Backport of 753a22a635, 0757e0f30d, and 6877a9d415 from master
Diffstat (limited to 'tests/cache/tests.py')
-rw-r--r--tests/cache/tests.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index 04ef21b851..b3374ab497 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -20,7 +20,7 @@ from django.core.cache import get_cache
from django.core.cache.backends.base import (CacheKeyWarning,
InvalidCacheBackendError)
from django.core.context_processors import csrf
-from django.db import router, transaction
+from django.db import connections, router, transaction
from django.core.cache.utils import make_template_fragment_key
from django.http import (HttpResponse, HttpRequest, StreamingHttpResponse,
QueryDict)
@@ -912,9 +912,16 @@ class CreateCacheTableForDBCacheTests(TestCase):
database='default',
verbosity=0, interactive=False)
# cache table should be created on 'other'
- # one query is used to create the table and another one the index
- with self.assertNumQueries(2, using='other'):
- management.call_command('createcachetable', 'cache_table',
+ # Queries:
+ # 1: create savepoint (if transactional DDL is supported)
+ # 2: create the table
+ # 3: create the index
+ # 4: release savepoint (if transactional DDL is supported)
+ from django.db import connections
+ num = 4 if connections['other'].features.can_rollback_ddl else 2
+ with self.assertNumQueries(num, using='other'):
+ management.call_command('createcachetable',
+ 'cache_table',
database='other',
verbosity=0, interactive=False)
finally:
@@ -1958,4 +1965,3 @@ class TestMakeTemplateFragmentKey(TestCase):
key = make_template_fragment_key('spam', ['abc:def%'])
self.assertEqual(key,
'template.cache.spam.f27688177baec990cdf3fbd9d9c3f469')
-