Пример #1
0
    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')),
        ])
Пример #2
0
    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')),
        ])
Пример #3
0
    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()
Пример #4
0
    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()
Пример #5
0
    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')),
        ])
Пример #6
0
    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)),
        ])
Пример #7
0
    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')),
        ])
Пример #8
0
    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)),
        ])