#NEWLINE# def test_insert_detach( self , models ) : #NEWLINE# #INDENT# assert ( models . parent . children . count ( ) == 0 ) #NEWLINE# assert ( models . child1 . parents == [ ] ) #NEWLINE# models . parent . insert ( 0 , models . child1 ) #NEWLINE# models . parent . insert ( 1 , models . child2 ) #NEWLINE# assert ( list ( models . parent . children ) == [ models . child1 , models . child2 ] ) #NEWLINE# models . child2 . detach ( ) #NEWLINE# assert ( list ( models . parent . children ) == [ models . child1 ] ) #NEWLINE# models . parent . insert ( 0 , models . child2 ) #NEWLINE# assert ( list ( models . parent . children ) == [ models . child2 , models . child1 ] ) #NEWLINE# models . child1 . append ( models . child2 ) #NEWLINE# assert ( ( list ( models . parent . children ) == [ models . child1 ] ) and ( list ( models . child1 . children ) == [ models . child2 ] ) ) #NEWLINE# assert ( list ( models . parent . contents ) == [ self . child1 , models . child2 ] ) #NEWLINE# models . child1 . empty ( ) #NEWLINE# assert ( list ( models . parent . contents ) == [ models . child1 ] ) #NEWLINE# assert ( TModel . objects . count ( ) == 2 )