mirror of
https://github.com/Hopiu/django-cachalot.git
synced 2026-05-10 13:44:44 +00:00
Creates a MySQL cursor before each test to avoid the extra SET SQL_AUTO_IS_NULL = 0 request.
This commit is contained in:
parent
d9e19a8ca5
commit
d2b03e5d8d
4 changed files with 25 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ try:
|
|||
except ImportError: # For Python 2.6
|
||||
from unittest2 import skipIf
|
||||
|
||||
from django import VERSION as django_version
|
||||
from django.conf import settings
|
||||
from django.core.cache import DEFAULT_CACHE_ALIAS
|
||||
from django.db import connection
|
||||
|
|
@ -16,6 +17,12 @@ from .models import Test
|
|||
|
||||
|
||||
class SettingsTestCase(TransactionTestCase):
|
||||
def setUp(self):
|
||||
if django_version >= (1, 7) and connection.vendor == 'mysql':
|
||||
# We need to reopen the connection or Django
|
||||
# will execute an extra SQL request below.
|
||||
connection.cursor()
|
||||
|
||||
@override_settings(CACHALOT_ENABLED=False)
|
||||
def test_decorator(self):
|
||||
with self.assertNumQueries(1):
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
from __future__ import unicode_literals
|
||||
from threading import Thread
|
||||
|
||||
from django import VERSION as django_version
|
||||
from django.db import connection, transaction
|
||||
from django.test import TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
|
|
@ -22,6 +23,12 @@ class TestThread(Thread):
|
|||
|
||||
@skipUnlessDBFeature('test_db_allows_multiple_connections')
|
||||
class ThreadSafetyTestCase(TransactionTestCase):
|
||||
def setUp(self):
|
||||
if django_version >= (1, 7) and connection.vendor == 'mysql':
|
||||
# We need to reopen the connection or Django
|
||||
# will execute an extra SQL request below.
|
||||
connection.cursor()
|
||||
|
||||
def test_concurrent_caching(self):
|
||||
t1 = TestThread().start_and_join()
|
||||
t = Test.objects.create(name='test')
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django import VERSION as django_version
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import connection, transaction
|
||||
from django.test import TransactionTestCase
|
||||
|
|
@ -10,6 +11,12 @@ from .models import Test
|
|||
|
||||
|
||||
class AtomicTestCase(TransactionTestCase):
|
||||
def setUp(self):
|
||||
if django_version >= (1, 7) and connection.vendor == 'mysql':
|
||||
# We need to reopen the connection or Django
|
||||
# will execute an extra SQL request below.
|
||||
connection.cursor()
|
||||
|
||||
def test_successful_read_atomic(self):
|
||||
is_sqlite = connection.vendor == 'sqlite'
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,10 @@ class WriteTestCase(TransactionTestCase):
|
|||
|
||||
def setUp(self):
|
||||
self.is_sqlite = connection.vendor == 'sqlite'
|
||||
if django_version >= (1, 7) and connection.vendor == 'mysql':
|
||||
# We need to reopen the connection or Django
|
||||
# will execute an extra SQL request below.
|
||||
connection.cursor()
|
||||
|
||||
def test_create(self):
|
||||
with self.assertNumQueries(1):
|
||||
|
|
|
|||
Loading…
Reference in a new issue