コード例 #1
0
class TestLogin:
    def __init__(self):
        self.gs=Getsession()
        self.db=Operatdb()

    def test_login(self,protocolname,caseid,casetitle,meth,url,data,exc):
        res,code=self.gs.reques_meth(meth,url,data)
        print(res,code)
        if code==200 and exc in res:
            print("测试通过")
            self.db.insert_res(protocolname,caseid,casetitle,"success","无")
        else:
            print("测试失败")
            self.db.insert_res(protocolname, caseid, casetitle, "failed", "无")
コード例 #2
0
class Testsafe:
    def __init__(self):
        self.gs = Getsession()
        self.db = Operatdb()

    def test_safe(self, protocolname, caseid, casetitle, meth, url, data, exc):
        self.gs.login("wncd123", "woniu123")
        res, code = self.gs.reques_meth(meth, url, data)
        # print(res)
        if code == 200 and exc in res:
            print("测试成功")
            self.db.insert_res(protocolname, caseid, casetitle, "success", "无")
        else:
            print("测试失败")
            self.db.insert_res(protocolname, caseid, casetitle, "failed", "无")
コード例 #3
0
class Testdecioher:
    def __init__(self):
        self.gs=Getsession()
        self.db = Operatdb()

    # 测试
    def test_decipher(self,protocolname,caseid,casetitle,meth,url,data,exc):
        self.gs.login()
        print(data)
        res,code=self.gs.reques_meth(meth,url,data)
        print(res,code)
        if code==200 and exc==res:
            print("测试成功")
            self.db.insert_res(protocolname, caseid, casetitle, "success", "无")
        else:
            print("测试失败")
            self.db.insert_res(protocolname, caseid, casetitle, "failed", "无")
コード例 #4
0
class Runner:
    def __init__(self):
        self.start=Testscesce()
        self.db=Operatdb()
        self.report=Get_report()
        self.rd=Getdata()

    # 开始测试
    def run(self):
        # 清空数据库
        self.db.trunc_data()
        # 执行测试
        print("登录接口".center(50, "*"))
        self.start.login_scence()
        time.sleep(3)
        print("解密接口".center(50,"*"))
        self.start.decipher_scence()
        print("上传简历接口".center(50, "*"))
        self.start.upload_scence()
        print("新增资源接口".center(50, "*"))
        self.start.addsrc_scence()
        print("查询资源接口".center(50, "*"))
        self.start.search_scence()
        print("跟踪资源接口".center(50, "*"))
        self.start.track_scence()
        print("缴费接口".center(50, "*"))
        self.start.paymoney_scence()
        print("待缴费接口".center(50, "*"))
        self.start.searchfin_scence()
        print("验证cookie".center(50, "*"))
        self.start.verify_cookie()
        print("权限验证".center(50, "*"))
        self.start.safe_scence()
        # 生成报告
        self.makereport()

    # 生成测试结果
    def makereport(self):
        success=self.db.get_num("success")
        faile=self.db.get_num("failed")
        error=self.db.get_num("erron")
        project=self.rd.read_conf("../config/env.conf","head","model")
        modpath=self.rd.read_conf("../config/env.conf", "head", "modelpath")
        report=self.rd.read_conf("../config/env.conf", "head", "reportpath")
        print(project)
        self.report.make_report(project,success,faile,error,modpath,report)
コード例 #5
0
class Testpaymoney:
    def __init__(self):
        self.gs = Getsession()
        self.db = Operatdb()

    def test_paymoney(self, protocolname, caseid, casetitle, meth, url, data,
                      exc):
        try:
            self.gs.login()
            # print(url)
            # 调用缴费接口
            detail_record = data["student_name"]
            res, code = self.gs.reques_meth(meth, url, data)
            # 数据库查询
            sql = f'SELECT * FROM finance_detail WHERE expend_name="{detail_record}";'
            li, num = self.db.read_db(sql)
            # print(res,exc)
            # print(num)
            if code == 200 and exc == res and num == 1:
                print("测试成功")
                self.db.insert_res(protocolname, caseid, casetitle, "success",
                                   "无")
            else:
                print("测试失败")
                self.db.insert_res(protocolname, caseid, casetitle, "failed",
                                   "无")
        except Exception as e:
            self.db.insert_res(protocolname, caseid, casetitle, "error", e)
コード例 #6
0
 def test_upload(self, protocolname, caseid, casetitle, meth, url, data,
                 exc):
     file = data["token"]
     data.pop("token")
     db = Operatdb()
     try:
         self.gs.login()
         if file != "":
             fil = {
                 "batchfile": ("Asdf.xls", open(rf"{file}",
                                                mode="rb").read())
             }
             # print(data,fil)
             # 构建数据 与 数据库查询出来的作对比
         else:
             fil = ""
         li = self.da.get_model_data(0, file)
         res, code = self.gs.reques_meth(meth, url, data, fil)
         print(res, code)
         li1 = []
         dic = {}
         dic.update({
             "age": str(int(li[0]["年龄"])),
             "sex": li[0]["性别"],
             "email": li[0]["电子邮件"],
             "school": li[0]["学校名称"]
         })
         li1.append(dic)
         mail = li1[0]["email"]
         print(mail)
         # 数据库查询
         sql = f'SELECT age,sex,email,school FROM customer WHERE email="{mail}";'
         # 得到数据库查询结果
         dbli, num = db.read_db(sql)
         # print(code==200)
         # print(li1==dbli)
         # print(li1)
         # print(dbli)
         # print(exc==res)
         # 断言
         if code == 200 and exc == res and li1 == dbli:
             print("测试成功")
             db.insert_res(protocolname, caseid, casetitle, "success", "无")
         else:
             print("测试失败")
             db.insert_res(protocolname, caseid, casetitle, "failed", "无")
     except Exception as e:
         print(e)
         db.insert_res(protocolname, caseid, casetitle, "error", "出错了")
コード例 #7
0
class Testsearchfin:
    def __init__(self):
        self.gs = Getsession()
        self.db = Operatdb()

    def test_searchfinance(self,protocolname, caseid, casetitle,meth,url,data,exc):
        # 登录
        self.gs.login()
        # 调用解密接口----不然查询结果含****
        ur = "http://localhost:8080/WoniuBoss3.5/second"
        da = {"vp": "woniu123"}
        self.gs.reques_meth("post", ur, da)
        res, code = self.gs.reques_meth(meth, url, data)
        # print(res)
        # 查询数据库
        if code == 200 and exc == res:
            print("测试成功")
            self.db.insert_res(protocolname, caseid, casetitle, "success", "无")
        else:
            print("测试失败")
            self.db.insert_res(protocolname, caseid, casetitle, "failed", "无")
コード例 #8
0
class Get_report:
    def __init__(self):
        self.db = Operatdb()

    # 报告数据收集:$product $passed $failed $error $runtime $tr
    def make_report(self, product, passed, failed, error, modlepath,
                    reportpath):
        # 读取html模板,进行替换
        with open(modlepath, "r", encoding="utf-8") as f:
            cont = f.read()
            cont = cont.replace("$product", product)
            cont = cont.replace("$passed", passed)
            cont = cont.replace("$failed", failed)
            cont = cont.replace("$error", error)
            cont = cont.replace("$runtime", time.strftime("%Y-%m-%d %H:%M:%S"))
            # 获取测试完成后构造好的结果
            res = self.make_table()
            print(res)
            # 替换结果
            cont = cont.replace("$table-tr", res)
            with open(reportpath, "w", encoding="utf-8") as w:
                print(reportpath)
                w.write(cont)
        print(1)

    # 构造测试结果表格内数据
    def make_table(self):
        # 读取数据库数据
        li, num = self.db.read_result()
        print(li)
        rest = ""
        for i in li:
            # print(i)
            rest += '<tr height="40">\n'
            rest += f'<td width="7%">{i["protocolname"]}</td>\n'
            rest += f'<td width="9%">{i["caseid"]}</td>\n'
            rest += f'<td width="10%">{i["casetitle"]}</td>\n'
            if i["result"] == "failed" or i["result"] == "error":
                rest += f'<td width="7%" bgcolor="red">{i["result"]}</td>\n'
            else:
                rest += f'<td width="7%" bgcolor="#00FFFF">{i["result"]}</td>\n'
            rest += f'<td width="15%">{i["runtime"]}</td>\n'
            rest += f'<td width="15%">{i["erromsg"]}</td>\n'
            rest += '</tr>'
        return rest
コード例 #9
0
class Testtracksrc:
    def __init__(self):
        self.gs = Getsession()
        self.db = Operatdb()

    # 测试
    def test_tracksrc(self,protocolname, caseid, casetitle,meth,url,data,exc):
        try:
            self.gs.login()
            # print(url)
            # 调用资源跟踪接口
            res, code = self.gs.reques_meth(meth, url, data)
            # print(res, code)
            # 数据库断言
            ids=data["id"]
            sql="SELECT " \
                "cus.last_status 'status'," \
                "stu.need_fee fee," \
                "cus.last_tracking_remark remark," \
                "cus.customer_id id," \
                "cus.next_tracking_time nextTime," \
                "cus.priority priority " \
                "FROM " \
                "customer cus,student stu " \
                "WHERE " \
                "stu.student_customer_id = cus.customer_id " \
                f"AND cus.customer_id = '{ids}' ;"
            li,num=self.db.read_db(sql)
            print(li)
            # 3个条件断言
            if code == 200 and exc == res and li[0]==data:
                print("测试成功")
                self.db.insert_res(protocolname, caseid, casetitle, "success", "无")
            else:
                print("测试失败")
                self.db.insert_res(protocolname, caseid, casetitle, "failed", "无")
        except Exception as e:
            self.db.insert_res(protocolname, caseid, casetitle, "error", e)
コード例 #10
0
 def __init__(self):
     self.gs = Getsession()
     self.db = Operatdb()
コード例 #11
0
 def __init__(self):
     self.db = Operatdb()
コード例 #12
0
 def __init__(self):
     self.start=Testscesce()
     self.db=Operatdb()
     self.report=Get_report()
     self.rd=Getdata()