def clean_project_reports(project_id): try: request_data = request.get_json() operator = request_data.pop('operator') project_id = request_data.get('projectId') clean_date = request_data.get('cleanDate') execution_mode = request_data.get('executionMode') clean_dict = dict() clean_dict["projectId"] = project_id clean_dict["executionMode"] = execution_mode clean_dict["createAt"] = {"$lt": datetime.utcnow() - timedelta(days=clean_date)} total_num, reports = common.get_total_num_and_arranged_data(TestReport, clean_dict) clean_report_ids = list(map(lambda x: x.get("_id"), reports)) if len(clean_report_ids): for clean_report_id in clean_report_ids: TestReport.delete_one({'_id': ObjectId(clean_report_id)}) TestReportDetail.delete_many({'reportId': ObjectId(clean_report_id)}) current_app.logger.info( "delete report successfully. Project ID:{},cleanDate:{},operator:{},deletedReportIds:{}".format( project_id, clean_date, operator, str(clean_report_ids))) return jsonify({'status': 'ok', 'data': '删除报告成功'}) else: current_app.logger.info( "no report need to be deleted. Project ID:{},cleanDate:{},operator:{}".format(project_id, clean_date, operator)) return jsonify({'status': 'ok', 'data': '未找到要删除的报告'}) except BaseException as e: current_app.logger.error("delete report failed. - %s" % str(e)) return jsonify({'status': 'failed', 'data': '删除报告失败: %s' % e})
def cron_list(): def time_stamp2str(cron): if cron.get('next_run_time'): cron['next_run_time'] = common.time_stamp2str(cron['next_run_time']) return cron total_num, crons = common.get_total_num_and_arranged_data(CronTab, request.args) crons = list(map(time_stamp2str, crons)) return jsonify({'status': 'ok', 'data': {'totalNum': total_num, 'rows': crons}})
def cron_job_list(project_id): def time_stamp2str(cron): if cron.get('next_run_time'): cron['next_run_time'] = common.time_stamp2str(cron['next_run_time']) return cron total_num, cron_jobs = common.get_total_num_and_arranged_data(CronJob, request.args, fuzzy_fields=['name']) cron_jobs = list(map(time_stamp2str, cron_jobs)) return jsonify({'status': 'ok', 'data': {'totalNum': total_num, 'rows': cron_jobs}})
def mock_api_list(): total_num, mock_apis = common.get_total_num_and_arranged_data( MockData, request.args, fuzzy_fields=['name', 'category']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': mock_apis } })
def test_env_list(project_id): total_num, envs = common.get_total_num_and_arranged_data( TestEnv, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': envs } })
def mail_sender_list(): total_num, mail_senders = common.get_total_num_and_arranged_data( MailSender, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': mail_senders } })
def host_list(project_id): total_num, hosts = common.get_total_num_and_arranged_data( Host, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': hosts } })
def mail_group_list(): total_num, mail_groups = common.get_total_num_and_arranged_data( MailGroup, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': mail_groups } })
def project_list(): total_num, projects = common.get_total_num_and_arranged_data( Project, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': projects } })
def tet_suite_param_list(project_id, test_suite_id): total_num, param_list = common.get_total_num_and_arranged_data( TestSuiteParam, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': param_list } })
def env_config_list(): total_num, envs = common.get_total_num_and_arranged_data( EnvConfig, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': envs } })
def get_role_list(): total_num, roles = common.get_total_num_and_arranged_data( Role, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': roles } })
def case_list(project_id, case_suite_id): total_num, testing_cases = common.get_total_num_and_arranged_data( TestingCase, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': testing_cases } })
def db_config_list(): total_num, dbs = common.get_total_num_and_arranged_data( DBConfig, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': dbs } })
def case_suite_list(project_id): total_num, case_suites = common.get_total_num_and_arranged_data( CaseSuite, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': case_suites } })
def get_report_list(project_id): total_num, reports = common.get_total_num_and_arranged_data( TestReport, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': reports } })
def get_test_case_reports(report_id, suite_id): total_num, reports = common.get_total_num_and_arranged_data( TestReportDetail, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': reports } })
def mail_list(): total_num, mails = common.get_total_num_and_arranged_data( MailRecipient, request.args, fuzzy_fields=['email']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': mails } })
def mail_list(project_id): total_num, mails = common.get_total_num_and_arranged_data( Mail, request.args) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': mails } })
def plan_list(): total_num, plans = common.get_total_num_and_arranged_data( Plan, request.args, fuzzy_fields=['name']) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': plans } })
def project_list(): total_num, projects = common.get_total_num_and_arranged_data( Project, request.args, fuzzy_fields=['name']) total_num, projects = filter_projects_by_user(current_user, total_num, projects) return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': projects } })
def reports_list(project_id): # TODO 性能优化 total_num, test_reports = common.get_total_num_and_arranged_data( TestReport, request.args) for test_report in test_reports: del test_report['testDetail'] return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': test_reports } })
def get_plan_report_detail(plan_report_id): request_data = request.args.to_dict() request_data.setdefault("planReportId", ObjectId(plan_report_id)) total_num, reports = common.get_total_num_and_arranged_data( TestReport, request_data) new_reports = list(map(set_project_name, reports)) # set projectName return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': new_reports } })
def get_user_list(): total_num, users = common.get_total_num_and_arranged_data( LeoUser, request.args, fuzzy_fields=['email']) for user in users: user_data = user_data_store.find_user(email=user['email']) roles_name = [] for role in user_data.roles: if role and role.name not in roles_name: roles_name.append(role.name) user['roleNames'] = roles_name return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': users } })
def delete_project(project_id): try: if not project_id: raise ValueError("project_id is empty!") delete_suites_count = 0 delete_cases_count = 0 Project.update({'_id': ObjectId(project_id)}, {'$set': { 'isDeleted': True }}) query = dict() query["projectId"] = ObjectId(project_id) total_num, test_suites = common.get_total_num_and_arranged_data( TestSuite, query) update_suite_response = TestSuite.update_many( {'projectId': ObjectId(project_id)}, {'$set': { 'isDeleted': True }}) delete_suites_count += update_suite_response.modified_count for test_suite in test_suites: update_case_response = TestCase.update_many( {'testSuiteId': ObjectId(test_suite['_id'])}, {'$set': { 'isDeleted': True }}) delete_cases_count += update_case_response.modified_count with app.app_context(): current_app.logger.info( "Delete project successfully. ProjectId:{}, Deleted Test Suites Count:{}, " "Deleted Test Cases Count:{}, User:{}".format( project_id, delete_suites_count, delete_cases_count, current_user.email)) except BaseException as e: with app.app_context(): current_app.logger.error( "delete project failed. User:{}, error:{}".format( current_user.email, str(e))) raise BaseException(str(e))
def case_list(project_id, test_suite_id): try: total_num, test_cases = common.get_total_num_and_arranged_data( TestCase, request.args, fuzzy_fields=['name']) for test_case in test_cases: if "lastManualResult" in test_case and "status" in test_case[ 'lastManualResult']: test_case['lastManualResult'] = { "status": test_case['lastManualResult']["status"] } return jsonify({ 'status': 'ok', 'data': { 'totalNum': total_num, 'rows': test_cases } }) except BaseException as e: current_app.logger.error("get case list failed. - %s" % str(e)) return jsonify({ 'status': 'failed', 'data': 'get case list failed %s' % str(e) })
def test_data_storage_list(project_id): # TODO 性能优化 total_num, storages = common.get_total_num_and_arranged_data(TestDataStorage, request.args, fuzzy_fields=['name']) return jsonify({'status': 'ok', 'data': {'totalNum': total_num, 'rows': storages}})