<s> import os <EOL> import sys <EOL> import lxml . etree <EOL> from mock import Mock , MagicMock , patch <EOL> from Bcfg2 . Server . Plugins . Cfg . CfgExternalCommandVerifier import * <EOL> from Bcfg2 . Server . Plugin import PluginExecutionError <EOL> path = os . path . dirname ( __file__ ) <EOL> while path != "<STR_LIT:/>" : <EOL> if os . path . basename ( path ) . lower ( ) . startswith ( "<STR_LIT:test>" ) : <EOL> sys . path . append ( path ) <EOL> if os . path . basename ( path ) == "<STR_LIT>" : <EOL> break <EOL> path = os . path . dirname ( path ) <EOL> from common import * <EOL> from TestServer . TestPlugins . TestCfg . Test_init import TestCfgVerifier <EOL> class TestCfgExternalCommandVerifier ( TestCfgVerifier ) : <EOL> test_obj = CfgExternalCommandVerifier <EOL> def test_verify_entry ( self ) : <EOL> entry = lxml . etree . Element ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> metadata = Mock ( ) <EOL> ecv = self . get_obj ( ) <EOL> ecv . cmd = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:foo>" ] <EOL> ecv . exc = Mock ( ) <EOL> ecv . exc . run . return_value = Mock ( ) <EOL> ecv . exc . run . return_value . success = True <EOL> ecv . verify_entry ( entry , metadata , "<STR_LIT:data>" ) <EOL> ecv . exc . run . assert_called_with ( ecv . cmd , inputdata = "<STR_LIT:data>" ) <EOL> ecv . exc . reset_mock ( ) <EOL> ecv . exc . run . return_value . success = False <EOL> self . assertRaises ( CfgVerificationError , <EOL> ecv . verify_entry , entry , metadata , "<STR_LIT:data>" ) <EOL> ecv . exc . run . assert_called_with ( ecv . cmd , inputdata = "<STR_LIT:data>" ) <EOL> ecv . exc . reset_mock ( ) <EOL> ecv . exc . reset_mock ( ) <EOL> ecv . exc . run . side_effect = OSError <EOL> self . assertRaises ( CfgVerificationError , <EOL> ecv . verify_entry , entry , metadata , "<STR_LIT:data>" ) <EOL> ecv . exc . run . assert_called_with ( ecv . cmd , inputdata = "<STR_LIT:data>" ) <EOL> @ patch ( "<STR_LIT>" ) <EOL> def test_handle_event ( self , mock_access ) : <EOL> @ patch ( "<STR_LIT>" ) <EOL> def inner ( mock_handle_event ) : <EOL> ecv = self . get_obj ( ) <EOL> event = Mock ( ) <EOL> mock_access . return_value = False <EOL> ecv . data = "<STR_LIT:data>" <EOL> self . assertRaises ( PluginExecutionError , <EOL> ecv . handle_event , event ) <EOL> mock_handle_event . assert_called_with ( ecv , event ) <EOL> mock_access . assert_called_with ( ecv . name , os . X_OK ) <EOL> self . assertItemsEqual ( ecv . cmd , [ ] ) <EOL> mock_access . reset_mock ( ) <EOL> mock_handle_event . reset_mock ( ) <EOL> ecv . data = "<STR_LIT>" <EOL> ecv . handle_event ( event ) <EOL> mock_handle_event . assert_called_with ( ecv , event ) <EOL> mock_access . assert_called_with ( ecv . name , os . X_OK ) <EOL> self . assertEqual ( ecv . cmd , [ "<STR_LIT>" , "<STR_LIT>" , ecv . name ] ) <EOL> mock_access . reset_mock ( ) <EOL> mock_handle_event . reset_mock ( ) <EOL> mock_access . return_value = True <EOL> ecv . data = "<STR_LIT:true>" <EOL> ecv . handle_event ( event ) <EOL> mock_handle_event . assert_called_with ( ecv , event ) <EOL> mock_access . assert_called_with ( ecv . name , os . X_OK ) <EOL> self . assertItemsEqual ( ecv . cmd , [ ecv . name ] ) <EOL> inner ( ) <EOL> mock_access . return_value = True <EOL> TestCfgVerifier . test_handle_event ( self ) </s>
