<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import textwrap <EOL> from salttesting import TestCase , skipIf <EOL> from salttesting . mock import ( <EOL> MagicMock , <EOL> patch , <EOL> NO_MOCK , <EOL> NO_MOCK_REASON <EOL> ) <EOL> from salttesting . helpers import ensure_in_syspath <EOL> ensure_in_syspath ( '<STR_LIT>' ) <EOL> from salt . modules import rh_service <EOL> rh_service . __salt__ = { } <EOL> RET = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> HAS_UPSTART = None <EOL> def _m_disable ( ) : <EOL> '''<STR_LIT>''' <EOL> if HAS_UPSTART : <EOL> return MagicMock ( return_value = True ) <EOL> else : <EOL> return MagicMock ( return_value = False ) <EOL> def _m_enable ( ) : <EOL> '''<STR_LIT>''' <EOL> if HAS_UPSTART : <EOL> return MagicMock ( return_value = True ) <EOL> else : <EOL> return MagicMock ( return_value = False ) <EOL> def _m_isenabled ( ) : <EOL> '''<STR_LIT>''' <EOL> if HAS_UPSTART : <EOL> return MagicMock ( return_value = True ) <EOL> else : <EOL> return MagicMock ( return_value = False ) <EOL> rh_service . _upstart_disable = _m_disable ( ) <EOL> rh_service . _upstart_enable = _m_enable ( ) <EOL> rh_service . _upstart_is_enabled = _m_isenabled ( ) <EOL> @ skipIf ( NO_MOCK , NO_MOCK_REASON ) <EOL> class RhServiceTestCase ( TestCase ) : <EOL> '''<STR_LIT>''' <EOL> @ staticmethod <EOL> def _m_lst ( ) : <EOL> '''<STR_LIT>''' <EOL> return MagicMock ( return_value = [ ] ) <EOL> @ staticmethod <EOL> def _m_ret ( ) : <EOL> '''<STR_LIT>''' <EOL> return MagicMock ( return_value = RET ) <EOL> @ staticmethod <EOL> def _m_bool ( bol = True ) : <EOL> '''<STR_LIT>''' <EOL> return MagicMock ( return_value = bol ) <EOL> def test__chkconfig_is_enabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> name = '<STR_LIT>' <EOL> chkconfig_out = textwrap . dedent ( '''<STR_LIT>''' . format ( name ) ) <EOL> xinetd_out = textwrap . dedent ( '''<STR_LIT>''' . format ( name ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , MagicMock ( return_value = <NUM_LIT:3> ) ) : <EOL> mock_run = MagicMock ( return_value = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : chkconfig_out } ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_run } ) : <EOL> self . assertTrue ( rh_service . _chkconfig_is_enabled ( name ) ) <EOL> self . assertFalse ( rh_service . _chkconfig_is_enabled ( name , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( rh_service . _chkconfig_is_enabled ( name , <NUM_LIT:3> ) ) <EOL> mock_run = MagicMock ( return_value = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : xinetd_out } ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_run } ) : <EOL> self . assertTrue ( rh_service . _chkconfig_is_enabled ( name ) ) <EOL> self . assertTrue ( rh_service . _chkconfig_is_enabled ( name , <NUM_LIT:2> ) ) <EOL> self . assertTrue ( rh_service . _chkconfig_is_enabled ( name , <NUM_LIT:3> ) ) <EOL> def test_get_enabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = True <EOL> self . assertListEqual ( rh_service . get_enabled ( '<STR_LIT>' ) , [ ] ) <EOL> mock_run = MagicMock ( return_value = '<STR_LIT>' ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_run } ) : <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( ) ) : <EOL> self . assertListEqual ( rh_service . get_enabled ( '<STR_LIT>' ) , <EOL> RET ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_lst ( ) ) : <EOL> HAS_UPSTART = True <EOL> self . assertListEqual ( rh_service . get_enabled ( ) , RET ) <EOL> def test_get_disabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = False <EOL> self . assertListEqual ( rh_service . get_disabled ( '<STR_LIT>' ) , RET ) <EOL> mock_run = MagicMock ( return_value = '<STR_LIT>' ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_run } ) : <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( False ) ) : <EOL> self . assertListEqual ( rh_service . get_disabled ( '<STR_LIT>' ) , <EOL> RET ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_lst ( ) ) : <EOL> HAS_UPSTART = False <EOL> self . assertListEqual ( rh_service . get_disabled ( ) , RET ) <EOL> def test_get_all ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> self . assertListEqual ( rh_service . get_all ( '<STR_LIT>' ) , RET ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_ret ( ) ) : <EOL> self . assertListEqual ( rh_service . get_all ( '<STR_LIT>' ) , RET ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_lst ( ) ) : <EOL> self . assertListEqual ( rh_service . get_all ( ) , RET ) <EOL> def test_available ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . available ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . available ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . available ( '<STR_LIT>' ) ) <EOL> def test_missing ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( False ) ) : <EOL> self . assertTrue ( rh_service . missing ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( False ) ) : <EOL> self . assertTrue ( rh_service . missing ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertFalse ( rh_service . missing ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( ) ) : <EOL> self . assertFalse ( rh_service . missing ( '<STR_LIT>' ) ) <EOL> def test_start ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : <EOL> self . _m_bool ( False ) } ) : <EOL> self . assertTrue ( rh_service . start ( '<STR_LIT>' ) ) <EOL> def test_stop ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : <EOL> self . _m_bool ( False ) } ) : <EOL> self . assertTrue ( rh_service . stop ( '<STR_LIT>' ) ) <EOL> def test_restart ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : <EOL> self . _m_bool ( False ) } ) : <EOL> self . assertTrue ( rh_service . restart ( '<STR_LIT>' ) ) <EOL> def test_reload ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : <EOL> self . _m_bool ( False ) } ) : <EOL> self . assertTrue ( rh_service . reload_ ( '<STR_LIT>' ) ) <EOL> def test_status ( self ) : <EOL> '''<STR_LIT>''' <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> mock_run = MagicMock ( return_value = '<STR_LIT>' ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_run } ) : <EOL> self . assertTrue ( rh_service . status ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( False ) ) : <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : <EOL> self . _m_bool ( ) } ) : <EOL> self . assertTrue ( rh_service . status ( '<STR_LIT>' , sig = True ) ) <EOL> mock_ret = MagicMock ( return_value = <NUM_LIT:0> ) <EOL> with patch . dict ( rh_service . __salt__ , { '<STR_LIT>' : mock_ret } ) : <EOL> self . assertTrue ( rh_service . status ( '<STR_LIT>' ) ) <EOL> def test_enable ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_bool = MagicMock ( side_effect = [ True , False ] ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , mock_bool ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = True <EOL> self . assertFalse ( rh_service . enable ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . enable ( '<STR_LIT>' ) ) <EOL> def test_disable ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_bool = MagicMock ( side_effect = [ True , False ] ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , mock_bool ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = True <EOL> self . assertFalse ( rh_service . disable ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . disable ( '<STR_LIT>' ) ) <EOL> def test_enabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_bool = MagicMock ( side_effect = [ True , False ] ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , mock_bool ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = True <EOL> self . assertFalse ( rh_service . enabled ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , self . _m_bool ( ) ) : <EOL> self . assertTrue ( rh_service . enabled ( '<STR_LIT>' ) ) <EOL> def test_disabled ( self ) : <EOL> '''<STR_LIT>''' <EOL> mock_bool = MagicMock ( side_effect = [ True , False ] ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , mock_bool ) : <EOL> global HAS_UPSTART <EOL> HAS_UPSTART = False <EOL> self . assertTrue ( rh_service . disabled ( '<STR_LIT>' ) ) <EOL> with patch . object ( rh_service , '<STR_LIT>' , <EOL> self . _m_bool ( False ) ) : <EOL> self . assertTrue ( rh_service . disabled ( '<STR_LIT>' ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from integration import run_tests <EOL> run_tests ( RhServiceTestCase , needs_daemon = False ) </s>
