Author: ramiro
Date: 2012-03-13 10:52:48 -0700 (Tue, 13 Mar 2012)
New Revision: 17702

Modified:
   django/trunk/django/db/backends/sqlite3/creation.py
   django/trunk/tests/regressiontests/test_runner/tests.py
Log:
Fixed #16329 -- Fixed detection of transaction-handling capabilities when all 
test databases are sqlite3, in-memory.

Thanks canassa for the report and agriffis (#17762) and lrekucki (in #17758) 
for their contribution to the fix.

Modified: django/trunk/django/db/backends/sqlite3/creation.py
===================================================================
--- django/trunk/django/db/backends/sqlite3/creation.py 2012-03-13 17:35:00 UTC 
(rev 17701)
+++ django/trunk/django/db/backends/sqlite3/creation.py 2012-03-13 17:52:48 UTC 
(rev 17702)
@@ -72,3 +72,18 @@
 
     def set_autocommit(self):
         self.connection.connection.isolation_level = None
+
+    def test_db_signature(self):
+        """
+        Returns a tuple that uniquely identifies a test database.
+
+        This takes into account the special cases of ":memory:" and "" for
+        SQLite since the databases will be distinct despite having the same
+        TEST_NAME. See http://www.sqlite.org/inmemorydb.html
+        """
+        settings_dict = self.connection.settings_dict
+        test_dbname = self._get_test_db_name()
+        sig = [self.connection.settings_dict['NAME']]
+        if test_dbname == ':memory:':
+            sig.append(self.connection.alias)
+        return tuple(sig)

Modified: django/trunk/tests/regressiontests/test_runner/tests.py
===================================================================
--- django/trunk/tests/regressiontests/test_runner/tests.py     2012-03-13 
17:35:00 UTC (rev 17701)
+++ django/trunk/tests/regressiontests/test_runner/tests.py     2012-03-13 
17:52:48 UTC (rev 17702)
@@ -11,6 +11,7 @@
 from django.core.management import call_command
 from django.test import simple
 from django.test.simple import DjangoTestSuiteRunner, get_tests
+from django.test.testcases import connections_support_transactions
 from django.test.utils import get_warnings_state, restore_warnings_state
 from django.utils import unittest
 from django.utils.importlib import import_module
@@ -262,3 +263,38 @@
         "Test for #12658 - Tests with ImportError's shouldn't fail silently"
         module = import_module(TEST_APP_ERROR)
         self.assertRaises(ImportError, get_tests, module)
+
+
+class Sqlite3InMemoryTestDbs(unittest.TestCase):
+    def test_transaction_support(self):
+        """Ticket #16329: sqlite3 in-memory test databases"""
+        from django import db
+        old_db_connections = db.connections
+        for option in ('NAME', 'TEST_NAME'):
+            try:
+                db.connections = db.ConnectionHandler({
+                    'default': {
+                        'ENGINE': 'django.db.backends.sqlite3',
+                        option: ':memory:',
+                    },
+                    'other': {
+                        'ENGINE': 'django.db.backends.sqlite3',
+                        option: ':memory:',
+                    },
+                })
+                other = db.connections['other']
+                self.assertEqual(other.features.supports_transactions, None)
+                DjangoTestSuiteRunner(verbosity=0).setup_databases()
+                # Transaction support should be properly initialised for the 
'other' DB
+                self.assertNotEqual(
+                    other.features.supports_transactions,
+                    None,
+                    "DATABASES setting '%s' option set to sqlite3's ':memory:' 
value causes problems with transaction support detection." % option
+                )
+                # And all the DBs should report that they support transactions
+                self.assertTrue(
+                    connections_support_transactions(),
+                    "DATABASES setting '%s' option set to sqlite3's ':memory:' 
value causes problems with transaction support detection." % option
+                )
+            finally:
+                db.connections = old_db_connections

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to