コード例 #1
0
ファイル: test_bconsole.py プロジェクト: gypsymauro/almir
    def test_send_command_by_polling(self):
        b = BConsole()
        with patch.object(b, 'start_process') as mock_method:
            mock_method.return_value = Popen(['cat'], stdout=PIPE, stdin=PIPE, stderr=PIPE)

            process, outputs = b.send_command_by_polling('version')
            self.assertEqual(outputs['commands'][0], 'version<br />')

            process.kill()
            time.sleep(1)
            process, outputs = b.send_command_by_polling('version', process)
            self.assertTrue('error' in outputs)

        with patch.object(b, 'start_process') as mock_method:
            start_process = mock_method.return_value
            start_process.communicate.return_value = ('error', 'error')

            process, outputs = b.send_command_by_polling('quit')
            self.assertEqual(outputs['commands'][0], 'Try harder.')
コード例 #2
0
ファイル: test_bconsole.py プロジェクト: weaselshit/almir
    def test_send_command_by_polling(self):
        b = BConsole()
        with patch.object(b, 'start_process') as mock_method:
            mock_method.return_value = Popen(['cat'], stdout=PIPE, stdin=PIPE, stderr=PIPE)

            process, outputs = b.send_command_by_polling('version')
            self.assertEqual(outputs['commands'][0], 'version<br />')

            process.kill()
            time.sleep(1)
            process, outputs = b.send_command_by_polling('version', process)
            self.assertTrue('error' in outputs)

        with patch.object(b, 'start_process') as mock_method:
            start_process = mock_method.return_value
            start_process.communicate.return_value = ('error', 'error')

            process, outputs = b.send_command_by_polling('quit')
            self.assertEqual(outputs['commands'][0], 'Try harder.')
コード例 #3
0
ファイル: views.py プロジェクト: gypsymauro/almir
def ajax_console_input(request):
    global bconsole_session
    # TODO: if status for client is requested, it might timeout after few seconds, but not 0.5
    # TODO: thread locking
    # TODO: implement session based on cookie
    # TODO: stderr?

    if not request.POST['bconsole_command'] and bconsole_session is not None:
        return {"commands": list(command_cache)}

    b = BConsole()
    bconsole_session, response = b.send_command_by_polling(request.POST['bconsole_command'], bconsole_session)

    if 'error' in response:
        command_cache.clear()

    if 'commands' in response:
        command_cache.extend(response['commands'])
    return response
コード例 #4
0
ファイル: views.py プロジェクト: weaselshit/almir
def ajax_console_input(request):
    global bconsole_session
    # TODO: if status for client is requested, it might timeout after few seconds, but not 0.5
    # TODO: thread locking
    # TODO: implement session based on cookie
    # TODO: stderr?

    if not request.POST['bconsole_command'] and bconsole_session is not None:
        return {"commands": list(command_cache)}

    b = BConsole()
    bconsole_session, response = b.send_command_by_polling(request.POST['bconsole_command'], bconsole_session)

    if 'error' in response:
        command_cache.clear()

    if 'commands' in response:
        command_cache.extend(response['commands'])
    return response