#NEWLINE# def test_deletion_order( self ) : #NEWLINE# #INDENT# pre_delete_order = [ ] #NEWLINE# post_delete_order = [ ] #NEWLINE# def log_post_delete( sender , **kwargs ) : #NEWLINE# #INDENT# pre_delete_order . append ( ( sender , kwargs [ 'instance' ] . pk ) ) #NEWLINE# #UNINDENT# def log_pre_delete( sender , **kwargs ) : #NEWLINE# #INDENT# post_delete_order . append ( ( sender , kwargs [ 'instance' ] . pk ) ) #NEWLINE# #UNINDENT# models . signals . post_delete . connect ( log_post_delete ) #NEWLINE# models . signals . pre_delete . connect ( log_pre_delete ) #NEWLINE# r = R . objects . create ( pk = 1 ) #NEWLINE# s1 = S . objects . create ( pk = 1 , r = r ) #NEWLINE# s2 = S . objects . create ( pk = 2 , r = r ) #NEWLINE# t1 = T . objects . create ( pk = 1 , s = s1 ) #NEWLINE# t2 = T . objects . create ( pk = 2 , s = s2 ) #NEWLINE# r . delete ( ) #NEWLINE# self . assertEqual ( pre_delete_order , [ ( T , 2 ) , ( T , 1 ) , ( S , 2 ) , ( S , 1 ) , ( R , 1 ) ] ) #NEWLINE# self . assertEqual ( post_delete_order , [ ( T , 1 ) , ( T , 2 ) , ( S , 1 ) , ( S , 2 ) , ( R , 1 ) ] ) #NEWLINE# models . signals . post_delete . disconnect ( log_post_delete ) #NEWLINE# models . signals . pre_delete . disconnect ( log_pre_delete )