#NEWLINE# @ mock . patch ( 'spotify.track.lib' , spec = spotify . lib ) #NEWLINE# def test_tracks( self , track_lib_mock , lib_mock ) : #NEWLINE# #INDENT# lib_mock . sp_search_error . return_value = spotify . ErrorType . OK #NEWLINE# sp_track = spotify . ffi . cast ( 'sp_track *' , 43 ) #NEWLINE# lib_mock . sp_search_num_tracks . return_value = 1 #NEWLINE# lib_mock . sp_search_track . return_value = sp_track #NEWLINE# sp_search = spotify . ffi . cast ( 'sp_search *' , 42 ) #NEWLINE# search = spotify . Search ( self . session , sp_search = sp_search ) #NEWLINE# self . assertEqual ( lib_mock . sp_search_add_ref . call_count , 1 ) #NEWLINE# result = search . tracks #NEWLINE# self . assertEqual ( lib_mock . sp_search_add_ref . call_count , 2 ) #NEWLINE# self . assertEqual ( len ( result ) , 1 ) #NEWLINE# lib_mock . sp_search_num_tracks . assert_called_with ( sp_search ) #NEWLINE# item = result [ 0 ] #NEWLINE# self . assertIsInstance ( item , spotify . Track ) #NEWLINE# self . assertEqual ( item . _sp_track , sp_track ) #NEWLINE# self . assertEqual ( lib_mock . sp_search_track . call_count , 1 ) #NEWLINE# lib_mock . sp_search_track . assert_called_with ( sp_search , 0 ) #NEWLINE# track_lib_mock . sp_track_add_ref . assert_called_with ( sp_track )