summaryrefslogtreecommitdiff
path: root/tests/schema
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-07-02 11:43:44 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-07-02 11:43:44 +0100
commit6a8cfbf07b2ba7e18db4d86aed0111be4457981e (patch)
treede45209732de0cef038f2a59237bbe3e7ad4d0d7 /tests/schema
parent3b20af3e96b45fd3cfd9beb74bd09f65b4e38aa8 (diff)
Support for index_together in schema backends
Diffstat (limited to 'tests/schema')
-rw-r--r--tests/schema/tests.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index 4f3c9b7f10..a92c3f7910 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -452,6 +452,57 @@ class SchemaTests(TransactionTestCase):
self.assertRaises(IntegrityError, UniqueTest.objects.create, year=2012, slug="foo")
UniqueTest.objects.all().delete()
+ def test_index_together(self):
+ """
+ Tests removing and adding index_together constraints on a model.
+ """
+ # Create the table
+ with connection.schema_editor() as editor:
+ editor.create_model(Tag)
+ # Ensure there's no index on the year/slug columns first
+ self.assertEqual(
+ False,
+ any(
+ c["index"]
+ for c in connection.introspection.get_constraints(connection.cursor(), "schema_tag").values()
+ if c['columns'] == set(["slug", "title"])
+ ),
+ )
+ # Alter the model to add an index
+ with connection.schema_editor() as editor:
+ editor.alter_index_together(
+ Tag,
+ [],
+ [("slug", "title")],
+ )
+ # Ensure there is now an index
+ self.assertEqual(
+ True,
+ any(
+ c["index"]
+ for c in connection.introspection.get_constraints(connection.cursor(), "schema_tag").values()
+ if c['columns'] == set(["slug", "title"])
+ ),
+ )
+ # Alter it back
+ new_new_field = SlugField(unique=True)
+ new_new_field.set_attributes_from_name("slug")
+ with connection.schema_editor() as editor:
+ editor.alter_unique_together(
+ Tag,
+ [("slug", "title")],
+ [],
+ )
+ # Ensure there's no index
+ self.assertEqual(
+ False,
+ any(
+ c["index"]
+ for c in connection.introspection.get_constraints(connection.cursor(), "schema_tag").values()
+ if c['columns'] == set(["slug", "title"])
+ ),
+ )
+
def test_db_table(self):
"""
Tests renaming of the table