Ejemplo n.º 1
0
def create_project():
    form = ProjectAddForm(request.form)
    if request.method == 'GET':
        return render_template('project.html', form=form)
    if form.validate():

        ProjectInfo.add_by_form(form)
        return redirect(url_for('web.list_projects'))
    print(form.errors)
    return render_template('project.html', form=form)
Ejemplo n.º 2
0
def delete_project():
    # 获取id
    # current_user == User()
    p_id = request.json.get('id')
    if not p_id.isdigit():
        raise JsonValidateError()
    project = ProjectInfo.get(int(p_id))
    if not project:
        raise JsonValidateError()
    try:
        ProjectInfo.delete(p_id)
        return jsonify({'msg': '成功'})
    except DatabaseException:
        raise JsonDatabaseError('数据库异常')
Ejemplo n.º 3
0
def edit_suite(s_id=None):
    req = request.json or {}
    # 转成字符串,不然解析只能得到一个字典,而不是一个列表。
    includes = str(req['includes']) if 'includes' in req else ''
    req['includes'] = includes.replace("'", '"')
    form = SuiteAddForm(data=req)
    # 添加接口所属项目可选项
    project_choices = ProjectInfo.all()

    suite = SuiteInfo.get(s_id)
    if suite is None:
        return render_template('suites.html',
                               form=form,
                               projects=project_choices)
    # form.project_id.choices.extend([(str(p.id), p.project_name) for p in project_choices])
    if request.method == 'GET':
        cases = json.loads(suite.includes)
        return render_template('suite_edit.html',
                               form=form,
                               projects=project_choices,
                               suite=suite,
                               cases=cases)

    if not form.validate():
        msg = ''
        for k, v in form.errors.items():
            msg = msg.join([k, ':', v[0], '; '])
        raise JsonValidateError(msg)

    SuiteInfo.update_by_form(form)
    return jsonify({'msg': '操作成功'})
Ejemplo n.º 4
0
def modules_by_project_id(p_id):
    current_app.logger.warn('正在进行module')
    project = ProjectInfo.get(p_id)
    if project is None:
        raise JsonValidateError()
    modules = project.module_records # status=1
    return jsonify({"data": [{"id": m.id, "name": m.module_name} for m in modules]})
Ejemplo n.º 5
0
def list_projects():
    page = request.args.get('page', 1)
    paginate = ProjectInfo.paginate(page)
    projects = paginate.items
    return render_template('projects.html',
                           projects=projects,
                           paginate=paginate)
Ejemplo n.º 6
0
def insert_project(num):
    """插入数据库数据"""
    with app.app_context() as ctx:
        for i in range(num):
            project = ProjectInfo(project_name=f'Project {i}')
            db.session.add(project)
        db.session.commit()
Ejemplo n.º 7
0
def load_project_case(id, time_path):
    """根据项目加载用例"""
    project = ProjectInfo.get(int(id))
    if not project:
        raise DatabaseException('没有 module', id)
    modules = project.module_records
    if not modules:
        raise DatabaseException()
    for m in modules:
        load_module_case(m.id, time_path)
    return True
Ejemplo n.º 8
0
def edit_project(p_id=None):
    project = ProjectInfo.get(p_id)
    if not project:
        return redirect(url_for('web.list_projects'))
    form = ProjectAddForm(obj=project)
    if request.method == 'GET':
        return render_template('project_edit.html', form=form, project=project)
    if form.validate():
        project.edit_by_form(form)
        return redirect(url_for('web.list_projects'))
    # 没有通过验证
    return render_template('project_edit.html', form=form, project=project)
Ejemplo n.º 9
0
def create_module():
    form = ModuleAddForm(request.form)
    # 添加接口所属项目可选项
    project_choices = ProjectInfo.all()
    form.project_id.choices.extend([(str(p.id), p.project_name)
                                    for p in project_choices])
    if request.method == 'GET':
        return render_template('module.html', form=form)
    if form.validate():
        ModuleInfo.add_by_form(form)
        return redirect(url_for('web.list_modules'))
    return render_template('module.html', form=form)
Ejemplo n.º 10
0
def edit_module(m_id=None):
    module = ModuleInfo.get(m_id)
    form = ModuleAddForm(obj=module)
    # 添加可选项目
    project_choices = ProjectInfo.all()
    form.project_id.choices.extend([(str(p.id), p.project_name)
                                    for p in project_choices])

    if request.method == 'GET':
        return render_template('module_edit.html', form=form, module=module)
    if form.validate():
        module.edit_by_form(form)
        return redirect(url_for('web.list_modules'))
    return render_template('module_edit.html', form=form, module=module)
Ejemplo n.º 11
0
def create_case():
    form = CaseInfoForm(data=request.json)
    project_choice = ProjectInfo.all()
    if request.method == 'GET':
        return render_template('case.html', form=form, project=project_choice)
    if not form.validate():
        # 返回 msg 信息
        msg = ''
        for k, v in form.errors.items():
            msg = msg.join([k, ':', v[0], '; '])
        raise JsonValidateError(msg)
    # 保存
    CaseInfo.save_by_form(form.data)
    return jsonify({"msg": '操作成功'})
Ejemplo n.º 12
0
def create_suite():
    req = request.json or {}
    # 转成字符串,不然解析只能得到一个字典,而不是一个列表。
    includes = str(req['includes']) if 'includes' in req else ''
    req['includes'] = includes.replace("'", '"')
    form = SuiteAddForm(data=req)
    # 添加接口所属项目可选项
    project_choices = ProjectInfo.all()
    # wtf 渲染方式:form.project_id.choices.extend([(str(p.id), p.project_name) for p in project_choices])
    if request.method == 'GET':
        return render_template('suite.html',
                               form=form,
                               projects=project_choices)

    if not form.validate():
        msg = ''
        for k, v in form.errors.items():
            msg = msg.join([k, ':', v[0], '; '])
        raise JsonValidateError(msg)

    SuiteInfo.add_by_form(form)
    return jsonify({'msg': '操作成功'})
Ejemplo n.º 13
0
@web.route('/get_case/<int:c_id>')
@login_required
def get_case(c_id=None):
    return 'get case '


@web.route('/edit_case/<int:c_id>', methods=['GET', 'POST'])
@login_required
def edit_case(c_id=None):
    case = CaseInfo.get(c_id)
    if not case:
        raise JsonValidateError()
    form = CaseInfoForm(obj=case)
    if request.method == 'GET':
        project_choice = ProjectInfo.all()
        return render_template('case_edit.html',
                               form=form,
                               project=project_choice,
                               case=case)
    if not form.validate():
        msg = ''
        for k, v in form.errors.items():
            msg = msg.join([k, ':', v[0], '; '])
        raise JsonValidateError(msg)
    case.update(form.data)
    return jsonify({"msg": '操作成功'})


@web.route('/create_case', methods=['GET', 'POST'])
@login_required
Ejemplo n.º 14
0
def index():
    # print(session)
    current_app.logger.warn('你好')
    projects = ProjectInfo.all()
    current_app.logger.info('hahh,正在访问index')
    return render_template('index.html', projects=projects)