Ejemplo n.º 1
0
def test_pm_delete(pm_id):
    config_env = load_config()  # 读取配置
    rights = get_user_right()
    if rights and 'update' in rights:
        url = "".join((config_env.TEST_DATA_BASE_URL, "api/v1/testpm/", str(pm_id)))
        headers = dict()
        headers["Content-Type"] = "application/json"
        data = dict()
        data["is_delete"] = 1
        data["update_time"] = str(datetime.datetime.today())
        data = json.dumps(data)
        try:
            r = requests.put(url=url, headers=headers, data=data, timeout=10)
        except:
            traceback.print_exc()
        else:
            try:
                r_dict = json.loads(r.content)
            except:
                traceback.print_exc()
                return """删除失败!"""
            else:
                if "is_delete" in r_dict and r_dict["is_delete"] == 1:
                    return """删除成功!"""
                else:
                    return """删除失败!"""
    else:
        return (u"当前用户没有删除权限")
Ejemplo n.º 2
0
def test_pm_add():
    config_env = load_config()  # 读取配置
    rights = get_user_right()
    if rights and 'add' in rights:
        form = TestPMForm()
        result = ''
        if form.validate_on_submit():
            headers = dict()
            headers["Content-Type"] = "application/json"
            data = dict()
            # 表单内容
            data["catalog"] = form.catalog.data
            data["name"] = form.name.data
            data["type"] = form.type.data
            data["time_of_start"] = form.time_of_start.data
            data["expected_time_of_test"] = form.expected_time_of_test.data
            data["expected_time_of_live"] = form.expected_time_of_live.data
            data["dev_leader"] = form.dev_leader.data
            data["requirement_url"] = form.requirement_url.data

            # 创建和修改时间
            now = datetime.datetime.today()
            data["create_time"] = str(now)
            data["update_time"] = str(now)

            data = json.dumps(data)
            url = "".join((config_env.TEST_DATA_BASE_URL, "api/v1/testpm"))
            try:
                r = requests.post(url=url, headers=headers, data=data, timeout=10)
            except:
                result = u'新增失败,数据库不能连接'
                traceback.print_exc()
            else:
                if "message" not in json.loads(r.content):
                    form.name.data = ''
                    form.dev_leader.data = ''
                    form.requirement_url.data = ''
                    result = u'新增成功'
                    return ("<script>alert('{}'); window.location.href='/test_pm';</script> ".format(result))
                else:
                    result = u'新增失败'
        return render_template("test_pm/test_pm_add.html", form=form, result=result)
    else:
        return abort(403)
Ejemplo n.º 3
0
def test_pm_update(pm_id):
    config_env = load_config()  # 读取配置
    rights = get_user_right()
    if rights and 'update' in rights:
        form = AllTestPMForm()
        result = ''
        result_old = {}
        url = "".join((config_env.TEST_DATA_BASE_URL, "api/v1/testpm/", str(pm_id)))

        if form.validate_on_submit():
            headers = dict()
            headers["Content-Type"] = "application/json"
            data = dict()
            data["catalog"] = form.catalog.data
            data["name"] = form.name.data
            data["type"] = form.type.data
            data["time_of_start"] = form.time_of_start.data
            data["expected_time_of_test"] = form.expected_time_of_test.data
            data["expected_time_of_live"] = form.expected_time_of_live.data
            data["dev_leader"] = form.dev_leader.data
            data["requirement_url"] = form.requirement_url.data

            data["status"] = form.status.data
            if form.test_leader.data:
                data["test_leader"] = form.test_leader.data

            data["case_review"] = form.case_review.data
            data["live_review"] = form.live_review.data
            data["test_env"] = form.test_env.data
            data["pre_env"] = form.pre_env.data
            data["live_env"] = form.live_env.data
            data["live_env"] = form.live_env.data
            if form.remark.data:
                data["remark"] = form.remark.data

            # 修改时间
            data["update_time"] = str(datetime.datetime.today())

            data = json.dumps(data)
            # update
            try:
                r = requests.put(url=url, headers=headers, data=data, timeout=10)
            except:
                traceback.print_exc()
            else:
                if "message" not in json.loads(r.content):
                    result = u'更新成功'

                else:
                    result = u'更新失败'
        # get
        try:
            r = requests.get(url=url, timeout=10)
        except:
            traceback.print_exc()
        else:
            result_old = json.loads(r.content)
            replace_rule = [('\r', '\\r'), ('\n', '\\n'), ("'", "\\'")]
            for key in result_old:
                for i in replace_rule:
                    if isinstance(result_old[key], unicode):
                        result_old[key] = result_old[key].replace(i[0], i[1])
        return render_template("test_pm/test_pm_update.html", form=form, result=result, result_old=result_old)

    else:
        return abort(403)