Made assertOptimizesTo() more strict in migrations tests.
A recursive deconstruction is needed because comparing deconstructed operations doesn't check field attributes. Fixed typo in failing test.
This commit is contained in:
parent
8d2dcc47cd
commit
d02b2aa11e
|
@ -1,6 +1,7 @@
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
from django.db.migrations import operations
|
from django.db.migrations import operations
|
||||||
from django.db.migrations.optimizer import MigrationOptimizer
|
from django.db.migrations.optimizer import MigrationOptimizer
|
||||||
|
from django.db.migrations.serializer import serializer_factory
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
from .models import EmptyManager, UnicodeModel
|
from .models import EmptyManager, UnicodeModel
|
||||||
|
@ -18,10 +19,13 @@ class OptimizerTests(SimpleTestCase):
|
||||||
optimizer = MigrationOptimizer()
|
optimizer = MigrationOptimizer()
|
||||||
return optimizer.optimize(operations, app_label), optimizer._iterations
|
return optimizer.optimize(operations, app_label), optimizer._iterations
|
||||||
|
|
||||||
|
def serialize(self, value):
|
||||||
|
return serializer_factory(value).serialize()[0]
|
||||||
|
|
||||||
def assertOptimizesTo(self, operations, expected, exact=None, less_than=None, app_label=None):
|
def assertOptimizesTo(self, operations, expected, exact=None, less_than=None, app_label=None):
|
||||||
result, iterations = self.optimize(operations, app_label)
|
result, iterations = self.optimize(operations, app_label)
|
||||||
result = [repr(f.deconstruct()) for f in result]
|
result = [self.serialize(f) for f in result]
|
||||||
expected = [repr(f.deconstruct()) for f in expected]
|
expected = [self.serialize(f) for f in expected]
|
||||||
self.assertEqual(expected, result)
|
self.assertEqual(expected, result)
|
||||||
if exact is not None and iterations != exact:
|
if exact is not None and iterations != exact:
|
||||||
raise self.failureException(
|
raise self.failureException(
|
||||||
|
@ -360,7 +364,7 @@ class OptimizerTests(SimpleTestCase):
|
||||||
('url', models.TextField()),
|
('url', models.TextField()),
|
||||||
('foo_fk', models.ForeignKey('migrations.Foo', models.CASCADE)),
|
('foo_fk', models.ForeignKey('migrations.Foo', models.CASCADE)),
|
||||||
]),
|
]),
|
||||||
migrations.AddField('Foo', 'bar_fk', models.ForeignKey('migrations.Foo', models.CASCADE)),
|
migrations.AddField('Foo', 'bar_fk', models.ForeignKey('migrations.Bar', models.CASCADE)),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue