#NEWLINE# @ patch ( 'salt.modules.npm._check_valid_version' , MagicMock ( return_value = True ) ) #NEWLINE# def test_list( self ) : #NEWLINE# #INDENT# '\n        Test if it list installed NPM packages.\n        ' #NEWLINE# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'retcode' : 1 , #NEWLINE# 'stderr' : 'error' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( npm . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertRaises ( CommandExecutionError , npm . list_ , 'coffee-script' ) #NEWLINE# #UNINDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'retcode' : 0 , #NEWLINE# 'stderr' : 'error' , #NEWLINE# 'stdout' : '{"salt": ["SALT"]}' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( npm . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : mock , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# mock_err = MagicMock ( return_value = { #NEWLINE# #INDENT# 'dependencies' : 'SALT' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . object ( json , 'loads' , mock_err ) : #NEWLINE# #INDENT# self . assertEqual ( npm . list_ ( 'coffee-script' ) , 'SALT' )