1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #33216 -- Simpilified deconstructed paths for some expressions.

This commit is contained in:
Allen Jonathan David
2021-12-06 14:17:22 +05:30
committed by Mariusz Felisiak
parent 96e7ff5e9f
commit 28c98d4113
3 changed files with 35 additions and 2 deletions

View File

@@ -607,6 +607,33 @@ class WriterTests(SimpleTestCase):
with self.assertRaisesMessage(ValueError, "Could not find object EmailValidator2 in django.core.validators."):
MigrationWriter.serialize(validator)
def test_serialize_complex_func_index(self):
index = models.Index(
models.Func('rating', function='ABS'),
models.Case(
models.When(name='special', then=models.Value('X')),
default=models.Value('other'),
),
models.ExpressionWrapper(
models.F('pages'),
output_field=models.IntegerField(),
),
models.OrderBy(models.F('name').desc()),
name='complex_func_index',
)
string, imports = MigrationWriter.serialize(index)
self.assertEqual(
string,
"models.Index(models.Func('rating', function='ABS'), "
"models.Case(models.When(name='special', then=models.Value('X')), "
"default=models.Value('other')), "
"models.ExpressionWrapper("
"models.F('pages'), output_field=models.IntegerField()), "
"models.OrderBy(models.OrderBy(models.F('name'), descending=True)), "
"name='complex_func_index')"
)
self.assertEqual(imports, {'from django.db import models'})
def test_serialize_empty_nonempty_tuple(self):
"""
Ticket #22679: makemigrations generates invalid code for (an empty