Skip to content

Commit

Permalink
[1.9.x] Refs #26034 -- Corrected a schema test to work with the corre…
Browse files Browse the repository at this point in the history
…ct field state.

Backport of d47f6d7 from master
  • Loading branch information
jdufresne authored and timgraham committed Jun 27, 2016
1 parent f40c91c commit 54c0dea
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions tests/schema/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1778,15 +1778,14 @@ def test_alter_field_add_unique_to_charfield_with_db_index(self):
self.get_constraints_for_column(BookWithoutAuthor, 'title'),
['schema_book_d5d3db17', 'schema_book_title_2dfb2dff_like', 'schema_book_title_2dfb2dff_uniq']
)
# Alter to remove unique=True (should drop unique index) # XXX: bug!
old_field = BookWithoutAuthor._meta.get_field('title')
new_field = CharField(max_length=100, db_index=True)
new_field.set_attributes_from_name('title')
# Alter to remove unique=True (should drop unique index)
new_field2 = CharField(max_length=100, db_index=True)
new_field2.set_attributes_from_name('title')
with connection.schema_editor() as editor:
editor.alter_field(BookWithoutAuthor, old_field, new_field, strict=True)
editor.alter_field(BookWithoutAuthor, new_field, new_field2, strict=True)
self.assertEqual(
self.get_constraints_for_column(BookWithoutAuthor, 'title'),
['schema_book_d5d3db17', 'schema_book_title_2dfb2dff_like', 'schema_book_title_2dfb2dff_uniq']
['schema_book_d5d3db17', 'schema_book_title_2dfb2dff_like']
)

@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
Expand All @@ -1809,11 +1808,10 @@ def test_alter_field_add_db_index_to_charfield_with_unique(self):
['schema_tag_slug_2c418ba3_like', 'schema_tag_slug_key']
)
# Alter to remove db_index=True
old_field = Tag._meta.get_field('slug')
new_field = SlugField(unique=True)
new_field.set_attributes_from_name('slug')
new_field2 = SlugField(unique=True)
new_field2.set_attributes_from_name('slug')
with connection.schema_editor() as editor:
editor.alter_field(Tag, old_field, new_field, strict=True)
editor.alter_field(Tag, new_field, new_field2, strict=True)
self.assertEqual(
self.get_constraints_for_column(Tag, 'slug'),
['schema_tag_slug_2c418ba3_like', 'schema_tag_slug_key']
Expand Down

0 comments on commit 54c0dea

Please sign in to comment.