commit 5f42bb73315d498cc7228669672b0fced1807a63
Author: Raphaël Barrois <raphael.barrois@polytechnique.org>
Date: Fri May 16 12:16:32 2014 +0200
Add failing test for #22432.
Works fine on psql, fails on sqlite.
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 388544c..7172f9e 100644
a
|
b
|
class OperationTests(MigrationTestBase):
|
34 | 34 | with connection.schema_editor() as editor: |
35 | 35 | return migration.unapply(project_state, editor) |
36 | 36 | |
37 | | def set_up_test_model(self, app_label, second_model=False, related_model=False, mti_model=False): |
| 37 | def set_up_test_model(self, app_label, second_model=False, third_model=False, related_model=False, mti_model=False): |
38 | 38 | """ |
39 | 39 | Creates a test model state and database table. |
40 | 40 | """ |
… |
… |
class OperationTests(MigrationTestBase):
|
48 | 48 | cursor.execute("DROP TABLE %s_stable" % app_label) |
49 | 49 | except DatabaseError: |
50 | 50 | pass |
| 51 | try: |
| 52 | cursor.execute("DROP TABLE %s_van" % app_label) |
| 53 | except DatabaseError: |
| 54 | pass |
51 | 55 | # Make the "current" state |
52 | 56 | operations = [migrations.CreateModel( |
53 | 57 | "Pony", |
… |
… |
class OperationTests(MigrationTestBase):
|
64 | 68 | ("id", models.AutoField(primary_key=True)), |
65 | 69 | ] |
66 | 70 | )) |
| 71 | if third_model: |
| 72 | operations.append(migrations.CreateModel( |
| 73 | "Van", |
| 74 | [ |
| 75 | ("id", models.AutoField(primary_key=True)), |
| 76 | ] |
| 77 | )) |
67 | 78 | if related_model: |
68 | 79 | operations.append(migrations.CreateModel( |
69 | 80 | "Rider", |
… |
… |
class OperationTests(MigrationTestBase):
|
405 | 416 | Pony = new_apps.get_model("test_alflmm", "Pony") |
406 | 417 | self.assertTrue(Pony._meta.get_field('stables').blank) |
407 | 418 | |
| 419 | def test_repoint_field_m2m(self): |
| 420 | project_state = self.set_up_test_model("test_alflmm", second_model=True, third_model=True) |
| 421 | |
| 422 | project_state = self.apply_operations("test_alflmm", project_state, operations=[ |
| 423 | migrations.AddField("Pony", "places", models.ManyToManyField("Stable", related_name="ponies")) |
| 424 | ]) |
| 425 | new_apps = project_state.render() |
| 426 | Pony = new_apps.get_model("test_alflmm", "Pony") |
| 427 | |
| 428 | project_state = self.apply_operations("test_alflmm", project_state, operations=[ |
| 429 | migrations.AlterField("Pony", "places", models.ManyToManyField(to="Van", related_name="ponies")) |
| 430 | ]) |
| 431 | |
| 432 | # Ensure the new field actually works |
| 433 | new_apps = project_state.render() |
| 434 | Pony = new_apps.get_model("test_alflmm", "Pony") |
| 435 | p = Pony.objects.create(pink=False, weight=4.55) |
| 436 | p.places.create() |
| 437 | self.assertEqual(p.places.count(), 1) |
| 438 | p.places.all().delete() |
| 439 | |
408 | 440 | def test_remove_field_m2m(self): |
409 | 441 | project_state = self.set_up_test_model("test_rmflmm", second_model=True) |
410 | 442 | |