| 13 | |
| 14 | class FunctionTests(TestCase): |
| 15 | def test_nested_function_ordering(self): |
| 16 | Author.objects.create(name="John Smith") |
| 17 | Author.objects.create(name="Rhonda Simpson", alias="ronny") |
| 18 | |
| 19 | authors = Author.objects.order_by(Length(Coalesce("alias", "name"))) |
| 20 | self.assertQuerySetEqual( |
| 21 | authors, |
| 22 | [ |
| 23 | "Rhonda Simpson", |
| 24 | "John Smith", |
| 25 | ], |
| 26 | lambda a: a.name, |
| 27 | ) |
| 28 | |
| 29 | authors = Author.objects.order_by(Length(Coalesce("alias", "name")).desc()) |
| 30 | self.assertQuerySetEqual( |
| 31 | authors, |
| 32 | [ |
| 33 | "John Smith", |
| 34 | "Rhonda Simpson", |
| 35 | ], |
| 36 | lambda a: a.name, |
| 37 | ) |
| 38 | |
| 39 | def test_func_transform_bilateral(self): |
| 40 | with register_lookup(CharField, UpperBilateral): |