#NEWLINE# def test_get_zone( self ) : #NEWLINE# #INDENT# '\n        Test to get current timezone (i.e. America/Denver)\n        ' #NEWLINE# zone = 'MST' #NEWLINE# with patch . object ( salt . utils , 'which' , return_value = True ) : #NEWLINE# #INDENT# mock_cmd = MagicMock ( return_value = { #NEWLINE# #INDENT# 'stderr' : 'error' , #NEWLINE# 'retcode' : 1 , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( timezone . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : mock_cmd , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertRaises ( CommandExecutionError , timezone . get_zone ) #NEWLINE# #UNINDENT# mock_cmd = MagicMock ( return_value = { #NEWLINE# #INDENT# 'stdout' : 'Timezone: {0}' . format ( zone ) , #NEWLINE# 'retcode' : 0 , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( timezone . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : mock_cmd , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertEqual ( timezone . get_zone ( ) , zone ) #NEWLINE# #UNINDENT# mock_cmd = MagicMock ( return_value = { #NEWLINE# #INDENT# 'stdout' : 'ZoneCTL: {0}' . format ( zone ) , #NEWLINE# 'retcode' : 0 , #NEWLINE# #UNINDENT# } ) #NEWLINE# with patch . dict ( timezone . __salt__ , { #NEWLINE# #INDENT# 'cmd.run_all' : mock_cmd , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertRaises ( CommandExecutionError , timezone . get_zone ) #NEWLINE# #UNINDENT# #UNINDENT# with patch . object ( salt . utils , 'which' , return_value = False ) : #NEWLINE# #INDENT# file_data = '\n' . join ( [ '#' , 'A' ] ) #NEWLINE# with patch ( 'salt.utils.fopen' , mock_open ( read_data = file_data ) , create = True ) as mfile : #NEWLINE# #INDENT# mfile . return_value . __iter__ . return_value = file_data . splitlines ( ) #NEWLINE# with patch . dict ( timezone . __grains__ , { #NEWLINE# #INDENT# 'os_family' : 'Debian' , #NEWLINE# 'os' : 'Debian' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertEqual ( timezone . get_zone ( ) , '#\nA' ) #NEWLINE# #UNINDENT# #UNINDENT# with patch ( 'salt.utils.fopen' , mock_open ( read_data = file_data ) , create = True ) as mfile : #NEWLINE# #INDENT# mfile . return_value . __iter__ . return_value = file_data . splitlines ( ) #NEWLINE# with patch . dict ( timezone . __grains__ , { #NEWLINE# #INDENT# 'os_family' : 'Gentoo' , #NEWLINE# 'os' : 'Gentoo' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# self . assertEqual ( timezone . get_zone ( ) , '#\nA' ) #NEWLINE# #UNINDENT# #UNINDENT# with patch . dict ( timezone . __grains__ , { #NEWLINE# #INDENT# 'os_family' : 'FreeBSD' , #NEWLINE# 'os' : 'FreeBSD' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# zone = 'America/Denver' #NEWLINE# linkpath = ( '/usr/share/zoneinfo/' + zone ) #NEWLINE# with patch . object ( os , 'readlink' , return_value = linkpath ) : #NEWLINE# #INDENT# self . assertEqual ( timezone . get_zone ( ) , zone ) #NEWLINE# #UNINDENT# #UNINDENT# with patch . dict ( timezone . __grains__ , { #NEWLINE# #INDENT# 'os_family' : 'Solaris' , #NEWLINE# 'os' : 'Solaris' , #NEWLINE# #UNINDENT# } ) : #NEWLINE# #INDENT# fl_data = 'TZ=Foo\n' #NEWLINE# with patch ( 'salt.utils.fopen' , mock_open ( read_data = fl_data ) ) as mfile : #NEWLINE# #INDENT# mfile . return_value . __iter__ . return_value = [ fl_data ] #NEWLINE# self . assertEqual ( timezone . get_zone ( ) , 'Foo' )