Exemplo n.º 1
0
def runner_setting_default(setting_id):

    default_setting = SystemSetting.get_default_runner_setting()

    for setting in default_setting:
        setting.is_default = False
        db.session.add(setting)
    runner_setting = SystemSetting.get_by_id(setting_id)
    runner_setting.is_default = True
    db.session.add(runner_setting)
    db.session.commit()
    return success()
Exemplo n.º 2
0
def testcase_edit(testcase_id):
    test_case_obj = TestInterfacecase.get_by_id(testcase_id)
    if request.method == "GET":
        form = populate_interface_testcase(test_case_obj)
        return render_template(
            "test_cases/test_case.html",
            form=form,
            runner_setting=SystemSetting.get_runner_setting(),
            title=u"编辑")
    else:
        form = TestInterfaceCaseFrom(request.form)
        data_type = request.form.get("data_type")

        if form.validate():
            test_case_obj.interface_url = form.interface_url.data
            test_case_obj.testcase_name = form.testcase_name.data
            test_case_obj.testcase_method = form.testcase_method.data
            test_case_obj.module = form.module.data
            test_case_obj.testcase_header = init_field_data(
                form.testcase_header.data)
            test_case_obj.testcase_query = init_field_data(
                form.testcase_query.data)
            if (data_type == "JSON_data_select"):
                test_case_body = form.testcase_json.data
            else:
                test_case_body = init_field_data(form.testcase_data.data)
            test_case_obj.testcase_body = test_case_body
            test_case_obj.testcase_verification = init_verification_data(
                form.testcase_verification.data)
            db.session.add(test_case_obj)
            db.session.commit()
            return success()
        else:
            logger.error(form.errors)
            return fail(2, error=form.errors)
Exemplo n.º 3
0
def replace_variable(runner_setting, tmp):
    """
    获取{$ key $}这样形式的key值
    请求中设置的变量优先与环境变量
    变量优于方法
    :return:
    """
    if type(tmp) != str:
        tmp = str(tmp)

    regex_param = re.compile("\{\$(.+?)\$\}")
    keys = regex_param.findall(tmp)

    runner_setting = SystemSetting.get_by_id(runner_setting)
    variable_in_setting = runner_setting.value
    for key in keys:
        value = None

        setting_value = variable_in_setting.get(key, None)

        if setting_value is not None:
            value = setting_value

        variable_value = variable.get(key, None)
        if variable_value is not None:
            value = variable_value

        if value is not None:
            tmp = tmp.replace("{$" + key + "$}", value)
        else:
            logger.error("没有设置该变量:{0}".format(key))

    logger.error(tmp)
    regex_func = re.compile("\(\$(.+?)\$\)")
    keys = regex_func.findall(tmp)
    logger.error(keys)

    for key in keys:
        func_value = replace_variable_plugin(key)
        if func_value is not None:
            tmp = tmp.replace("($" + key + "$)", func_value)
        else:
            logger.error("没有设置该变量:{0}".format(key))

    logger.error(tmp)
    return tmp
Exemplo n.º 4
0
def runner_setting_edit(setting_id):
    setting = SystemSetting.get_by_id(setting_id)
    if setting is None:
        return render_template("error/404.html")

    if request.method == "GET":
        form = populate_setting(setting)
        return render_template("setting/runner_setting_new.html",
                               form=form,
                               title=u"更新")
    else:
        # 更新
        form = SettingFrom(request.form)
        target = request.referrer
        if form.validate():
            setting.key = form.key.data
            setting.desc = form.desc.data
            setting.value = init_setting_value(form.value.data)
            db.session.add(setting)
            db.session.commit()
            flash(u'更新成功', category='success')
        else:
            flash(form.errors, category='danger')
        return redirect(target)
Exemplo n.º 5
0
def runner_setting_new():
    if request.method == "GET":

        form = SettingFrom()
        return render_template("setting/runner_setting_new.html",
                               form=form,
                               title=u"新增")
    else:
        form = SettingFrom(request.form)
        target = request.referrer
        if form.validate():
            setting_obj = SystemSetting()
            setting_obj.key = form.key.data
            setting_obj.value = init_setting_value(form.value.data)
            setting_obj.desc = form.desc.data
            setting_obj.type = 1
            db.session.add(setting_obj)
            db.session.commit()
            flash(u'添加成功', category='success')
            return redirect("/runner_setting_list.html")
        else:
            flash(form.errors, category='danger')
            return redirect(target)
Exemplo n.º 6
0
def get_runner_setting():
    return SystemSetting.get_runner_setting()
Exemplo n.º 7
0
def runner_setting_list():
    runner_setting = SystemSetting.get_runner_setting()
    return render_template("setting/runner_setting_list.html",
                           runner_setting=runner_setting)