Esempio n. 1
0
 def setUp(self):
     self.sql = con.get('SQL', 'Income_LeaveAmount')
     #充值之前的账户余额
     self.LeaveAmount = MysqlUtill().get_fetch_one(sql=self.sql)
     my_log.info("初始化数据-->充值前账户余额:{}".format(self.LeaveAmount["LeaveAmount"]))
     # 借款人充值流水记录
     self.sq = con.get('SQL', 'normal_record')
     self.Pay_record = MysqlUtill().get_fetch_one(sql=self.sq)
     my_log.info("初始化数据-->没有充值之前最新的一条流水记录:{}".format(self.Pay_record))
Esempio n. 2
0
 def test_http_case(self,i):
     #对excel里面的正则进行替换
     date = Regular().regular(i.request_data)  # 正则参数替换
     my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.
                 format(i.case_id, i.case_name, i.case_rept, i.api_name))
     my_log.info('================检查url====================')
     my_log.info('url:{}'.format(config_url+i.url))
     my_log.info('================检查request_data====================')
     my_log.info('request_data:{}'.format(i.request_data))
     my_log.info('================检查替换后的request_data====================')
     my_log.info('request_data:{}'.format(date))
     my_log.info('================检查method====================')
     my_log.info('method:{}'.format(i.mathod))
     my_log.info('================检查api_name====================')
     my_log.info('api_name:{}'.format(i.api_name))
     my_log.info('================检查预期结果expected_data====================')
     my_log.info('expected_data:{}'.format(i.expected_data))
     if hasattr(Context,'cookies'):      #因为第一次登陆没有cookies,需要判断
         cookies = getattr(Context,'cookies')    #存在赋值给cookies
     else:
         cookies = None
     res = HttpRequest(config_url+i.url,json.loads(date),i.mathod,cookies)
     my_log.info('实际结果:{}'.format(res.get_json()))
     # 当cookie不为空时,改变全局变量的值
     if res.get_cookies():
         setattr(Context,'cookies',res.get_cookies())
     my_log.info('=================开始断言==================')
     try:
         #断言判断实际结果与期望结果是否一致
         self.assertEqual(json.loads(i.expected_data)['code'],json.loads(res.get_text())['code'])
         Testresult = 'pass'
         if json.loads(res.get_text())['code'] == '10001':     #项目新增成功,进行数据校验
             sql = con.get("SQL","new_LoanId")
             new_ID = MysqlUtill().get_fetch_one(sql=sql)   #获取最新的项目ID
             if new_ID["Id"] == self.ID["Id"] :
                 my_log.info("数据库校验-->还未进行项目新增操作")
             if new_ID["Id"] not in self.ID:
                 my_log.info("数据库校验-->{}ID项目新增成功".format(new_ID["Id"]))
             else:
                 my_log.info("数据库校验-->{}ID项目新增失败".format(new_ID["Id"]))
         else:
             # 项目新增失败,进行数据校验
             sql = con.get("SQL", "new_LoanId")
             new_ID = MysqlUtill().get_fetch_one(sql=sql)  # 获取最新的项目ID
             if new_ID["Id"] in self.ID:
                 my_log.info("数据库校验-->项目新增失败")
     except Exception as e:
         Testresult = 'failed'
         my_log.error('断言错误:{0}'.format(e))
         raise e
     finally:
         my_log.info('resultd的值是:{0}'.format(Testresult))
         my_log.info('=================结束断言==================')
         #写入实际结果actual和result值
         excel_date.write_by_case_id(sheet_name='add', case_id=i.case_id,
                                     actual=res.get_text(), result=Testresult)
Esempio n. 3
0
    def test_http_case(self, i):
        global cookies  # 声明全局变量
        #对excel里面的正则进行替换
        date = Regular().regular(i.request_data)  # 正则参数替换
        my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.format(
            i.case_id, i.case_name, i.case_rept, i.api_name))
        my_log.info('================检查url====================')
        my_log.info('url:{}'.format(config_url + i.url))
        my_log.info('================检查request_data====================')
        my_log.info('request_data:{}'.format(i.request_data))
        my_log.info('================检查替换后的request_data====================')
        my_log.info('request_data:{}'.format(date))
        my_log.info('================检查method====================')
        my_log.info('method:{}'.format(i.mathod))
        my_log.info('================检查api_name====================')
        my_log.info('api_name:{}'.format(i.api_name))
        my_log.info('================检查预期结果expected_data====================')
        my_log.info('expected_data:{}'.format(i.expected_data))
        res = HttpRequest(config_url + i.url, json.loads(date), i.mathod,
                          cookies)
        my_log.info('实际结果:{}'.format(res.get_json()))
        # 当cookie不为空时,改变全局变量的值
        if res.get_cookies():
            cookies = res.get_cookies()
            my_log.info('=================开始断言==================')
        try:
            #断言判断实际结果与期望结果是否一致
            self.assertEqual(
                json.loads(i.expected_data)['code'],
                json.loads(res.get_text())['code'])
            Testresult = 'pass'
            if json.loads(res.get_text())['code'] == '10001':  # 查询成功,进行数据库校验
                recroed = MysqlUtill().get_fetch_one(sql)
                try:
                    if recroed is None:
                        my_log.info("数据库校验-->投资人还未进行投资或者充值")
                    elif recroed['Id'] == Income_record['Id']:
                        my_log.info("数据库校验-->查询成功,最新记录ID:{}".format(
                            recroed['Id']))
                    elif Income_record is None and recroed is not None:
                        my_log.info("数据库校验-->查询成功,最新记录ID:{}".format(
                            recroed['Id']))
                except Exception as e:
                    my_log.info("数据库校验-->查询成功异常{}".format(e))
                    raise e
            else:  #查询失败
                my_log.info("数据库校验-->查询失败!!!")

        except Exception as e:
            Testresult = 'failed'
            my_log.error('断言错误:{0}'.format(e))
            raise e
        finally:
            my_log.info('resultd的值是:{0}'.format(Testresult))
            my_log.info('=================结束断言==================')
            #写入实际结果actual和result值
            excel_date.write_by_case_id(sheet_name='getFinanceLogList',
                                        case_id=i.case_id,
                                        actual=res.get_text(),
                                        result=Testresult)
Esempio n. 4
0
 def setUp(self):
     #用户最新一条投资记录
     global sql,Investment_all
     sql =con.get("SQL","Investment_all")
     Investment_all = MysqlUtill().get_fetch_one(sql)
     if Investment_all is None:
         my_log.info("初始化数据--》用户还未进行投资")
 def setUp(self):
     self.sql = con.get('SQL','Income_LeaveAmount')
     #充值之前的账户余额
     self.LeaveAmount = MysqlUtill().get_fetch_one(sql=self.sql)
     try:
         if self.LeaveAmount["LeaveAmount"] == 0:
             my_log.info("初始化数据--》账户余额为0 ,不允许提现,请先充值!")
         else:
             my_log.info("初始化数据--》提现前账户余额:{}".format(self.LeaveAmount["LeaveAmount"]))
     except Exception as e:
         my_log.info("初始化数据--》账户金额异常:{}".format(e))
         raise e
     #借款人提现流水记录
     self.sq = con.get('SQL','normal_record')
     self.Pay_record = MysqlUtill().get_fetch_one(sql=self.sq)
     my_log.info("初始化数据--》没有提现之前最新的一条流水记录:{}".format(self.Pay_record))
Esempio n. 6
0
class Context:
    #创建配置文件实例
    config = Reading(http_path.config_path_control)
    #获取数据库最大phone查询sql
    sql = config.get("SQL", "sql_max_Phone")
    #获取配置文件里面项目用户
    normal_uesr = config.get('BASIC', 'normal_uesr')
    # 获取配置文件里面的购买用户
    Income_name = config.get('BASIC', 'Income_name')
    # 获取配置文件里面的pwd
    pwd = config.get('BASIC', 'pwd')
    # 审核用户
    audit_user = config.get('BASIC', 'audit_user')
    # 查询项目用户MemberID
    Member = MysqlUtill().get_fetch_one(config.get("SQL", "sql_PayMemberId"))
    #用户不存在是,ID为空
    if Member is not None:
        PayMemberId = str(Member['Id'])
    else:
        print("反射类里面获取的:PayMemberId为None")
    # 查询购买用户MemberID
    Income = MysqlUtill().get_fetch_one(config.get("SQL",
                                                   "sql_IncomeMemberId"))
    if Income is not None:
        IncomeMemberId = str(Income['Id'])
    else:
        print("反射类里面获取的:PayMemberId为None")
    #查询项目的全部id
    Loan = MysqlUtill().get_fetch_one(config.get("SQL", "sql_LoanId"))
    #还没有新增项目,ID为空
    if Loan is not None:
        LoanId = str(Loan['Id'])
    else:
        print("反射类里面获取的:LoanId为None")
    #最新的项目id
    an = MysqlUtill().get_fetch_one(config.get("SQL", "sql_anId"))
    if an is not None:
        anId = str(an['Id'])
    else:
        print("反射类里面获取的:anId为None")
    # 满标的项目ID
    mark = MysqlUtill().get_fetch_one(config.get("SQL", "Full_mark"))
    if mark is not None:
        Full_mark = str(mark['Id'])
    else:
        print("反射类里面获取的:Full_mark为None")
 def setUp(self):
     global sql, back_plan, Money_back_plan
     sql = con.get("SQL", "Money_back_plan")
     Money_back_plan = MysqlUtill().get_fetch_one(sql=sql)
     if Money_back_plan is not None:
         back_plan = Money_back_plan
         print("Money_back_plan:", type(Money_back_plan), Money_back_plan)
     else:
         my_log.info("初始化数据--》回款计划暂未生成!")
Esempio n. 8
0
 def test_http_case(self,i):
     global cookies  # 声明全局变量
     #对excel里面的正则进行替换
     date = Regular().regular(i.request_data)  # 正则参数替换
     my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.
                 format(i.case_id, i.case_name,i.case_rept,i.api_name))
     my_log.info('================检查url====================')
     my_log.info('url:{}'.format(config_url+i.url))
     my_log.info('================检查request_data====================')
     my_log.info('request_data:{}'.format(i.request_data))
     my_log.info('================检查替换后的request_data====================')
     my_log.info('request_data:{}'.format(date))
     my_log.info('================检查method====================')
     my_log.info('method:{}'.format(i.mathod))
     my_log.info('================检查api_name====================')
     my_log.info('api_name:{}'.format(i.api_name))
     my_log.info('================检查预期结果expected_data====================')
     my_log.info('expected_data:{}'.format(i.expected_data))
     if hasattr(Context,'cookies'):      #因为第一次登陆没有cookies,需要判断
         cookies = getattr(Context,'cookies')    #存在赋值给cookies
     else:
         cookies = None
     res = HttpRequest(config_url+i.url,json.loads(date),i.mathod,cookies)
     my_log.info('实际结果:{}'.format(res.get_json()))
     # 当cookie不为空时,把cookie写入反射类里面
     if res.get_cookies():
         setattr(Context,'cookies',res.get_cookies())
     my_log.info('=================开始断言==================')
     try:
         #断言判断实际结果与期望结果是否一致
         self.assertEqual(json.loads(i.expected_data)['code'],json.loads(res.get_text())['code'])
         Testresult = 'pass'
         if json.loads(res.get_text())['code'] == '10001':  # 查询成功,进行数据库校验
             all_ment = MysqlUtill().get_fetch_one(sql)
             try:
                 if all_ment is None:
                     my_log.info("数据库校验-->用户还未进行投资")
                 elif Investment_all['Id'] == all_ment['Id'] :
                     my_log.info("数据库校验-->查询成功!,最新记录ID:{}".format(all_ment['Id'] ))
                 elif Investment_all is None and all_ment is not None:
                     my_log.info("数据库校验-->查询成功!")
             except Exception as e:
                 my_log.info("数据库校验-->查询成功异常{}".format(e))
                 raise e
         else:
             my_log.info("数据库校验-->查询失败!!!")
     except Exception as e:
         Testresult = 'failed'
         my_log.error('断言错误:{0}'.format(e))
         raise e
     finally:
         my_log.info('resultd的值是:{0}'.format(Testresult))
         my_log.info('=================结束断言==================')
         #写入实际结果actual和result值
         excel_date.write_by_case_id(sheet_name='geneInvestsByMemberId', case_id=i.case_id,
                                     actual=res.get_text(), result=Testresult)
 def setUp(self):
     global sql1, sql2, sql3, sql4, sql5, meny, mount, poject_Amount, normal_record, Income_record, record_all
     # 借款人用户金额
     sql1 = con.get("SQL", "Pay_LeaveAmount")
     meny = MysqlUtill().get_fetch_one(sql=sql1)
     my_log.info("初始化数据--》借款人账户余额为:{}".format(meny["LeaveAmount"]))
     print(type(meny), meny)
     # 投资人用户金额
     sql2 = con.get("SQL", "Income_LeaveAmount")
     mount = MysqlUtill().get_fetch_one(sql=sql2)
     print(type(mount), mount)
     try:
         if mount["LeaveAmount"] == 0:
             my_log.info("初始化数据--》投资人账户余额为0 ,不允许投资,请先充值!")
         else:
             my_log.info("初始化数据--》投资人账户余额为:{}".format(mount["LeaveAmount"]))
     except Exception as e:
         my_log.info("初始化数据--》投资人账户金额异常:{}".format(e))
         raise e
     # 标的金额
     sql3 = con.get("SQL", "poject_Amount")
     poject_Amount = MysqlUtill().get_fetch_one(sql=sql3)
     print(type(poject_Amount), poject_Amount)
     # 借款人用户流水记录
     sql4 = con.get("SQL", "normal_record")
     normal_record = MysqlUtill().get_fetch_one(sql=sql4)
     # 投资人用户流水记录
     sql5 = con.get("SQL", "Income_record")
     Income_record = MysqlUtill().get_fetch_one(sql=sql5)
     #对当前项目的投资记录
     sql6 = con.get("SQL", "Investment_record_all")
     record_all = MysqlUtill().get_fetch_all(sql=sql6)
 def test_http_case(self, i):
     #对excel里面的正则进行替换
     date = Regular().regular(i.request_data)  # 正则参数替换
     my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.format(
         i.case_id, i.case_name, i.case_rept, i.api_name))
     my_log.info('================检查url====================')
     my_log.info('url:{}'.format(config_url + i.url))
     my_log.info('================检查request_data====================')
     my_log.info('request_data:{}'.format(i.request_data))
     my_log.info('================检查替换后的request_data====================')
     my_log.info('request_data:{}'.format(date))
     my_log.info('================检查method====================')
     my_log.info('method:{}'.format(i.mathod))
     my_log.info('================检查api_name====================')
     my_log.info('api_name:{}'.format(i.api_name))
     my_log.info('================检查预期结果expected_data====================')
     my_log.info('expected_data:{}'.format(i.expected_data))
     if hasattr(Context, 'cookies'):  #因为第一次登陆没有cookies,需要判断
         cookies = getattr(Context, 'cookies')  #存在赋值给cookies
     else:
         cookies = None
     res = HttpRequest(config_url + i.url, json.loads(date), i.mathod,
                       cookies)
     my_log.info('实际结果:{}'.format(res.get_json()))
     # 当cookie不为空时,把cookie写入反射类里面
     if res.get_cookies():
         setattr(Context, 'cookies', res.get_cookies())
     my_log.info('=================开始断言==================')
     try:
         #断言判断实际结果与期望结果是否一致
         self.assertEqual(
             json.loads(i.expected_data)['code'],
             json.loads(res.get_text())['code'])
         Testresult = 'pass'
         if json.loads(res.get_text())['msg'] == '生成回款计划成功':  # 生成成功,进行数据库校验
             new_back_plan = MysqlUtill().get_fetch_one(sql=sql)
             try:
                 if Money_back_plan is None and new_back_plan is not None:
                     my_log.info("数据库校验-->回款计划生成成功!")
                 elif Money_back_plan['Id'] < new_back_plan['Id']:
                     my_log.info("数据库校验-->回款计划生成成功!,最新记录ID:{}".format(
                         new_back_plan['Id']))
                 elif new_back_plan is None:
                     my_log.info("数据库校验-->回款计划暂未生成!")
             except Exception as e:
                 my_log.info("数据库校验-->生成回款计划异常{}".format(e))
                 raise e
         else:  #生成失败
             new_back_plan = MysqlUtill().get_fetch_all(sql=sql)
             try:
                 if Money_back_plan['Id'] == new_back_plan['Id']:
                     my_log.info("数据库校验-->生成失败!")
             except Exception as e:
                 my_log.info("数据库校验-->生成失败异常{}".format(e))
                 raise e
     except Exception as e:
         Testresult = 'failed'
         my_log.error('断言错误:{0}'.format(e))
         raise e
     finally:
         my_log.info('resultd的值是:{0}'.format(Testresult))
         my_log.info('=================结束断言==================')
         #写入实际结果actual和result值
         excel_date.write_by_case_id(sheet_name='generateRepayments',
                                     case_id=i.case_id,
                                     actual=res.get_text(),
                                     result=Testresult)
 def test_http_case(self, i):
     #对excel里面的正则进行替换
     date = Regular().regular(i.request_data)  # 正则参数替换
     my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.format(
         i.case_id, i.case_name, i.case_rept, i.api_name))
     my_log.info('================检查url====================')
     my_log.info('url:{}'.format(config_url + i.url))
     my_log.info('================检查request_data====================')
     my_log.info('request_data:{}'.format(i.request_data))
     my_log.info('================检查替换后的request_data====================')
     my_log.info('request_data:{}'.format(date))
     my_log.info('================检查method====================')
     my_log.info('method:{}'.format(i.mathod))
     my_log.info('================检查api_name====================')
     my_log.info('api_name:{}'.format(i.api_name))
     my_log.info('================检查预期结果expected_data====================')
     my_log.info('expected_data:{}'.format(i.expected_data))
     if hasattr(Context, 'cookies'):  # 因为第一次登陆没有cookies,需要判断
         cookies = getattr(Context, 'cookies')  # 存在赋值给cookies
     else:
         cookies = None
     res = HttpRequest(config_url + i.url, json.loads(date), i.mathod,
                       cookies)
     my_log.info('实际结果:{}'.format(res.get_json()))
     # 当cookie不为空时,写用映射文件Context里面
     if res.get_cookies():
         setattr(Context, 'cookies', res.get_cookies())
     my_log.info('=================开始断言==================')
     try:
         #断言判断实际结果与期望结果是否一致
         self.assertEqual(
             json.loads(i.expected_data)['code'],
             json.loads(res.get_text())['code'])
         Testresult = 'pass'
         if json.loads(res.get_text())['code'] == '10001':  # 项目审核成功,数据校验
             global new_status
             new_status = MysqlUtill().get_fetch_one(sql=sql)  #获取最新项目状态
             sta = getattr(Context, 'status')  #获取反射里面的状态
             try:
                 if sta == 1 and new_status['Status'] == 1:  #登录时,获取的状态不变
                     my_log.info(
                         "数据库校验-->没有进行审核操作,状态不变:{}".format(new_status))
                 elif sta == 2 and new_status['Status'] == 2:
                     my_log.info(
                         "数据库校验-->没有进行审核操作,状态不变:{}".format(new_status))
                 elif sta == 3 and new_status['Status'] == 3:
                     my_log.info(
                         "数据库校验-->没有进行审核操作,状态不变:{}".format(new_status))
                 elif sta == 1:
                     if new_status['Status'] in (2, 3, 4, 8):
                         my_log.info(
                             "数据库校验-->审核成功,状态为:{}".format(new_status))
                     else:
                         my_log.info(
                             "数据库校验-->审核失败,状态为:{}".format(new_status))
                 elif sta == 2:
                     if new_status['Status'] in (3, 4, 8):
                         my_log.info(
                             "数据库校验-->审核成功,状态为:{}".format(new_status))
                     else:
                         my_log.info(
                             "数据库校验-->审核失败,状态为:{}".format(new_status))
                 elif sta == 3:
                     if new_status['Status'] in (4, 8):
                         my_log.info(
                             "数据库校验-->审核成功,状态为:{}".format(new_status))
                     else:
                         my_log.info(
                             "数据库校验-->审核失败,状态为:{}".format(new_status))
                 else:
                     my_log.info("数据库校验-->审核失败,状态为:{}".format(new_status))
             except Exception as e:
                 my_log.info("审核成功异常:{}".format(e))
                 raise e
     except Exception as e:
         Testresult = 'failed'
         my_log.error('断言错误:{0}'.format(e))
         sta = getattr(Context, 'status')
         new_sta = MysqlUtill().get_fetch_one(sql=sql)
         try:  # 项目审核失败,数据校验
             if sta == new_status['Status']:
                 my_log.info("数据库校验-->修改失败,当前标已经是{}该状态".format(new_sta))
             elif new_status['Status'] in ('5', '6', '7', '8', '9', '10'):
                 my_log.info("数据库校验-->审核失败,状态不能直接更新到:{}".format(new_sta))
         except Exception as e:
             my_log.info("数据库校验-->审核失败异常:{}".format(e))
             raise e
         raise e
     finally:
         my_log.info('resultd的值是:{0}'.format(Testresult))
         my_log.info('=================结束断言==================')
         #写入实际结果actual和result值
         excel_date.write_by_case_id(sheet_name='audit',
                                     case_id=i.case_id,
                                     actual=res.get_text(),
                                     result=Testresult)
 def setUp(self):
     global status, sql
     sql = con.get('SQL', 'Status')
     status = MysqlUtill().get_fetch_one(sql=sql)
     setattr(Context, 'status', status['Status'])  #把状态写入到到反射里面
     my_log.info("初始化数据--》审核之前的状态为:{}".format(status))
    def test_http_case(self, i):
        #对excel里面的正则进行替换
        date = Regular().regular(i.request_data)  # 正则参数替换
        my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.format(
            i.case_id, i.case_name, i.case_rept, i.api_name))
        my_log.info('================检查url====================')
        my_log.info('url:{}'.format(config_url + i.url))
        my_log.info('================检查request_data====================')
        my_log.info('request_data:{}'.format(i.request_data))
        my_log.info('================检查替换后的request_data====================')
        my_log.info('request_data:{}'.format(date))
        my_log.info('================检查method====================')
        my_log.info('method:{}'.format(i.mathod))
        my_log.info('================检查api_name====================')
        my_log.info('api_name:{}'.format(i.api_name))
        my_log.info('================检查预期结果expected_data====================')
        my_log.info('expected_data:{}'.format(i.expected_data))
        if hasattr(Context, 'cookies'):  #因为第一次登陆没有cookies,需要判断
            cookies = getattr(Context, 'cookies')  #存在赋值给cookies
        else:
            cookies = None
        res = HttpRequest(config_url + i.url, json.loads(date), i.mathod,
                          cookies)
        my_log.info('实际结果:{}'.format(res.get_json()))
        # 当cookie不为空时,把cookie写入反射类里面
        if res.get_cookies():
            setattr(Context, 'cookies', res.get_cookies())
        my_log.info('=================开始断言==================')
        try:
            #断言判断实际结果与期望结果是否一致
            self.assertEqual(
                json.loads(i.expected_data)['code'],
                json.loads(res.get_text())['code'])
            Testresult = 'pass'
            if json.loads(res.get_text())['code'] == '10001':  # 充值成功,进行数据库校验
                # 把竞标成功的金额写入映射Context里面
                if 'amount' not in eval(date):  # 如果在date里面没有amount字段,直接赋值为0
                    setattr(Context, "leaveamount", 0)
                else:
                    setattr(Context, "leaveamount", eval(date)["amount"])
                re_amount = getattr(Context, "leaveamount")  # 读取反射里面竞标成功的金额
                #标的最新的金额
                # new_poject_Amount = MysqlUtill().get_fetch_one(sql=sql3)
                # po_Amount = int(poject_Amount["Amount"]) - int(re_amount)
                # try:
                #     if new_poject_Amount == '0':
                #         my_log.info("数据库校验-->已满标")
                #     else:
                #         self.assertEqual(int(new_poject_Amount["Amount"]), po_Amount)
                #         my_log.info("数据库校验-->最新可竞标的余额:{}".format(new_poject_Amount["Amount"]))
                # except BaseException as b:
                #     my_log.info("数据库校验-->竞标余额异常:{}".format(b))
                #     raise b
                #借款人
                # new_meny = MysqlUtill().get_fetch_one(sql=sql1)
                # ne_men = int(meny["LeaveAmount"]) + int(re_amount)
                # try:
                #     self.assertEqual(int(new_meny["LeaveAmount"]), ne_men)
                #     my_log.info("数据库校验-->借款人的最新余额:{}".format(new_meny["LeaveAmount"]))
                # except BaseException as b:
                #     my_log.info("数据库校验-->借款人余额异常:{}".format(b))
                #     raise b
                #投资人
                new_mount = MysqlUtill().get_fetch_one(sql=sql2)
                ne_moun = float(mount["LeaveAmount"]) - float(
                    re_amount["LeaveAmount"])
                try:
                    self.assertEqual(float(new_mount["LeaveAmount"]),
                                     ne_moun)  # 判断余额是否正确
                    my_log.info("数据库校验-->投资人的最新余额:{}".format(
                        new_mount["LeaveAmount"]))
                except BaseException as b:
                    my_log.info("数据库校验-->投资人余额异常:{}".format(b))
                    raise b
                # 把借款人的流水记录
                new_normal_record = MysqlUtill().get_fetch_one(sql=sql4)
                if normal_record is None:
                    my_log.info('数据库校验-->借款人未充值、提现,没有流水记录!')
                else:
                    if normal_record['Id'] == new_normal_record['Id']:
                        my_log.info('数据库校验-->借款人没有进行提现操作')
                    elif new_normal_record['Id'] > normal_record['Id']:
                        my_log.info('数据库校验-->借款人提现操作成功,流水记录ID是{}'.format(
                            new_normal_record['Id']))
                    else:
                        raise AssertionError
                # 把投资人投资记录
                new_Income_record = MysqlUtill().get_fetch_one(sql=sql4)
                if Income_record is None:
                    my_log.info('数据库校验-->投资人第一次投标')
                else:
                    if Income_record['Id'] == new_Income_record['Id']:
                        my_log.info('数据库校验-->投资人没有进行提现操作')
                    elif new_Income_record['Id'] > Income_record['Id']:
                        my_log.info('数据库校验-->投资人提现操作成功,流水记录ID是{}'.format(
                            new_Income_record['Id']))
                    else:
                        raise AssertionError
            else:  #竞标失败,数据校验
                new_poject_Amount = MysqlUtill().get_fetch_one(
                    sql=sql3)  # 最新的竞标金额
                try:
                    self.assertEqual(int(poject_Amount["Amount"]),
                                     new_poject_Amount["Amount"])
                    my_log.info("数据库校验-->最新可竞标的余额:{}".format(
                        poject_Amount["Amount"]))
                except BaseException as b:
                    my_log.info("数据库校验-->竞标余额异常:{}".format(b))
                    raise b
                # 借款人
                new_meny = MysqlUtill().get_fetch_one(sql=sql1)
                try:
                    self.assertEqual(int(meny["LeaveAmount"]),
                                     new_meny["LeaveAmount"])
                    my_log.info("数据库校验-->借款人的最新余额:{}".format(
                        new_meny["LeaveAmount"]))
                except BaseException as b:
                    my_log.info("数据库校验-->借款人余额异常:{}".format(b))
                    raise b
                # 投资人
                new_mount = MysqlUtill().get_fetch_one(sql=sql2)
                try:
                    self.assertEqual(int(mount["LeaveAmount"]),
                                     new_mount["LeaveAmount"])  # 判断余额是否正确
                    my_log.info("数据库校验-->投资人的最新余额:{}".format(
                        new_mount["LeaveAmount"]))
                except BaseException as b:
                    my_log.info("数据库校验-->投资人余额异常:{}".format(b))
                    raise b
                #把借款人的流水记录
                new_normal_record = MysqlUtill().get_fetch_one(sql=sql4)
                if normal_record is None:
                    my_log.info('数据库校验-->借款人未充值、提现,没有流水记录!')
                else:
                    if normal_record['Id'] == new_normal_record['Id']:
                        my_log.info('数据库校验-->借款人最新流水记录{}'.format(
                            new_normal_record['Id']))
                    else:
                        raise AssertionError
                # 投资人投资记录
                new_Income_record = MysqlUtill().get_fetch_one(sql=sql4)
                if Income_record is None:
                    my_log.info('数据库校验-->投资人第一次投标')
                else:
                    if Income_record['Id'] == new_Income_record['Id']:
                        my_log.info('数据库校验-->投资人最新流水记录{}'.format(
                            new_Income_record['Id']))
                    else:
                        raise AssertionError

        except Exception as e:
            Testresult = 'failed'
            my_log.error('断言错误:{0}'.format(e))
            raise e
        finally:
            my_log.info('resultd的值是:{0}'.format(Testresult))
            my_log.info('=================结束断言==================')
            #写入实际结果actual和result值
            excel_date.write_by_case_id(sheet_name='bidLoan',
                                        case_id=i.case_id,
                                        actual=res.get_text(),
                                        result=Testresult)


# if __name__ == '__main__':
#     unittest.main()
# 金额为小数时,如何避免重复判断
Esempio n. 14
0
 def setUp(self):
     global sql,mark_record
     sql = con.get('SQL','mark_record')
     mark_record = MysqlUtill().get_fetch_one(sql)
     if mark_record is None:
         my_log.info("初始化数据--》标还没有人来投资")
Esempio n. 15
0
 def setUp(self):
     #获取用户所有的项目id
     self.sql = con.get("SQL","sql_LoanId")
     self.ID = MysqlUtill().get_fetch_one(sql=self.sql)
Esempio n. 16
0
    def test_http_case(self,i):
        date = Regular().regular(i.request_data)  #正则参数替换
        my_log.info('正在执行地{0}条用例; 用例名称:{1}; 用例说明:{2}; 用例接口:{3}'.
                    format(i.case_id, i.case_name, i.case_rept, i.api_name))
        my_log.info('================检查url====================')
        my_log.info('url:{}'.format(config_url+i.url))
        my_log.info('================检查request_data====================')
        my_log.info('request_data:{}'.format(i.request_data))
        my_log.info('================检查替换后的request_data====================')
        my_log.info('request_data:{}'.format(date))
        my_log.info('================检查method====================')
        my_log.info('method:{}'.format(i.mathod))
        my_log.info('================检查api_name====================')
        my_log.info('api_name:{}'.format(i.api_name))
        my_log.info('================检查预期结果expected_data====================')
        my_log.info('expected_data:{}'.format(i.expected_data))
        if hasattr(Context,'cookies'):      #因为第一次登陆没有cookies,需要判断
            cookies = getattr(Context,'cookies')    #存在赋值给cookies
        else:
            cookies = None
        res = HttpRequest(config_url+i.url,eval(date),i.mathod,cookies)
        my_log.info('实际结果:{}'.format(res.get_json()))
        # 当cookie不为空时,写用映射文件Context里面
        if res.get_cookies():
            setattr(Context,'cookies',res.get_cookies())
        my_log.info('=================开始断言==================')
        try:
            #断言判断实际结果与期望结果是否一致
            self.assertEqual(json.loads(i.expected_data)['code'],json.loads(res.get_text())['code'])
            Testresult = 'pass'
            if json.loads(res.get_text())['code'] == '1000':  # 充值成功,进行数据库校验
                #把充值成功的金额写入映射Context里面
                if 'amount' in json.loads(date):      #如果在date里面没有amount字段,直接赋值为0
                    setattr(Context, "leaveamount", eval(date)["amount"])
                else:
                    setattr(Context, "leaveamount", 0)

                Amount = MysqlUtill().get_fetch_one(sql=self.sql)   #获取最新的余额
                mount = getattr(Context, "leaveamount")  #读取反射里面充值成功的金额
                # 余额 = 初始金额+充值金额
                money = int(self.LeaveAmount["LeaveAmount"]) + int(mount)
                try:
                    self.assertEqual(int(Amount["LeaveAmount"]), money)     #判断余额是否正确
                    my_log.info("数据库校验-->充值成功后账户余额:{}".format(Amount["LeaveAmount"]))
                except BaseException as b:
                    my_log.info("数据库校验-->充值异常:{}".format(b))
                    raise b
                # 查询充值成功流水记录
                new_recod = MysqlUtill().get_fetch_one(sql=self.sq)
                if self.Pay_record is None:
                    my_log.info('数据库校验-->用户无流水记录')
                else:
                    if self.Pay_record['Id'] == new_recod['Id']:
                        my_log.info('数据库校验-->没有进行充值操作')
                    elif new_recod['Id'] > self.Pay_record['Id']:
                        my_log.info('数据库校验-->充值操作成功,流水记录ID是{}'.format(new_recod['Id']))
                    else:
                        raise AssertionError
            else:
                # 充值失败,进行数据库校验
                try:
                    mou = MysqlUtill().get_fetch_one(sql=self.sql)  # 获取最新的金额
                    self.assertEqual(int(self.LeaveAmount["LeaveAmount"]), int(mou["LeaveAmount"]))  # 判断余额是否正确
                    my_log.info("数据库校验-->充值失败账户余额:{}".format(mou["LeaveAmount"]))
                except Exception as e:
                    my_log.info("数据库校验-->充值异常:{}".format(e))
                    raise e
                # 查询提现成功流水记录
                new_recod = MysqlUtill().get_fetch_one(sql=self.sq)
                if self.Pay_record == None:
                    my_log.info('数据库校验-->用户无流水记录')
                else:
                    if self.Pay_record['Id'] == new_recod['Id']:
                        my_log.info('数据库校验-->充值失败')
                    else:
                        raise AssertionError
        except Exception as e:
            Testresult = 'failed'
            my_log.error('断言错误:{0}'.format(e))
            raise e
        finally:
            my_log.info('resultd的值是:{0}'.format(Testresult))
            my_log.info('=================结束断言==================')
            #写入实际结果actual和result值
            excel_date.write_by_case_id(sheet_name='recharge2', case_id=i.case_id,
                                        actual=res.get_text(), result=Testresult)
Esempio n. 17
0
 def setUp(self):
     global sql, Income_record
     sql = con.get('SQL', 'Income_record')
     Income_record = MysqlUtill().get_fetch_one(sql)
     if Income_record is None:
         my_log.info("初始化数据--》投资人还未进行投资或者充值")