Commits

and...@69d324d9-c39d-4fdc-8679-7745eae9e2c8  committed 5608187

Test fix for [227]; also finally add strings so tests can easily do db-specific tests,

  • Participants
  • Parent commits 88eb586

Comments (0)

Files changed (4)

File south/db/generic.py

     delete_column_string = 'ALTER TABLE %s DROP COLUMN %s CASCADE;'
     create_primary_key_string = "ALTER TABLE %(table)s ADD CONSTRAINT %(constraint)s PRIMARY KEY (%(columns)s)"
     drop_primary_key_string = "ALTER TABLE %(table)s DROP CONSTRAINT %(constraint)s"
+    backend_name = None
 
     def __init__(self):
         self.debug = False

File south/db/mysql.py

     MySQL implementation of database operations.
     """
     
+    backend_name = "mysql"
     alter_string_set_type = ''
     alter_string_set_null = 'MODIFY %(column)s %(type)s NULL;'
     alter_string_drop_null = 'MODIFY %(column)s %(type)s NOT NULL;'

File south/db/postgresql_psycopg2.py

     """
     PsycoPG2 implementation of database operations.
     """
+    
+    backend_name = "postgres"
 
     def rename_column(self, table_name, old, new):
         if old == new:

File south/tests/db.py

         Tests altering columns with multiple words in Postgres types (issue #125)
         e.g. 'datetime with time zone', look at django/db/backends/postgresql/creation.py
         """
-        db.create_table("postgres_multiword", [
-            (('datetime'), models.DateTimeField(null=True)),
-            (('integer'), models.PositiveIntegerField(null=True)),
-            (('smallint'), models.PositiveSmallIntegerField(null=True)),
-            (('float'), models.FloatField(null=True)),
+        db.create_table("test_multiword", [
+            ('col_datetime', models.DateTimeField(null=True)),
+            ('col_integer', models.PositiveIntegerField(null=True)),
+            ('col_smallint', models.PositiveSmallIntegerField(null=True)),
+            ('col_float', models.FloatField(null=True)),
         ])
         
         # test if 'double precision' is preserved
-        db.alter_column('postgres_multiword', 'float', models.FloatField('float', null=True))
+        db.alter_column('test_multiword', 'col_float', models.FloatField('float', null=True))
 
         # test if 'CHECK ("%(column)s" >= 0)' is stripped
-        db.alter_column('postgres_multiword', 'integer', models.PositiveIntegerField(null=True))
-        db.alter_column('postgres_multiword', 'smallint', models.PositiveSmallIntegerField(null=True))
+        db.alter_column('test_multiword', 'col_integer', models.PositiveIntegerField(null=True))
+        db.alter_column('test_multiword', 'col_smallint', models.PositiveSmallIntegerField(null=True))
 
         # test if 'with timezone' is preserved
-        db.start_transaction()
-        db.execute("INSERT INTO postgres_multiword (datetime) VALUES ('2009-04-24 14:20:55+02')")
-        db.alter_column('postgres_multiword', 'datetime', models.DateTimeField(auto_now=True))
-        assert db.execute("SELECT datetime = '2009-04-24 14:20:55+02' FROM postgres_multiword")[0][0]
-        db.rollback_transaction()
+        if db.backend_name == "postgres":
+            db.start_transaction()
+            db.execute("INSERT INTO test_multiword (col_datetime) VALUES ('2009-04-24 14:20:55+02')")
+            db.alter_column('test_multiword', 'col_datetime', models.DateTimeField(auto_now=True))
+            assert db.execute("SELECT col_datetime = '2009-04-24 14:20:55+02' FROM test_multiword")[0][0]
+            db.rollback_transaction()
 
         
-        db.delete_table("postgres_multiword")
+        db.delete_table("test_multiword")
     
     def test_alter_constraints(self):
         """