Ticket #24435: 24435-test.diff

File 24435-test.diff, 1.7 KB (added by Tim Graham, 10 years ago)
  • tests/migrations/test_autodetector.py

    diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
    index 3d82207..2d45dac 100644
    a b class AutodetectorTests(TestCase):  
    127127        ("id", models.AutoField(primary_key=True)),
    128128        ("publishers", models.ManyToManyField("testapp.Publisher")),
    129129    ])
     130    author_with_m2m_blank = ModelState("testapp", "Author", [
     131        ("id", models.AutoField(primary_key=True)),
     132        ("publishers", models.ManyToManyField("testapp.Publisher", blank=True)),
     133    ])
    130134    author_with_m2m_through = ModelState("testapp", "Author", [
    131135        ("id", models.AutoField(primary_key=True)),
    132136        ("publishers", models.ManyToManyField("testapp.Publisher", through="testapp.Contract")),
    class AutodetectorTests(TestCase):  
    12631267        self.assertOperationTypes(changes, 'testapp', 0, ["AddField"])
    12641268        self.assertOperationAttributes(changes, 'testapp', 0, 0, name="publishers")
    12651269
     1270    def test_alter_many_to_many(self):
     1271        before = self.make_project_state([self.author_with_m2m, self.publisher])
     1272        after = self.make_project_state([self.author_with_m2m_blank, self.publisher])
     1273        autodetector = MigrationAutodetector(before, after)
     1274        changes = autodetector._detect_changes()
     1275        # Right number/type of migrations?
     1276        self.assertNumberMigrations(changes, 'testapp', 1)
     1277        self.assertOperationTypes(changes, 'testapp', 0, ["AlterField"])
     1278        self.assertOperationAttributes(changes, 'testapp', 0, 0, name="publishers")
     1279
    12661280    def test_create_with_through_model(self):
    12671281        """
    12681282        Adding a m2m with a through model and the models that use it should be
Back to Top