#NEWLINE# def test_delete_signals( self ) : #NEWLINE# #INDENT# data = [ ] #NEWLINE# def pre_delete_handler( signal , sender , instance , **kwargs ) : #NEWLINE# #INDENT# data . append ( ( instance , ( instance . id is None ) ) ) #NEWLINE# #UNINDENT# class PostDeleteHandler ( object ) : #NEWLINE# #INDENT# def __init__( self , data ) : #NEWLINE# #INDENT# self . data = data #NEWLINE# #UNINDENT# def __call__( self , signal , sender , instance , **kwargs ) : #NEWLINE# #INDENT# self . data . append ( ( instance , ( instance . id is None ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# post_delete_handler = PostDeleteHandler ( data ) #NEWLINE# signals . pre_delete . connect ( pre_delete_handler , weak = False ) #NEWLINE# signals . post_delete . connect ( post_delete_handler , weak = False ) #NEWLINE# try : #NEWLINE# #INDENT# p1 = Person . objects . create ( first_name = 'John' , last_name = 'Smith' ) #NEWLINE# p1 . delete ( ) #NEWLINE# self . assertEqual ( data , [ ( p1 , False ) , ( p1 , False ) ] ) #NEWLINE# data [ : ] = [ ] #NEWLINE# p2 = Person ( first_name = 'James' , last_name = 'Jones' ) #NEWLINE# p2 . id = 99999 #NEWLINE# p2 . save ( ) #NEWLINE# p2 . id = 99998 #NEWLINE# p2 . save ( ) #NEWLINE# p2 . delete ( ) #NEWLINE# self . assertEqual ( data , [ ( p2 , False ) , ( p2 , False ) ] ) #NEWLINE# data [ : ] = [ ] #NEWLINE# self . assertQuerysetEqual ( Person . objects . all ( ) , [ 'James Jones' ] , six . text_type ) #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# signals . pre_delete . disconnect ( p1 ) #NEWLINE# signals . post_delete . disconnect ( post_delete_handler )