1010from tortoise .contrib .test .condition import NotEQ
1111from tortoise .exceptions import ConfigurationError , FieldError
1212from tortoise .expressions import Case , Q , When
13- from tortoise .functions import Count , Sum
13+ from tortoise .functions import Count , Lower , Sum
1414
1515
1616class TestOrderBy (test .TestCase ):
@@ -95,6 +95,16 @@ async def test_order_by_aggregation_reversed(self):
9595 )
9696 self .assertEqual ([t .name for t in tournaments ], ["1" , "2" ])
9797
98+ async def test_order_by_reserved_word_annotation (self ):
99+ await Tournament .create (name = "1" )
100+ await Tournament .create (name = "2" )
101+
102+ reserved_words = ["order" , "group" , "limit" , "offset" , "where" ]
103+
104+ for word in reserved_words :
105+ tournaments = await Tournament .annotate (** {word : Lower ("name" )}).order_by (word )
106+ self .assertEqual ([t .name for t in tournaments ], ["1" , "2" ])
107+
98108 async def test_distinct_values_with_annotation (self ):
99109 await Tournament .create (name = "3" )
100110 await Tournament .create (name = "1" )
@@ -115,7 +125,7 @@ async def test_distinct_values_with_annotation(self):
115125 )
116126 self .assertEqual ([t ["name" ] for t in tournaments ], ["1" , "2" , "3" ])
117127
118- async def test_distinct_all_withl_annotation (self ):
128+ async def test_distinct_all_with_annotation (self ):
119129 await Tournament .create (name = "3" )
120130 await Tournament .create (name = "1" )
121131 await Tournament .create (name = "2" )
0 commit comments