<s> import mock <EOL> import testtools <EOL> from shaker . agent import agent <EOL> class TestAgent ( testtools . TestCase ) : <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_work_act_idle ( self , mock_sleep ) : <EOL> agent_id = '<STR_LIT>' <EOL> polling_interval = <NUM_LIT:10> <EOL> mock_socket = mock . Mock ( ) <EOL> mock_socket . recv_json . side_effect = [ { } ] <EOL> agent . work_act ( mock_socket , agent_id , polling_interval ) <EOL> mock_sleep . assert_called_once_with ( polling_interval ) <EOL> mock_socket . send_json . assert_called_once_with ( <EOL> dict ( operation = '<STR_LIT>' , agent_id = agent_id ) ) <EOL> mock_socket . recv_json . assert_called_once_with ( ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_work_act_execute ( self , mock_run_command , mock_sleep ) : <EOL> agent_id = '<STR_LIT>' <EOL> polling_interval = <NUM_LIT:10> <EOL> mock_socket = mock . Mock ( ) <EOL> mock_socket . recv_json . side_effect = [ <EOL> dict ( operation = '<STR_LIT>' ) , dict ( ) , <EOL> ] <EOL> execute_result = { '<STR_LIT>' : '<STR_LIT:data>' } <EOL> mock_run_command . return_value = execute_result <EOL> agent . work_act ( mock_socket , agent_id , polling_interval ) <EOL> mock_sleep . assert_called_once_with ( polling_interval ) <EOL> mock_socket . send_json . assert_has_calls ( [ <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id ) ) , <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id , res = '<STR_LIT:data>' ) ) , <EOL> ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_work_act_schedule ( self , mock_run_command , mock_now , mock_sleep ) : <EOL> agent_id = '<STR_LIT>' <EOL> polling_interval = <NUM_LIT:10> <EOL> start_at = <NUM_LIT> <EOL> now = <NUM_LIT> <EOL> mock_socket = mock . Mock ( ) <EOL> mock_socket . recv_json . side_effect = [ <EOL> dict ( operation = '<STR_LIT>' , start_at = start_at ) , dict ( ) , <EOL> ] <EOL> execute_result = { '<STR_LIT>' : '<STR_LIT:data>' } <EOL> mock_run_command . return_value = execute_result <EOL> mock_now . return_value = now <EOL> agent . work_act ( mock_socket , agent_id , polling_interval ) <EOL> mock_sleep . assert_has_calls ( [ <EOL> mock . call ( start_at - now ) , <EOL> mock . call ( polling_interval ) , <EOL> ] ) <EOL> mock_socket . send_json . assert_has_calls ( [ <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id ) ) , <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id , res = '<STR_LIT:data>' ) ) , <EOL> ] ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> @ mock . patch ( '<STR_LIT>' ) <EOL> def test_work_act_configure ( self , mock_run_command , mock_sleep ) : <EOL> agent_id = '<STR_LIT>' <EOL> polling_interval = <NUM_LIT:10> <EOL> mock_socket = mock . Mock ( ) <EOL> mock_socket . recv_json . side_effect = [ <EOL> dict ( operation = '<STR_LIT>' , polling_interval = polling_interval ) , <EOL> dict ( ) , <EOL> ] <EOL> agent . work_act ( mock_socket , agent_id , polling_interval ) <EOL> mock_sleep . assert_has_calls ( [ <EOL> mock . call ( polling_interval ) , <EOL> ] ) <EOL> mock_socket . send_json . assert_has_calls ( [ <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id ) ) , <EOL> mock . call ( dict ( operation = '<STR_LIT>' , agent_id = agent_id ) ) , <EOL> ] ) </s>
