def do_get_log(botname, **kwargs): data = request.get_json(force=True) lines = data.get('lines', None) if not data.get('name', False): return error_response("Specify a bot name.") username = github.get('user').get('login') bot_name = get_bot_name(username, data.get('name')) logs = deployer.bot_log(bot_name, lines=lines) return success_response(logs=dict(content=logs))
def do_get_log(botname, **kwargs): data = request.get_json(force=True) lines = data.get('lines', None) if not data.get('name', False): return "Specify a bot name." username = secure_filename(github.get('user').get('login')) bot_root = username + "-" + secure_filename(data.get('name')) bot_root = bot_root.lower() logs = deployer.bot_log(bot_root, lines=lines) return logs
def test_bot_log_all_success(self): bot_name = 'user1-bot_1' bot_logs = 'some\nbot\nlogs\nin\nseveral\nlines' docker_client = test_docker_client( containers=[ dict(id='c1', image_id='i1', status='running', logs=bot_logs) ], images=[dict(id='i1', tags=['zulip-{}:latest'.format(bot_name)])]) with patch('deployer.docker_client', new=docker_client): actual_logs = deployer.bot_log(bot_name) self.assertEqual(actual_logs, bot_logs)
def test_bot_logs_last_lines_success(self): bot_name = 'user1-bot_1' bot_logs_lines = ['line1', 'line2', 'line3'] docker_client = test_docker_client( containers=[ dict(id='c1', image_id='i1', status='running', logs='\n'.join(bot_logs_lines)) ], images=[dict(id='i1', tags=['zulip-{}:latest'.format(bot_name)])]) with patch('deployer.docker_client', new=docker_client): lines_count = len(bot_logs_lines) // 2 actual_logs = deployer.bot_log(bot_name, lines=lines_count) expected_logs = '\n'.join(bot_logs_lines[-lines_count:]) self.assertEqual(actual_logs, expected_logs)
def test_bot_log_not_found(self): docker_client = test_docker_client(containers=[], images=[]) with patch('deployer.docker_client', new=docker_client): logs = deployer.bot_log('non-existing-bot') self.assertEqual(logs, 'No logs found.')