From d02b2aa11e5b6c351a9a2c0673c23569889f90d6 Mon Sep 17 00:00:00 2001 From: Vytis Banaitis Date: Tue, 22 Jan 2019 00:29:46 +0200 Subject: [PATCH] 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. --- tests/migrations/test_optimizer.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/migrations/test_optimizer.py b/tests/migrations/test_optimizer.py index b2c7b062c6..439ab39f2b 100644 --- a/tests/migrations/test_optimizer.py +++ b/tests/migrations/test_optimizer.py @@ -1,6 +1,7 @@ from django.db import migrations, models from django.db.migrations import operations from django.db.migrations.optimizer import MigrationOptimizer +from django.db.migrations.serializer import serializer_factory from django.test import SimpleTestCase from .models import EmptyManager, UnicodeModel @@ -18,10 +19,13 @@ class OptimizerTests(SimpleTestCase): optimizer = MigrationOptimizer() 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): result, iterations = self.optimize(operations, app_label) - result = [repr(f.deconstruct()) for f in result] - expected = [repr(f.deconstruct()) for f in expected] + result = [self.serialize(f) for f in result] + expected = [self.serialize(f) for f in expected] self.assertEqual(expected, result) if exact is not None and iterations != exact: raise self.failureException( @@ -360,7 +364,7 @@ class OptimizerTests(SimpleTestCase): ('url', models.TextField()), ('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)), ], )