Author: jacob
Date: 2006-05-18 13:25:49 -0500 (Thu, 18 May 2006)
New Revision: 2940

Modified:
   django/trunk/tests/runtests.py
Log:
The tests now run correctly with the new psycopg2 backend.  There's 4 failures, 
but they all have to do with the new way the psycopg2 handles datetimes and are 
probably a single fix.

Modified: django/trunk/tests/runtests.py
===================================================================
--- django/trunk/tests/runtests.py      2006-05-18 18:03:27 UTC (rev 2939)
+++ django/trunk/tests/runtests.py      2006-05-18 18:25:49 UTC (rev 2940)
@@ -114,14 +114,11 @@
             global TEST_DATABASE_NAME
             TEST_DATABASE_NAME = ":memory:"
         else:
-            # Create the test database and connect to it. We need autocommit()
-            # because PostgreSQL doesn't allow CREATE DATABASE statements
-            # within transactions.
+            # Create the test database and connect to it. We need to autocommit
+            # if the database supports it because PostgreSQL doesn't allow 
+            # CREATE/DROP DATABASE statements within transactions.
             cursor = connection.cursor()
-            try:
-                connection.connection.autocommit(1)
-            except AttributeError:
-                pass
+            self._set_autocommit(connection)
             self.output(1, "Creating test database")
             try:
                 cursor.execute("CREATE DATABASE %s" % TEST_DATABASE_NAME)
@@ -224,12 +221,8 @@
             settings.DATABASE_NAME = old_database_name
             cursor = connection.cursor()
             self.output(1, "Deleting test database")
-            try:
-                connection.connection.autocommit(1)
-            except AttributeError:
-                pass
-            else:
-                time.sleep(1) # To avoid "database is being accessed by other 
users" errors.
+            self._set_autocommit(connection)
+            time.sleep(1) # To avoid "database is being accessed by other 
users" errors.
             cursor.execute("DROP DATABASE %s" % TEST_DATABASE_NAME)
 
         # Display output.
@@ -242,6 +235,15 @@
             print "%s error%s:" % (len(error_list), len(error_list) != 1 and 
's' or '')
         else:
             print "All tests passed."
+            
+    def _set_autocommit(self, connection):
+        """
+        Make sure a connection is in autocommit mode.
+        """
+        if hasattr(connection.connection, "autocommit"):
+            connection.connection.autocommit(True)
+        elif hasattr(connection.connection, "set_isolation_level"):
+            connection.connection.set_isolation_level(0)
 
 if __name__ == "__main__":
     from optparse import OptionParser


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates
-~----------~----~----~----~------~----~------~--~---

Reply via email to