def test_work_act_schedule(self, mock_run_command, mock_now, mock_sleep): agent_id = 'the-agent' polling_interval = 10 start_at = 1234 now = 1230 mock_socket = mock.Mock() mock_socket.recv_json.side_effect = [ dict(operation='execute', start_at=start_at), dict(), ] execute_result = {'res': 'data'} mock_run_command.return_value = execute_result mock_now.return_value = now agent.work_act(mock_socket, agent_id, polling_interval) mock_sleep.assert_has_calls([ mock.call(start_at - now), mock.call(polling_interval), ]) mock_socket.send_json.assert_has_calls([ mock.call(dict(operation='poll', agent_id=agent_id)), mock.call(dict(operation='reply', agent_id=agent_id, res='data')), ])
def test_work_act_idle(self, mock_sleep): agent_id = 'the-agent' polling_interval = 10 mock_socket = mock.Mock() mock_socket.recv_json.side_effect = [{}] agent.work_act(mock_socket, agent_id, polling_interval) mock_sleep.assert_called_once_with(polling_interval) mock_socket.send_json.assert_called_once_with( dict(operation='poll', agent_id=agent_id)) mock_socket.recv_json.assert_called_once_with()
def test_work_act_execute(self, mock_run_command, mock_sleep): agent_id = 'the-agent' polling_interval = 10 mock_socket = mock.Mock() mock_socket.recv_json.side_effect = [ dict(operation='execute'), dict(), ] execute_result = {'res': 'data'} mock_run_command.return_value = execute_result agent.work_act(mock_socket, agent_id, polling_interval) mock_sleep.assert_called_once_with(polling_interval) mock_socket.send_json.assert_has_calls([ mock.call(dict(operation='poll', agent_id=agent_id)), mock.call(dict(operation='reply', agent_id=agent_id, res='data')), ])
def test_work_act_configure(self, mock_run_command, mock_sleep): agent_id = 'the-agent' polling_interval = 10 mock_socket = mock.Mock() mock_socket.recv_json.side_effect = [ dict(operation='configure', polling_interval=polling_interval), dict(), ] agent.work_act(mock_socket, agent_id, polling_interval) mock_sleep.assert_has_calls([ mock.call(polling_interval), ]) mock_socket.send_json.assert_has_calls([ mock.call(dict(operation='poll', agent_id=agent_id)), mock.call(dict(operation='reply', agent_id=agent_id)), ])