From 60873ea2ade8bed909b9f2dabb0f8a499226e10d Mon Sep 17 00:00:00 2001 From: Andrew Godwin Date: Fri, 10 Aug 2012 15:03:18 +0100 Subject: Add db_table and db_tablespace handling --- tests/modeltests/schema/tests.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/modeltests/schema/tests.py b/tests/modeltests/schema/tests.py index 52d99225f0..8813d3ca23 100644 --- a/tests/modeltests/schema/tests.py +++ b/tests/modeltests/schema/tests.py @@ -342,3 +342,42 @@ class SchemaTests(TestCase): UniqueTest.objects.create(year=2012, slug="foo") self.assertRaises(IntegrityError, UniqueTest.objects.create, year=2012, slug="foo") connection.rollback() + + def test_db_table(self): + """ + Tests renaming of the table + """ + # Create the table + editor = connection.schema_editor() + editor.start() + editor.create_model(Author) + editor.commit() + # Ensure the table is there to begin with + columns = self.column_classes(Author) + self.assertEqual(columns['name'][0], "CharField") + # Alter the table + editor = connection.schema_editor() + editor.start() + editor.alter_db_table( + Author, + "schema_author", + "schema_otherauthor", + ) + editor.commit() + # Ensure the table is there afterwards + Author._meta.db_table = "schema_otherauthor" + columns = self.column_classes(Author) + self.assertEqual(columns['name'][0], "CharField") + # Alter the table again + editor = connection.schema_editor() + editor.start() + editor.alter_db_table( + Author, + "schema_otherauthor", + "schema_author", + ) + editor.commit() + # Ensure the table is still there + Author._meta.db_table = "schema_author" + columns = self.column_classes(Author) + self.assertEqual(columns['name'][0], "CharField") -- cgit v1.3