Example #1
0
 def test_optimize_through_fields(self):
     """
     field-level through checking is working. This should manage to collapse
     model Foo to nonexistence, and model Bar to a single IntegerField
     called "width".
     """
     self.assertOptimizesTo(
         [
             migrations.CreateModel(
                 "Foo", [("name", models.CharField(max_length=255))]),
             migrations.CreateModel("Bar",
                                    [("size", models.IntegerField())]),
             migrations.AddField("Foo", "age", models.IntegerField()),
             migrations.AddField("Bar", "width", models.IntegerField()),
             migrations.AlterField("Foo", "age", models.IntegerField()),
             migrations.RenameField("Bar", "size", "dimensions"),
             migrations.RemoveField("Foo", "age"),
             migrations.RenameModel("Foo", "Phou"),
             migrations.RemoveField("Bar", "dimensions"),
             migrations.RenameModel("Phou", "Fou"),
             migrations.DeleteModel("Fou"),
         ],
         [
             migrations.CreateModel("Bar",
                                    [("width", models.IntegerField())]),
         ],
     )
Example #2
0
 def test_rename_model_self(self):
     """
     RenameModels should absorb themselves.
     """
     self.assertOptimizesTo(
         [
             migrations.RenameModel("Foo", "Baa"),
             migrations.RenameModel("Baa", "Bar"),
         ],
         [
             migrations.RenameModel("Foo", "Bar"),
         ],
     )
Example #3
0
 def test_create_rename_model(self):
     """
     CreateModel should absorb RenameModels.
     """
     managers = [('objects', EmptyManager())]
     self.assertOptimizesTo(
         [
             migrations.CreateModel(
                 name="Foo",
                 fields=[("name", models.CharField(max_length=255))],
                 options={'verbose_name': 'Foo'},
                 bases=(UnicodeModel, ),
                 managers=managers,
             ),
             migrations.RenameModel("Foo", "Bar"),
         ],
         [
             migrations.CreateModel(
                 "Bar",
                 [("name", models.CharField(max_length=255))],
                 options={'verbose_name': 'Foo'},
                 bases=(UnicodeModel, ),
                 managers=managers,
             )
         ],
     )
Example #4
0
class Migration(migrations.Migration):

    dependencies = [
        ('contenttypes_tests', '0001_initial'),
    ]

    operations = [
        migrations.RenameModel('Foo', 'RenamedFoo'),
        migrations.RunPython(assert_foo_contenttype_not_cached,
                             migrations.RunPython.noop)
    ]
Example #5
0
 def test_optimize_elidable_operation(self):
     elidable_operation = operations.base.Operation()
     elidable_operation.elidable = True
     self.assertOptimizesTo(
         [
             elidable_operation,
             migrations.CreateModel(
                 "Foo", [("name", models.CharField(max_length=255))]),
             elidable_operation,
             migrations.CreateModel("Bar",
                                    [("size", models.IntegerField())]),
             elidable_operation,
             migrations.RenameModel("Foo", "Phou"),
             migrations.DeleteModel("Bar"),
             elidable_operation,
         ],
         [
             migrations.CreateModel(
                 "Phou", [("name", models.CharField(max_length=255))]),
         ],
     )