+ db.rollback_transaction()
+ db.delete_table("test2")
+
+ def test_dry_rename(self):
+ """
+ Test column renaming while --dry-run is turned on (should do nothing)
+ See ticket #65
+ """
+ cursor = connection.cursor()
+ db.create_table("test2", [('spam', models.BooleanField(default=False))])
+ db.start_transaction()
+ # Make sure we can select the column
+ cursor.execute("SELECT spam FROM test2")
+ # Rename it
+ db.dry_run = True
+ db.rename_column("test2", "spam", "eggs")
+ db.dry_run = False
+ cursor.execute("SELECT spam FROM test2")
+ try:
+ cursor.execute("SELECT eggs FROM test2")
+ self.fail("Dry-renamed new column could be selected!")
+ except:
+ pass
+ db.rollback_transaction()
+ db.delete_table("test2")
+
+ def test_table_rename(self):
+ """
+ Test column renaming
+ """
+ cursor = connection.cursor()
+ db.create_table("testtr", [('spam', models.BooleanField(default=False))])
+ db.start_transaction()
+ # Make sure we can select the column
+ cursor.execute("SELECT spam FROM testtr")
+ # Rename it
+ db.rename_table("testtr", "testtr2")
+ cursor.execute("SELECT spam FROM testtr2")
+ try:
+ cursor.execute("SELECT spam FROM testtr")
+ self.fail("Just-renamed column could be selected!")
+ except:
+ pass
+ db.rollback_transaction()
+ db.delete_table("testtr2")
+
+ def test_index(self):
+ """
+ Test the index operations
+ """
+ db.create_table("test3", [
+ ('SELECT', models.BooleanField(default=False)),
+ ('eggs', models.IntegerField(unique=True)),
+ ])
+ db.execute_deferred_sql()
+ db.start_transaction()
+ # Add an index on that column
+ db.create_index("test3", ["SELECT"])
+ # Add another index on two columns
+ db.create_index("test3", ["SELECT", "eggs"])
+ # Delete them both
+ db.delete_index("test3", ["SELECT"])
+ db.delete_index("test3", ["SELECT", "eggs"])
+ # Delete the unique index
+ db.delete_index("test3", ["eggs"])
+ db.rollback_transaction()
+ db.delete_table("test3")
+
+ def test_alter(self):
+ """
+ Test altering columns/tables
+ """
+ db.create_table("test4", [
+ ('spam', models.BooleanField(default=False)),
+ ('eggs', models.IntegerField()),
+ ])
+ db.start_transaction()
+ # Add a column
+ db.add_column("test4", "add1", models.IntegerField(default=3), keep_default=False)
+ # Add a FK with keep_default=False (#69)
+ User = db.mock_model(model_name='User', db_table='auth_user', db_tablespace='', pk_field_name='id', pk_field_type=models.AutoField, pk_field_args=[], pk_field_kwargs={})
+ db.add_column("test4", "user", models.ForeignKey(User), keep_default=False)
+
+ db.rollback_transaction()
+ db.delete_table("test4")
\ No newline at end of file