#NEWLINE# def test_basic_sorting( backend ) : #NEWLINE# #INDENT# backend . filter ( Actor , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . delete ( ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1983 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1983 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1984 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1984 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1984 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1985 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1980 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1990 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 2000 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 2000 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1900 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 1843 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . save ( Actor ( { #NEWLINE# #INDENT# 'birth_year' : 2014 , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# backend . commit ( ) #NEWLINE# actors = backend . filter ( Actor , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . sort ( [ ( 'birth_year' , ( - 1 ) ) ] ) #NEWLINE# for i in range ( 1 , len ( actors ) ) : #NEWLINE# #INDENT# assert ( actors [ ( i - 1 ) ] . birth_year >= actor_wo_birth_year [ i ] . birth_year ) #NEWLINE# #UNINDENT# '\n    Objects with missing sort keys should be returned first when\n    sorting in ascending order, else last.\n    ' #NEWLINE# actor_wo_birth_year = Actor ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# backend . save ( actor_wo_birth_year ) #NEWLINE# backend . commit ( ) #NEWLINE# actors = list ( backend . filter ( Actor , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) . sort ( [ ( 'birth_year' , 1 ) ] ) ) #NEWLINE# assert ( actor_wo_birth_year in actors ) #NEWLINE# if ( not isinstance ( backend , SqlBackend ) ) : #NEWLINE# #INDENT# assert ( actors [ 0 ] == actor_wo_birth_year )