mirror of
https://github.com/django/django.git
synced 2025-08-03 02:23:12 +00:00
Autodetect field alters
This commit is contained in:
parent
80bdf68d6b
commit
47e4b86ddf
4 changed files with 40 additions and 2 deletions
|
@ -13,6 +13,7 @@ class AutodetectorTests(TestCase):
|
|||
|
||||
author_empty = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True))])
|
||||
author_name = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=200))])
|
||||
author_name_longer = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True)), ("name", models.CharField(max_length=400))])
|
||||
other_pony = ModelState("otherapp", "Pony", [("id", models.AutoField(primary_key=True))])
|
||||
other_stable = ModelState("otherapp", "Stable", [("id", models.AutoField(primary_key=True))])
|
||||
third_thing = ModelState("thirdapp", "Thing", [("id", models.AutoField(primary_key=True))])
|
||||
|
@ -130,3 +131,20 @@ class AutodetectorTests(TestCase):
|
|||
action = migration.operations[0]
|
||||
self.assertEqual(action.__class__.__name__, "RemoveField")
|
||||
self.assertEqual(action.name, "name")
|
||||
|
||||
def test_alter_field(self):
|
||||
"Tests autodetection of new fields"
|
||||
# Make state
|
||||
before = self.make_project_state([self.author_name])
|
||||
after = self.make_project_state([self.author_name_longer])
|
||||
autodetector = MigrationAutodetector(before, after)
|
||||
changes = autodetector.changes()
|
||||
# Right number of migrations?
|
||||
self.assertEqual(len(changes['testapp']), 1)
|
||||
# Right number of actions?
|
||||
migration = changes['testapp'][0]
|
||||
self.assertEqual(len(migration.operations), 1)
|
||||
# Right action?
|
||||
action = migration.operations[0]
|
||||
self.assertEqual(action.__class__.__name__, "AlterField")
|
||||
self.assertEqual(action.name, "name")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue