#NEWLINE# def test_vm_cputime( self ) : #NEWLINE# #INDENT# '\n            Test to Return cputime used by the vms\n        ' #NEWLINE# ret = { #NEWLINE# #INDENT# '1' : { #NEWLINE# #INDENT# 'cputime_percent' : 0 , #NEWLINE# 'cputime' : 1 , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } #NEWLINE# with patch . object ( xapi , '_get_xapi_session' , MagicMock ( ) ) : #NEWLINE# #INDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'host_CPUs' : '1' , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . object ( xapi , '_get_record_by_label' , mock ) : #NEWLINE# #INDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# 'VCPUs_number' : '1' , #NEWLINE# 'VCPUs_utilisation' : { #NEWLINE# #INDENT# '0' : '1' , #NEWLINE# #UNINDENT# } , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . object ( xapi , '_get_metrics_record' , mock ) : #NEWLINE# #INDENT# self . assertDictEqual ( xapi . vm_cputime ( '1' ) , ret ) #NEWLINE# #UNINDENT# #UNINDENT# mock = MagicMock ( return_value = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . object ( xapi , 'list_domains' , mock ) : #NEWLINE# #INDENT# self . assertDictEqual ( xapi . vm_cputime ( '' ) , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } )