Exemplo n.º 1
0
    def test_001(self,item):
        global result#指明全球变量
        global COOKIES#设置cookies为全局变量
        url=item["url"]
        method=item["method"]
        param=item["param"]
        case_id=item["case_id"]
        modular=item["modular"]
        title=item["title"]
        expected=item["expected"]
        sql=item["sql"]
        # print(sql)
        param=get_data.GetData().replace(param)
        print("现在的param是{}".format(param))
        # if sql is not None:
        #  sql=get_data.GetData().replace(sql)
        #  print("现在的sql是{}".format(sql))
        #
        # if sql is not None  and eval(sql)["sql_2"] is not None:
        #     sql_result=DoMysql().do_mysql(eval(sql)["sql_2"],2)
        #     my_log.my_info("交易记录是:{}".format(sql_result))

        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular,case_id,title))
        my_log.my_info("测试数据是:{}".format(param))

        if case_id == 1:
            new_param = json.dumps(eval(param))
            headers = DoRequests(url, method, new_param).get_header(index=1)
        else:
            new_param = json.loads(param)
            headers = DoRequests(url, method, new_param).get_header(index=2)
        test_result=DoRequests(url,method,new_param).request(headers=headers,cookies=getattr(get_data.GetData,"COOKIES"))
        print(test_result.text)

        #获取loan_id
        # if sql is not None  and eval(sql)["sql_1"] is not None:
        #     sql=get_data.GetData().replace(sql)
        #     member_id=DoMysql().do_mysql(eval(sql)["sql_1"],1)[0]
        #     setattr(get_data.GetData,"normal_member_id",str(member_id))
        # if sql is not None  and eval(sql)["sql_2"] is not None:
        #     sql=get_data.GetData().replace(sql)
        #     sql_result=DoMysql().do_mysql(eval(sql)["sql_2"],1)[0]
        #增加一个判断
        if test_result.cookies:#判断请求cookies是否为空  # c = requests.cookies.RequestsCookieJar()# c.set('cookie-name', 'cookie-value', path='/', domain='.abc.com')# s.cookies.update(c)
            cookies = requests.utils.dict_from_cookiejar(test_result.cookies)
            setattr(get_data.GetData,"COOKIES",cookies)
        new_expected=json.loads(expected)
        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(new_expected))
        try:
            self.assertEqual(new_expected["code"],test_result.json()["code"])
            result="pass"
            my_log.my_info("测试通过了")
        except Exception as e:
            my_log.my_error("测试失败,http请求发生错误")
            result="failed"
            raise e
        finally:
            row=case_id+1
            DoExcel(project_path.case_path,"getWarningDetail").write_data(row,test_result.text,result)
Exemplo n.º 2
0
 def test_001(self, item):
     global result  #指明全球变量
     url = item["url"]
     method = item["method"]
     param = item["param"]
     case_id = item["case_id"]
     modular = item["modular"]
     title = item["title"]
     expected = item["expected"]
     my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
     my_log.my_info("测试数据是:{}".format(param))
     new_param = json.dumps(eval(param))
     headers = DoRequests(url, method, new_param).get_header(index=1)
     test_result = DoRequests(url, method, new_param).request(headers)
     # my_log.my_info("测试结果是:{}".format(test_result.json()))
     # my_log.my_info("测试结果是:{}".format(test_result.text))
     new_expected = json.loads(expected)
     my_log.my_info("预期结果是:{}".format(new_expected))
     new_result = test_result.json()
     new_result2 = new_result.pop("timestamp")
     my_log.my_info("已删除当前需要断言的登录时间:timestamp: {}".format(new_result2))
     try:
         self.assertEqual(new_expected, new_result)
         my_log.my_info("实际结果是:{}".format(new_result))
         my_log.my_info("测试通过了")
         result = "pass"
     except AssertionError as e:
         my_log.my_error("http请求发生错误")
         result = "failed"
         raise e
     finally:
         row = case_id + 1
         DoExcel(project_path.case_path,
                 "login").write_data(row, test_result.text,
                                     result)  #写回的数据格式必须是字符串或者数字类型才可以
Exemplo n.º 3
0
 def test_001(self, item):
     global result  #指明全球变量
     url = item["url"]
     method = item["method"]
     param = item["param"]
     case_id = item["case_id"]
     modular = item["modular"]
     title = item["title"]
     expected = item["expected"]
     my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
     my_log.my_info("测试数据是:{}".format(param))
     test_result = DoRequests(url, method, eval(param)).request()
     my_log.my_info("测试结果是:{}".format(test_result.json()))
     my_log.my_info("预期结果是:{}".format(eval(expected)))
     try:
         self.assertEqual(eval(expected), test_result.json())
         my_log.my_info("测试通过了")
         result = "pass"
     except AssertionError as e:
         my_log.my_error("http请求发生错误")
         result = "failed"
         raise e
     finally:
         row = case_id + 1
         DoExcel(project_path.case_path,
                 "register").write_data(row, test_result.text,
                                        result)  #写回的数据格式必须是字符串或者数字类型才可以
Exemplo n.º 4
0
    def test_001(self,item):
        global result#指明全球变量
        global COOKIES#设置cookies为全局变量
        url=item["url"]
        method=item["method"]
        param=item["param"]
        case_id=item["case_id"]
        modular=item["modular"]
        title=item["title"]
        expected=item["expected"]
        sql=item["sql"]
        print(sql)
        param=get_data.GetData().replace(param)
        print("现在的param是{}".format(param))
        if sql is not None:
         sql=get_data.GetData().replace(sql)
         print("现在的sql是{}".format(sql))

        if sql is not None  and eval(sql)["sql_3"] is not None:
        #投资之前查询数据库用户余额保存下来
            before_amount=DoMysql().do_mysql(eval(sql)["sql_3"],1)[0]
            print("before_sql查询结果是{}".format(before_amount))
        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular,case_id,title))
        my_log.my_info("测试数据是:{}".format(param))
        test_result=DoRequests(url,method,eval(param)).request(cookies=getattr(get_data.GetData,"COOKIES"))
        #获取用户的member_id
        if sql is not None  and eval(sql)["sql_1"] is not None:
            member_id=DoMysql().do_mysql(eval(sql)["sql_1"],1)[0]
            setattr(get_data.GetData,"normal_member_id",str(member_id))
        #获取loan_id
        if sql is not None  and eval(sql)["sql_2"] is not None:
            sql=get_data.GetData().replace(sql)
            loan_id=DoMysql().do_mysql(eval(sql)["sql_2"],1)[0]
            setattr(get_data.GetData,"loan_id",str(loan_id))
        #投资之后,再做一个查询,查询数据库里面用户的余额
        #增加一个判断
        if test_result.cookies:#判断请求cookies是否为空
            setattr(get_data.GetData,"COOKIES",test_result.cookies)
        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(eval(expected)))
        try:
            self.assertEqual(eval(expected),test_result.json())
            #增加一个判断,判断是否投资之后用户余额减少
            if sql is not None  and eval(sql)["sql_3"] is not None:
                after_amount=DoMysql().do_mysql(eval(sql)["sql_3"],1)[0]
                print("after_sql查询结果是{}".format(after_amount))
                invest_amount=eval(param)["amount"]
                expected_amount=before_amount-after_amount
                self.assertEqual(invest_amount,expected_amount)
            result="pass"
            my_log.my_info("测试通过了")
        except AssertionError as e:
            my_log.my_error("测试失败,http请求发生错误")
            result="failed"
            raise e
        finally:
            row=case_id+1
            DoExcel(project_path.case_path,"invest").write_data(row,test_result.text,result)
Exemplo n.º 5
0
    def test_001(self,item):
        global param
        global url
        global method
        global case_id
        global modular
        global title
        global expected



        url=item["url"]
        method=item["method"]
        param=item["param"]
        case_id=item["case_id"]
        modular=item["modular"]
        title=item["title"]
        expected=item["expected"]
        sql=item["sql"]

        param=get_data.GetData().replace(param)
        mylog.my_info("参数化之后param是{}".format(param))


        headers = {"User-Agent": "Mozilla/5.0"}
        test_result=DoRequests(url,method,eval(param)).request(cookies=getattr(get_data.GetData,"COOKIES"))
        # do_session = Do_Requests()
        # # 登录
        # test_result=do_session(url=url, method=method, data=param,headers=headers)




        if test_result.cookies:#判断请求cookies是否为空
                setattr(get_data.GetData,"COOKIES",test_result.cookies)

        mylog.my_info("接口返回的http状态码:{}".format(test_result))
        if case_id == 2:
            mylog.my_info("测试结果是:{}".format(test_result))
            mylog.my_info("预期结果是:{}".format(expected))
        else:
            mylog.my_info("测试结果是:{}".format(test_result.json()))
            mylog.my_info("预期结果是:{}".format(eval(expected)))


        try:
            self.assertEqual(eval(expected)["Code"],test_result.json()["Code"])
            self.assertEqual(eval(expected)["Message"],test_result.json()["Message"])
            result="pass"
            mylog.my_info("测试通过了")
        except AssertionError as e:
            mylog.my_error("测试失败,http请求发生错误")
            result="failed"
            raise e
        finally:
            row=case_id+1
            DoExcel(project_path.case_path,"generate_repayments").write_data(row,test_result.text,result)
Exemplo n.º 6
0
    def test_001(self, item, login):
        global result  # 指明全球变量
        global COOKIES  # 设置cookies为全局变量

        # 获取item中的用例数据
        url = item["url"]
        method = item["method"]
        param = item["param"]  # 返回的是字符串类型的数据
        case_id = item["case_id"]
        modular = item["modular"]
        title = item["title"]
        expected = item["expected"]
        sql = item["sql"]
        header = eval(item["header"])

        # 如果有sql则把sql中需要参数化的量去进行替换
        if sql is not None:
            sql = get_data.GetData().replace(sql)
            my_log.my_info("现在的sql是{}".format(sql))

        # param不管里面是否有参数化都可以替代,反正返回的还是param本身,找到一个返回一个
        param = get_data.GetData().replace(param)

        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
        my_log.my_info("测试数据是:{}".format(param))

        # 执行接口测试,cookies利用反射进行动态的获取
        if "application/json" in header["Content-Type"]:
            new_param = param
        else:
            new_param = eval(param)
        test_result = DoRequests(url, method, new_param).request(
            headers=header, cookies=getattr(get_data.GetData, "COOKIES"))
        print(test_result.text)

        # 增加一个判断 是在完成完请求之后才去判断
        if test_result.cookies:
            cookies = requests.utils.dict_from_cookiejar(test_result.cookies)
            setattr(get_data.GetData, "COOKIES", cookies)
        new_expected = json.loads(expected)  # 处理Null无法识别的问题

        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(new_expected))
        try:
            assert new_expected["code"] == test_result.json()["code"]
            result = "pass"
            my_log.my_info("测试通过了")
        except AssertionError as e:
            my_log.my_error("测试失败,http请求发生错误")
            result = "failed"
            raise e
        finally:
            row = case_id + 1
            # 这里需要注意写回测试数据的时候,需要把测试数据转换成字符串类型
            DoExcel(project_path.case_path,
                    "getserialnumber").write_data(row, test_result.text,
                                                  result)
Exemplo n.º 7
0
def login():
    test_data = DoExcel(project_path.case_path, "camera").read_data()[0]
    test_result = DoRequests(test_data["url"], test_data["method"],
                             test_data["param"]).request(
                                 headers=eval(test_data["header"]),
                                 cookies=getattr(get_data.GetData, "COOKIES"))
    if test_result.cookies:
        cookies = requests.utils.dict_from_cookiejar(test_result.cookies)
        setattr(get_data.GetData, "COOKIES", cookies)
    print("cookies返回成功")
Exemplo n.º 8
0
 def test_001(self, item):
     global result  #指明全球变量
     global COOKIES  #设置cookies为全局变量
     url = item["url"]
     method = item["method"]
     param = item["param"]  #返回的是字符串类型的数据
     case_id = item["case_id"]
     modular = item["modular"]
     title = item["title"]
     expected = item["expected"]
     sql = item["sql"]
     if sql != None:
         sql = get_data.GetData().replace(sql)
         print(sql)
     param = get_data.GetData().replace(param)
     print(param)
     my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
     my_log.my_info("测试数据是:{}".format(param))
     test_result = DoRequests(
         url, method,
         eval(param)).request(cookies=getattr(get_data.GetData, "COOKIES"))
     #增加一个判断是否查询数据库
     if sql != None:  #如果测试用例中的query不为none就进行数据库查询操作
         sql_data = DoMysql().do_mysql(eval(sql)["sql"], 1)
         member_id = sql_data[0]
         setattr(get_data.GetData, "normal_member_id", str(member_id))
         print(getattr(get_data.GetData, "normal_member_id"))
     #增加一个判断 是在完成完请求之后才去判断
     if test_result.cookies:  #判断请求cookies是否为空
         setattr(get_data.GetData, "COOKIES", test_result.cookies)
     my_log.my_info("测试结果是:{}".format(test_result.json()))
     my_log.my_info("预期结果是:{}".format(eval(expected)))
     # expected=eval(expected)
     # test_result=test_result.json()
     # # if case_id==2:
     #     expected["data"]=test_result["data"]
     try:
         self.assertEqual(
             eval(expected)["status"],
             test_result.json()["status"])
         self.assertEqual(
             eval(expected)["code"],
             test_result.json()["code"])
         self.assertEqual(eval(expected)["msg"], test_result.json()["msg"])
         result = "pass"
         my_log.my_info("测试通过了")
     except AssertionError as e:
         my_log.my_error("测试失败,http请求发生错误")
         result = "failed"
         raise e
     finally:
         row = case_id + 1
         DoExcel(project_path.case_path,
                 "get_InvestsByMemberId").write_data(
                     row, test_result.text, result)
Exemplo n.º 9
0
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        url = item["url"]
        method = item["method"]
        param = item["param"]
        case_id = item["case_id"]
        modular = item["modular"]
        title = item["title"]
        expected = item["expected"]
        sql = item["sql"]
        print(sql)
        param = get_data.GetData().replace(param)
        print("现在的param是{}".format(param))
        if sql is not None:
            sql = get_data.GetData().replace(sql)
            print(type(sql))
            print("现在的sql是{}".format(sql))

        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
        my_log.my_info("测试数据是:{}".format(param))
        test_result = DoRequests(
            url, method,
            eval(param)).request(cookies=getattr(get_data.GetData, "COOKIES"))
        #获取loan_id
        if sql is not None and eval(sql)["sql"] is not None:
            print("测试的sql{}".format(eval(sql)["sql"]))
            sql = get_data.GetData().replace(sql)
            loan_id = DoMysql().do_mysql(eval(sql)["sql"], 1)[0]
            setattr(get_data.GetData, "loan_id", str(loan_id))
        #增加一个判断
        if test_result.cookies:  #判断请求cookies是否为空
            setattr(get_data.GetData, "COOKIES", test_result.cookies)
        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(eval(expected)))
        try:
            self.assertEqual(
                eval(expected)["status"],
                test_result.json()["status"])
            self.assertEqual(
                eval(expected)["code"],
                test_result.json()["code"])
            self.assertEqual(eval(expected)["msg"], test_result.json()["msg"])
            result = "pass"
            my_log.my_info("测试通过了")
        except AssertionError as e:
            my_log.my_error("测试失败,http请求发生错误")
            result = "failed"
            raise e
        finally:
            row = case_id + 1
            DoExcel(project_path.case_path,
                    "get_InvestsByLoanId").write_data(row, test_result.text,
                                                      result)
Exemplo n.º 10
0
 def test_001(self, item):
     global result  # 指明全局变量
     global COOKIES  # 设置cookies为全局变量
     global before_amount
     url = item["url"]
     method = item["method"]
     param = item["param"]
     case_id = item["case_id"]
     modular = item["modular"]
     title = item["title"]
     expected = item["expected"]
     sql = item["sql"]
     param = get_data.GetData().replace(param)
     print("目前的param是{}".format(param))
     if sql is not None:
         sql = get_data.GetData().replace(sql)
         print("目前的sql是{}".format(sql))
         before_amount = DoMysql().do_mysql(eval(sql)["sql"])[0]
         my_log.my_info("充值之前账户余额:{}".format(before_amount))
     my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
     my_log.my_info("测试数据是:{}".format(param))
     test_result = DoRequests(
         url, method,
         eval(param)).request(cookies=getattr(get_data.GetData, "COOKIES"))
     # 增加一个判断
     if test_result.cookies:  # 判断请求cookies是否为空
         setattr(get_data.GetData, "COOKIES", test_result.cookies)
     my_log.my_info("测试结果是:{}".format(test_result.text))
     my_log.my_info("预期结果是:{}".format(eval(expected)))
     try:
         self.assertEqual(
             eval(expected)["code"],
             test_result.json()["total"])
         #     if sql is not None:
         #         after_amount = DoMysql().do_mysql(eval(sql)["sql"], 1)[0]
         #         recharge_amount = int(eval(param)["amount"])
         #         my_log.my_info("充值的金额是:{}".format(str(recharge_amount)))
         #         expected_amount = recharge_amount + before_amount
         #         my_log.my_info("充值之后的用户余额:{}".format(expected_amount))
         #         self.assertEqual(expected_amount, after_amount)
         #         expected = expected.replace("expectedamount", str(expected_amount))
         #     self.assertEqual(eval(expected)["status"], test_result.json()["status"])
         #     self.assertEqual(eval(expected)["code"], test_result.json()["code"])
         #     self.assertEqual(eval(expected)["msg"], test_result.json()["msg"])
         result = "pass"
         my_log.my_info("测试通过了")
     except AssertionError as e:
         my_log.my_error("测试失败,http请求发生错误")
         result = "failed"
         raise e
     finally:
         row = case_id + 1
         DoExcel(project_path.case_path,
                 "invest").write_data(row, test_result.text, result)
Exemplo n.º 11
0
 def test_001(self, item):
     global result  #指明全球变量
     global COOKIES  #设置cookies为全局变量
     global before_amount
     url = item["url"]
     method = item["method"]
     param = item["param"]
     case_id = item["case_id"]
     modular = item["modular"]
     title = item["title"]
     expected = item["expected"]
     sql = item["sql"]
     param = get_data.GetData().replace(param)
     print("目前的param是{}".format(param))
     my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))
     my_log.my_info("测试数据是:{}".format(param))
     test_result = DoRequests(url, method, param=eval(param)).request(
         cookies=getattr(get_data.GetData, "COOKIES"))
     #增加一个判断
     if test_result.cookies:  #判断请求cookies是否为空
         setattr(get_data.GetData, "COOKIES", test_result.cookies)
     my_log.my_info("测试结果是:{}".format(test_result.json()))
     my_log.my_info("预期结果是:{}".format(eval(expected)))
     try:
         self.assertEqual(
             eval(expected)["status"],
             test_result.json()["status"])
         self.assertEqual(
             eval(expected)["code"],
             test_result.json()["code"])
         result = "pass"
         my_log.my_info("测试通过了")
     except AssertionError as e:
         my_log.my_error("测试失败,http请求发生错误")
         result = "failed"
         raise e
     finally:
         row = case_id + 1
         DoExcel(project_path.case_path,
                 "getLoanList").write_data(row, test_result.text,
                                           result)  #写回的数据格式必须是字符串或者数字类型才可以
Exemplo n.º 12
0
#2引入ddt,参数化我们测试用例里面的每一条数据,提高复用性,做法就是先获取excel文件中用例
#1)然后通过data传入(需要解包),然后将data里面的元祖的每一个元素,传入到函数中,再对传入的元素进行处理
#3测试用例里面引入try..except..finally,最后写回测试数据
#4测试报告--在run文件中进行运行
#5测试报告的路径

import unittest
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
import json

my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "login").read_data()


@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        url = item["url"]
        method = item["method"]
Exemplo n.º 13
0
__author__ = '程程'
#1引入单元测试,代替run这个文件
#2引入ddt,参数化我们测试用例里面的每一条数据,提高复用性,做法就是先获取excel文件中用例
#1)然后通过data传入(需要解包),然后将data里面的元祖的每一个元素,传入到函数中,再对传入的元素进行处理
#3测试用例里面引入try..except..finally,最后写回测试数据
#4测试报告--在run文件中进行运行
#5测试报告的路径

import unittest
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "register").read_data()


@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        url = item["url"]
        method = item["method"]
Exemplo n.º 14
0
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        #获取测试用例数据,数据类型基本都为字符串类型
        url = item["url"]
        method = item["method"]
        param = item["param"]
        case_id = item["case_id"]
        modular = item["modular"]
        title = item["title"]
        expected = item["expected"]
        sql = item["sql"]

        #参数化param
        param = get_data.GetData().replace(param)
        my_log.my_info("参数化之后param是{}".format(param))

        #参数化sql
        my_log.my_info("参数化之前的sql:".format(sql))
        if sql is not None:
            sql = get_data.GetData().replace(sql)
            my_log.my_info("参数化之后的sql是{}".format(sql))

        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))

        #输入参数进行接口测试
        test_result = DoRequests(
            url, method,
            eval(param)).request(cookies=getattr(get_data.GetData, "COOKIES"))

        #获取用户的member_id
        if sql is not None and eval(sql)["sql_1"] is not None:
            member_id = DoMysql().do_mysql(eval(sql)["sql_1"], 1)[0]
            setattr(get_data.GetData, "normal_member_id", str(member_id))

        #获取loan_id
        if sql is not None and eval(sql)["sql_2"] is not None:
            sql = get_data.GetData().replace(sql)
            loan_id = DoMysql().do_mysql(eval(sql)["sql_2"], 1)[0]
            setattr(get_data.GetData, "loan_id", str(loan_id))

        #投资之后,再做一个查询,查询数据库里面用户的余额
        #增加一个判断
        if test_result.cookies:  #判断请求cookies是否为空
            setattr(get_data.GetData, "COOKIES", test_result.cookies)

        my_log.my_info("接口返回的http状态码:{}".format(test_result))
        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(eval(expected)))

        try:
            self.assertEqual(eval(expected), test_result.json())
            result = "pass"
            my_log.my_info("测试通过了")
        except AssertionError as e:
            my_log.my_error("测试失败,http请求发生错误")
            result = "failed"
            raise e
        finally:
            row = case_id + 1
            DoExcel(project_path.case_path,
                    "generate_repayments").write_data(row, test_result.text,
                                                      result)
Exemplo n.º 15
0
__author__ = '程程'
import unittest
from common.do_mysql import DoMysql
from common import get_data
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
my_log = MyLogg()
test_data = DoExcel(project_path.case_path,
                    "get_InvestsByMemberId").read_data()


@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        url = item["url"]
        method = item["method"]
        param = item["param"]  #返回的是字符串类型的数据
        case_id = item["case_id"]
        modular = item["modular"]
Exemplo n.º 16
0
__author__ = '程程'

import unittest
from common.do_mysql import DoMysql
from common import get_data
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
import requests
import json
import pytest
import os
my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "getserialnumber").read_data()

# def login():
#     test_data = DoExcel(project_path.case_path, "camera").read_data()[0]
#     test_result = DoRequests(test_data["url"], test_data["method"], eval(test_data["param"])).request(headers=test_data["header"],
#                                                               cookies=getattr(get_data.GetData, "COOKIES"))
#     yield requests.utils.dict_from_cookiejar(test_result.cookies)
#     print("cookies返回成功")


class TestCases():
    @pytest.mark.parametrize('item', test_data)
    def test_001(self, item, login):
        global result  # 指明全球变量
        global COOKIES  # 设置cookies为全局变量
Exemplo n.º 17
0
__author__ = '程程'
import unittest
from  common.do_mysql import DoMysql
from  common import get_data
from  common.do_requests import DoRequests
from  common.learn_do_excel import DoExcel
from  common import project_path
from ddt import ddt,data,unpack
from  common.my_log import MyLogg
my_log=MyLogg()
test_data=DoExcel(project_path.case_path,"invest").read_data()
# print(test_data)
@ddt
class TestCases(unittest.TestCase):
    def setUp(self):#测试之前的准备工作
        pass
    def tearDown(self):
        pass
    @data(*test_data)
    def test_001(self,item):
        global result#指明全球变量
        global COOKIES#设置cookies为全局变量
        url=item["url"]
        method=item["method"]
        param=item["param"]
        case_id=item["case_id"]
        modular=item["modular"]
        title=item["title"]
        expected=item["expected"]
        sql=item["sql"]
        print(sql)
Exemplo n.º 18
0
__author__ = '程程'
import unittest
from common.do_mysql import DoMysql
from common import get_data
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "withdraw").read_data()


@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        global before_amount
        global withdraw_amount
        url = item["url"]
        method = item["method"]
        param = item["param"]
        case_id = item["case_id"]
Exemplo n.º 19
0
__author__ = '程程'
import unittest
from  common.do_mysql import DoMysql
from  common import get_data
from  common.do_requests import DoRequests
from  common.learn_do_excel import DoExcel
from  common import project_path
from ddt import ddt,data,unpack
from  common.my_log import MyLogg
import json
import requests
my_log=MyLogg()
test_data=DoExcel(project_path.case_path,"getWarningDetail").read_data()
# print(test_data)
@ddt
class TestCases(unittest.TestCase):
    def setUp(self):#测试之前的准备工作
        pass
    def tearDown(self):
        pass
    @data(*test_data)
    def test_001(self,item):
        global result#指明全球变量
        global COOKIES#设置cookies为全局变量
        url=item["url"]
        method=item["method"]
        param=item["param"]
        case_id=item["case_id"]
        modular=item["modular"]
        title=item["title"]
        expected=item["expected"]
Exemplo n.º 20
0
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        global before_amount
        global withdraw_amount
        url = item["url"]
        method = item["method"]
        param = item["param"]
        case_id = item["case_id"]
        modular = item["modular"]
        title = item["title"]
        expected = item["expected"]
        sql = item["sql"]

        #参数化测试数据
        param = get_data.GetData().replace(param)
        my_log.my_info("目前的param是{}".format(param))

        #判断是否需要执行sql 如果需要执行则运行代码
        if sql is not None:
            sql = get_data.GetData().replace(sql)
            print("目前的sql是{}".format(sql))
            before_amount = DoMysql().do_mysql(eval(sql)["sql"])[0]
            my_log.my_info("体现之前的用户余额是:{}".format(before_amount))

        my_log.my_info("正在发起{}模块中的第{}条用例:{}".format(modular, case_id, title))

        #传入参数 进行接口测试
        test_result = DoRequests(
            url, method,
            eval(param)).request(cookies=getattr(get_data.GetData, "COOKIES"))
        # print(test_result)

        #打印测试结果与实际结果
        # my_log.my_info("目前的测试结果是{}".format(test_result.json()))
        # my_log.my_info("预期结果是:{}".format(eval(expected)))

        #增加一个判断 传递cookies
        if test_result.cookies:  #判断请求cookies是否为空
            setattr(get_data.GetData, "COOKIES", test_result.cookies)

        #打印出测试结果与预期结果
        my_log.my_info("测试结果是:{}".format(test_result.json()))
        my_log.my_info("预期结果是:{}".format(eval(expected)))

        #测试结果与预期结果进行断言
        try:
            if sql is not None:
                after_amount = DoMysql().do_mysql(eval(sql)["sql"], 1)[0]
                my_log.my_info("提现之后的用户余额是:{}".format(after_amount))
                withdraw_amount = int(eval(param)["amount"])
                my_log.my_info("提现金额是:{}".format(str(withdraw_amount)))
                expected_amount = before_amount - withdraw_amount
                self.assertEqual(expected_amount, after_amount)
                expected = expected.replace("expectedamount",
                                            str(expected_amount))
                my_log.my_info("预期的用户余额是:{}".format(expected_amount))
            self.assertEqual(
                eval(expected)["status"],
                test_result.json()["status"])
            self.assertEqual(
                eval(expected)["code"],
                test_result.json()["code"])
            self.assertEqual(eval(expected)["msg"], test_result.json()["msg"])
            result = "pass"
            my_log.my_info("测试通过了")
        except AssertionError as e:
            my_log.my_error("测试失败,http请求发生错误")
            result = "failed"
            raise e
        finally:
            #写回测试结果
            row = case_id + 1
            DoExcel(project_path.case_path,
                    "withdraw").write_data(row, test_result.text, result)
Exemplo n.º 21
0
from ddt import ddt,data

__author__ = 'Administrator'
import unittest
from  common.learn_do_excel import DoExcel
from  common.cs import Do_Requests
from  common.do_requests import DoRequests
from  common import project_path
from  common import get_data
from  common.my_log import MyLogg
mylog=MyLogg()
test_data=DoExcel(project_path.exampels_path,"recharge").read_data()
print(test_data)
@ddt
class TestCases(unittest.TestCase):
    @data(*test_data)
    def test_001(self,item):
        global param
        global url
        global method
        global case_id
        global modular
        global title
        global expected



        url=item["url"]
        method=item["method"]
        param=item["param"]
Exemplo n.º 22
0
#2引入ddt,参数化我们测试用例里面的每一条数据,提高复用性,做法就是先获取excel文件中用例
#1)然后通过data传入(需要解包),然后将data里面的元祖的每一个元素,传入到函数中,再对传入的元素进行处理
#3测试用例里面引入try..except..finally,最后写回测试数据
#4测试报告--在run文件中进行运行
#5测试报告的路径

import unittest
from common.do_mysql import DoMysql
from common import get_data
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "getLoanList").read_data()


@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        global before_amount
Exemplo n.º 23
0
__author__ = '程程'
import unittest
from common.do_mysql import DoMysql
from common import get_data
from common.do_requests import DoRequests
from common.learn_do_excel import DoExcel
from common import project_path
from ddt import ddt, data, unpack
from common.my_log import MyLogg
my_log = MyLogg()
test_data = DoExcel(project_path.case_path, "generate_repayments").read_data()


# print(test_data)
@ddt
class TestCases(unittest.TestCase):
    def setUp(self):  #测试之前的准备工作
        pass

    def tearDown(self):
        pass

    @data(*test_data)
    def test_001(self, item):
        global result  #指明全球变量
        global COOKIES  #设置cookies为全局变量
        #获取测试用例数据,数据类型基本都为字符串类型
        url = item["url"]
        method = item["method"]
        param = item["param"]
        case_id = item["case_id"]