Пример #1
0
def spider_batch():
    form = CaseBatchForm().validate_for_api()
    #将之前的最后一次执行记录设置为非最后一次执行记录
    Case.set_is_new_false(form.task_id.data)
    task_cases = TaskCase.query.filter_by(task_id=form.task_id.data).all()
    #需要执行的case列表
    case_list = []
    for task_case in task_cases:
        case = Case()
        case.case_id = task_case.case_id
        case.case_name = task_case.case_name
        case.is_run = task_case.is_run
        case.method = task_case.method
        case.url = task_case.url
        case.header = task_case.header
        case.deal_method = task_case.deal_method
        case.dependent_case = task_case.dependent_case
        case.need_position = task_case.need_position
        case.submission = task_case.submission
        case.data = task_case.data
        case.expect_result = task_case.expect_result
        case.task = task_case.task
        case.task_id = task_case.task_id
        case.task_case_id = task_case.id
        case_list.append(case)
Пример #2
0
    def delete_tasks(cls, user, project, no, start, end):
        tasks = cls.query.filter(
            cls.create_user == user if user else '',
            cls.project_id == project if project else '',
            cls.task_no.like(f'%{no}%') if no is not None else '',
            cls._create_time.between(start, end) if start and end else '',
            cls.delete_time == None,
        ).all()
        task_no_list = [task.task_no for task in tasks]
        try:
            for task in tasks:
                task.delete_time = datetime.now()
            db.session.commit()
            # 删除task全局变量
            [mongo.db.task.delete_one({'task_id': task.id}) for task in tasks]
            # 删除日志
            for task_no in task_no_list:
                Case.case_log_remove(name=None,
                                     url=None,
                                     project=None,
                                     task=task_no,
                                     result=None,
                                     start=None,
                                     end=None)
        except Exception:
            db.session.rollback()
            raise RecordRemoveException()

        return len(tasks)
Пример #3
0
def case_download():
    form = CaseSearchForm().validate_for_api()
    # 查询用例
    search_result = Case.case_download_search(form.name.data, form.url.data, form.caseGroup.data, form.start.data,
                                              form.end.data, form.id.data, form.method.data, form.deal.data)
    # 复制模板
    download_file_path, directory, filename = Case.copy_excel_template()
    # 写入用例
    Case.write_case_excel(search_result, download_file_path)
    # 下载
    response = make_response(send_from_directory(directory, filename, as_attachment=True))

    return response
Пример #4
0
def upload_case():
    config = {
        'INCLUDE': ['xlsx', 'xls'],
        'SINGLE_LIMIT': 2048 * 1000,
        'NUMS': 1,
        'STORE_DIR': 'app/document/excel/upload'
    }

    files = request.files
    uploader = CaseUploader(files, config)
    ret = uploader.upload()
    Case.upload_add(ret[0]['url'])
    return Success(msg='用例上传成功')
Пример #5
0
def create_case(
        *,
        db: Session = Depends(get_db),
        name: CreateCasePayload,
        current_user: DBUser = Depends(get_current_active_user),
):
    """
    Create new user
    """

    user = crud.case.get_by_case_number(db,
                                        name=name.name,
                                        user_details=current_user)
    if user:
        raise HTTPException(
            status_code=400,
            detail="The case with this name already exists in the system.",
        )
    try:
        case_in = Case(business_id=current_user.business_id,
                       name=name.name,
                       created_by=current_user.id,
                       modified_by=current_user.id)

        user = crud.case.create(db, case_in=case_in)

        return user
    except Exception as e:
        print(e)
        raise HTTPException(
            status_code=400,
            detail=str(e),
        )
Пример #6
0
def today():
    test_count, test_project_count = Task.today()
    return {
        'case_add_count': Case.today(),
        'test_count': test_count,
        'test_project_count': test_project_count
    }
Пример #7
0
def create_case():
    form = CaseForm().validate_for_api()
    case = Case(form.caseGroup.data, form.name.data, form.info.data, form.url.data, form.method.data, form.submit.data,
                form.header.data, form.data.data, form.deal.data, form.condition.data, form.expect.data,
                form.assertion.data, form.type.data)
    case.new_case()
    return Success(msg='新增用例成功')
Пример #8
0
def total():
    return {
        'project': Project.total(),
        'case': Case.total(),
        'scheduler': Scheduler.total(),
        'mock': Mock.total()
    }
Пример #9
0
 def batch(cls, project, create_user):
     project.var_dick = {}
     configs = cls.query.filter_by(project_id=project.id,
                                   is_run=True).order_by(cls.order).all()
     if not configs:
         raise ConfigNotFound(msg='工程下无可运行用例')
     # 执行用例总数
     total = len(configs)
     task = Task(project.id, create_user.id, total)
     task.new_task()
     task.update_task_no()
     step = 100 / total
     progress = 0
     with db.session.no_autoflush:
         for config in configs:
             case = Case(0, config.name, config.info, config.url,
                         config.method, config.submit, config.header,
                         config.data, config.deal, config.condition,
                         config.expect, config.assertion, config.type)
             case.id = config.case_id
             # 副本工程类型 不管理原用例分组
             case.case_group = None
             case.case_group_name = None
             case.execute_one(project, task, create_user)
             progress += step
             # 更新工程进度
             project.update_progress(progress)
Пример #10
0
def task_log(taskNo):
    logs = Case.case_log_search_all(taskNo)
    logs_lists = []
    for log in logs:
        l = log_format(log)
        logs_lists.append(l)
    socket_io.emit('log', {'logs': logs_lists, 'task_no': taskNo})
    return Success(msg='广播成功')
Пример #11
0
def edit_logs_delete():
    form = CaseEditLogForm().validate_for_api()
    count = Case.edit_logs_remove(form.id.data, form.url.data, form.method.data, form.deal.data, form.start.data,
                                  form.end.data)
    if count == 0:
        return Success(msg='无符合条件数据')
    else:
        return Success(msg='成功删除' + str(count) + '条数据')
Пример #12
0
def search_case():
    form = CaseSearchForm().validate_for_api()
    search_result = Case.paginate_query(form.page.data, form.task_id.data,
                                        form.case_name.data, form.url.data,
                                        form.is_new.data, form.user_name.data,
                                        form.task_name.data, form.result.data,
                                        form.startDate.data, form.endDate.data)
    return jsonify(search_result)
Пример #13
0
def case_logs_delete():
    form = CaseLogsSearchForm().validate_for_api()
    count = Case.case_log_remove(form.name.data, form.url.data, form.project.data, form.task.data,
                                 form.result.data, form.start.data, form.end.data)
    if count == 0:
        return Success(msg='无符合条件数据')
    else:
        return Success(msg='成功删除' + str(count) + '条数据')
Пример #14
0
def case_detail():
    form = CaseDetailForm().validate_for_api()
    case = Case()
    case.id = form.id.data
    detail = case.get_case_detail()
    detail.set_keys('case_id', 'case_name', 'is_run', 'method', 'url',
                    'header', 'deal_method', 'dependent_case', 'need_position',
                    'submission', 'data', 'expect_result', 'actual_result',
                    'interface_return', 'task_name', 'user_name', 'is_new')
    return jsonify(detail)
Пример #15
0
def run_requests():
    form = CaseForm().validate_for_api()
    case = Case()
    case.case_name = form.case_name.data
    case.method = form.method.data
    case.url = form.url.data
    case.header = form.header.data
    case.data = form.data.data
    case.submission = form.submission.data
    case.expect_result = form.expect_result.data
    case.pass_or_fail()
    #将返回数据格式化为字符串
    if isinstance(case.data, dict):
        case.data = json.dumps(case.data, ensure_ascii=False)
Пример #16
0
 def batch(cls, project, create_user):
     project.var_dick = {}
     # 获取用户自定义的运行时变量
     param = project.get_user_parameters()['param']
     # 将变量加入到全局字典
     project.var_dick.update(param) if param else ''
     log.logger.info(project.var_dick)
     configs = cls.query.filter_by(project_id=project.id,
                                   is_run=True).order_by(cls.order).all()
     if not configs:
         raise ConfigNotFound(msg='工程下无可运行用例')
     # 执行用例总数
     total = len(configs)
     task = Task(project.id, create_user.id, total)
     task.new_task()
     task.update_task_no()
     step = 100 / total
     progress = 0
     with db.session.no_autoflush:
         for config in configs:
             case_source = Case.query.filter_by(id=config.case_id,
                                                delete_time=None).first()
             # 此处需实例化一个case用于执行 如果使用 case_source 则会自动更新数据库case表
             case = Case(0, case_source.name, case_source.info,
                         case_source.url, case_source.method,
                         case_source.submit, case_source.header,
                         case_source.data, case_source.deal,
                         case_source.condition, case_source.expect,
                         case_source.assertion, case_source.type)
             case.id = config.case_id
             case.case_group = case_source.case_group
             group = CaseGroup.query.filter_by(id=case.case_group).first()
             if group:
                 case.case_group_name = group.name
             else:
                 case.case_group_name = None
             case.actual_result = False
             case.reason = None
             case.result = {}
             # 执行一条用例
             case.execute_one(project, task, create_user)
             progress += step
             # 更新工程进度
             project.update_progress(progress)
Пример #17
0
def debug():
    form = CaseDebugForm().validate_for_api()
    case = Case(None, None, None, form.url.data, form.method.data, form.submit.data, form.header.data, form.data.data)
    result = case.case_debug()
    return jsonify(result)
Пример #18
0
def cases_by_group():
    form = CaseSearchForm().validate_for_api()
    cases = Case.cases_by_group(form.caseGroup.data)
    return jsonify(cases)
Пример #19
0
    def build_report(self):
        # 测试时间
        report_time = self._create_time.strftime("%Y-%m-%d %H:%M")
        # 被测试工程
        from app.models.project import Project
        project = Project.query.filter_by(id=self.project_id).first()
        # 测试人员
        tester = manager.user_model.query.filter_by(
            id=self.create_user).first()
        # task 成功个数
        if self.success:
            input_success = '<input checked="true" class="filter" data-test-result="passed" hidden="true" ' \
                            'name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span ' \
                            'class="passed">' + str(self.success) + ' passed</span>'
        else:
            input_success = '<input checked="true" class="filter" disabled="true" data-test-result="passed" ' \
                            'hidden="true" name="filter_checkbox" onChange="filter_table(this)" ' \
                            'type="checkbox"/><span class="passed">' + str(self.success) + ' passed</span>'
        # task 失败个数
        if self.fail:
            input_fail = '<input checked="true" class="filter" data-test-result="failed" hidden="true" ' \
                         'name="filter_checkbox" onChange="filter_table(this)" type="checkbox"/><span ' \
                         'class="failed">' + str(self.fail) + ' passed</span>'
        else:
            input_fail = '<input checked="true" class="filter" disabled="true" data-test-result="failed" ' \
                         'hidden="true" name="filter_checkbox" onChange="filter_table(this)" ' \
                         'type="checkbox"/><span class="failed">' + str(self.fail) + ' failed</span>'
        # 用例记录
        logs = Case.case_log_search_all(self.task_no)
        table_logs = ''
        for log in logs:
            result = 'Passed' if log['actual_result'] else 'Failed'
            expect = log['expect'] if log['expect'] else ''
            interface_return = log['result']['text'] if log['result'] else ''
            if log['actual_result']:
                table_tr = '<tbody class="passed results-table-row"><tr><td class="col-result">' + result + \
                           '</td><td class="col-name">' + log['name'] + \
                           '</td><td class="col-method">' + log['method_text'] + '</td><td class="col-url">' + \
                           log['url'] + '</td><td class="col-assertion">' + log['assertion_text'] + \
                           '</td><td class="col-expect">' + expect + \
                           '</td></tr><tr><td class="extra" colspan="6"><div class="empty log">' \
                           + interface_return + '</div></td></tr></tbody>'
            else:
                table_tr = '<tbody class="failed results-table-row"><tr><td class="col-result">' + result + \
                           '</td><td class="col-name">' + log['name'] + \
                           '</td><td class="col-method">' + log['method_text'] + '</td><td class="col-url">' + \
                           log['url'] + '</td><td class="col-assertion">' + log['assertion_text'] + \
                           '</td><td class="col-expect">' + expect + \
                           '</td></tr><tr><td class="extra" colspan="6"><div class="empty log">' \
                           + interface_return + '</div></td></tr></tbody>'
            table_logs = table_logs + table_tr

        download_file, download_directory, download_filename = self.copy_report_template(
        )
        old_file = open(download_file, "r", encoding='utf-8')
        report = old_file.read()
        old_file.close()
        new_file = report.replace('{{ logs }}', table_logs).replace(
            '{{ input_success }}', input_success).replace(
                '{{ input_fail }}',
                input_fail).replace('{{ project }}', project.name).replace(
                    '{{ report_time }}',
                    report_time).replace('{{ tester }}', tester.username)
        with open(download_file, "w", encoding='utf-8') as f:
            f.write(new_file)

        return download_file, download_directory, download_filename
Пример #20
0
def case_logs_all():
    form = CaseLogsSearchForm().validate_for_api()
    cases = Case.case_log_search_all(form.task.data)
    return jsonify(cases)
Пример #21
0
def case_logs():
    form = CaseLogsSearchForm().validate_for_api()
    cases = Case.case_log_search(form.id.data, form.name.data, form.url.data, form.project.data, form.task.data,
                                 form.result.data, form.start.data, form.end.data, form.count.data, form.page.data)
    return jsonify(cases)
Пример #22
0
def group_by_case_group():
    result = Case.group_by_case_group()
    return jsonify(result)
Пример #23
0
def search_edit_logs():
    form = CaseEditLogForm().validate_for_api()
    edit_logs = Case.search_edit_logs(form.id.data, form.url.data, form.method.data, form.deal.data, form.start.data,
                                      form.end.data, form.count.data, form.page.data)

    return jsonify(edit_logs)
Пример #24
0
def case():
    form = MineSearchForm().validate_for_api()
    cases = Case.user_case(form.uid.data, form.name.data, form.page.data,
                           form.count.data)
    return jsonify(cases)
Пример #25
0
def case_top():
    return Case.top()
Пример #26
0
def get_case():
    form = CaseSearchForm().validate_for_api()
    result = Case.search_case(form.name.data, form.url.data, form.caseGroup.data, form.start.data, form.end.data,
                              form.id.data, form.method.data, form.deal.data, form.page.data, form.count.data)

    return jsonify(result)