Ticket #22432: 22432-failing-test.patch

File 22432-failing-test.patch, 3.0 KB (added by Raphaël Barrois, 11 years ago)

Failing test to reproduce the issue.

  • tests/migrations/test_operations.py

    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):  
    3434        with connection.schema_editor() as editor:
    3535            return migration.unapply(project_state, editor)
    3636
    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):
    3838        """
    3939        Creates a test model state and database table.
    4040        """
    class OperationTests(MigrationTestBase):  
    4848                cursor.execute("DROP TABLE %s_stable" % app_label)
    4949            except DatabaseError:
    5050                pass
     51            try:
     52                cursor.execute("DROP TABLE %s_van" % app_label)
     53            except DatabaseError:
     54                pass
    5155        # Make the "current" state
    5256        operations = [migrations.CreateModel(
    5357            "Pony",
    class OperationTests(MigrationTestBase):  
    6468                    ("id", models.AutoField(primary_key=True)),
    6569                ]
    6670            ))
     71        if third_model:
     72            operations.append(migrations.CreateModel(
     73                "Van",
     74                [
     75                    ("id", models.AutoField(primary_key=True)),
     76                ]
     77            ))
    6778        if related_model:
    6879            operations.append(migrations.CreateModel(
    6980                "Rider",
    class OperationTests(MigrationTestBase):  
    405416        Pony = new_apps.get_model("test_alflmm", "Pony")
    406417        self.assertTrue(Pony._meta.get_field('stables').blank)
    407418
     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
    408440    def test_remove_field_m2m(self):
    409441        project_state = self.set_up_test_model("test_rmflmm", second_model=True)
    410442
Back to Top