#NEWLINE# def test_replace( self , models ) : #NEWLINE# #INDENT# replacer = TModel . objects . create ( name = 'replacer' , path = 'r' ) #NEWLINE# models . child1 . appendTo ( models . parent ) #NEWLINE# models . child1 . reload ( ( - 1 ) ) #NEWLINE# assert ( TModel . objects . count ( ) == 4 ) #NEWLINE# replacer . replace ( models . child1 ) #NEWLINE# assert ( TModel . objects . count ( ) == 3 ) #NEWLINE# assert ( list ( replacer . parent . children ) == [ replacer . reload ( ( - 1 ) ) ] ) #NEWLINE# models . child2 . replaceWith ( replacer ) #NEWLINE# replacer . reload ( ( - 1 ) ) #NEWLINE# assert ( models . parent . children . count ( ) == 0 ) #NEWLINE# assert ( replacer . name == 'child2' )