Beispiel #1
0
 def test_recharge(self, value):
     row = value.CaseId + 1  # 用例ID所在行号
     precondition = value.Precondition  # excel用例的前置条件
     title = value.Title  # 用例标题
     url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
     request_value = value.Data  # 请求参数
     request_method = value.Method  # 请求方法
     select_sql = value.Sql  # 查询充值结果的sql语句
     replace_sql = recharge_parameters(select_sql)
     recharge_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
     log.info('执行充值-测试用例"{}"开始'.format(title))
     request_value = recharge_parameters(request_value)
     before_amount = self.mysql(sql=replace_sql)['LeaveAmount']  # 充值前的金额
     # 切换会话
     if precondition == '用户未登录':
         response = self.request(request_method, url=url, data=request_value)
     else:
         response = request(request_method, url=url, data=request_value)
     after_amount = self.mysql(sql=replace_sql)['LeaveAmount']  # 充值后的金额
     actual_amount = str(after_amount - before_amount)  # 实际金额
     actual_code = response.json()['code']  # 实际code
     # 构造个实际结果的字典
     actual_result = dict(leaveamount=actual_amount, code=actual_code)
     do_excel.write_cell(
         do_conf('SheetName', 'Recharge'),
         row,
         do_conf('ExcelNum', 'Actual_Column'),
         HandleJson.python_to_json(actual_result)
     )
     try:
         self.assertEqual(recharge_expected, actual_result, msg='测试{}失败'.format(title))
     except AssertionError as e:
         do_excel.write_cell(
             do_conf('SheetName', 'Recharge'),
             row,
             do_conf('ExcelNum', 'Result_Column'),
             do_conf('Result', 'Fail'),
             color=RED)
         log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(inspect.stack()[0][3], title, e))
         raise e
     else:
         do_excel.write_cell(
             do_conf('SheetName', 'Recharge'),
             row,
             do_conf('ExcelNum', 'Result_Column'),
             do_conf('Result', 'Pass'),
             color=GREEN)
         log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
     log.info('执行登录-测试用例"{}"结束'.format(title))
Beispiel #2
0
 def test_add(self, value):
     row = value.CaseId + 1  # 用例ID所在行号
     precondition = value.Precondition  # excel用例的前置条件
     title = value.Title  # 用例标题
     url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
     request_method = value.Method  # 请求方法
     request_value = value.Data  # 请求参数
     select_sql = value.Sql  # 查询数据库中不存在的member id
     add_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
     if precondition == '借款人用户ID不存在':
         not_exist_loan_member_id = str(
             int(self.mysql(select_sql)['Id']) - 1)
         request_value = add_parameters(not_exist_loan_member_id,
                                        request_value)
     else:
         request_value = add_parameters('', request_value)
     log.info('执行加标-测试用例"{}"开始'.format(title))
     response = request(request_method, url=url, data=request_value)
     actual_result = response.json()
     do_excel.write_cell(do_conf('SheetName', 'Add'), row,
                         do_conf('ExcelNum', 'Actual_Column'),
                         response.text)
     try:
         self.assertEqual(add_expected,
                          actual_result,
                          msg='测试{}失败'.format(title))
     except AssertionError as e:
         do_excel.write_cell(do_conf('SheetName', 'Add'),
                             row,
                             do_conf('ExcelNum', 'Result_Column'),
                             do_conf('Result', 'Fail'),
                             color=RED)
         log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
             inspect.stack()[0][3], title, e))
         raise e
     else:
         do_excel.write_cell(do_conf('SheetName', 'Add'),
                             row,
                             do_conf('ExcelNum', 'Result_Column'),
                             do_conf('Result', 'Pass'),
                             color=GREEN)
         log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
     log.info('执行加标-测试用例"{}"结束'.format(title))
Beispiel #3
0
 def test_bid_loan(self, value):
     row = value.CaseId + 1  # 用例ID所在行号
     precondition = value.Precondition  # excel用例的前置条件
     title = value.Title  # 用例标题
     url = do_conf('URL', 'Host_Url') + value.URL  # 用例url
     request_method = value.Method  # 请求方法
     request_value = value.Data  # 请求参数
     select_sql = value.Sql
     audit_expected = HandleJson.json_to_python(value.Expected)  # 期望结果
     if precondition == '投资人不存在':
         not_exist_member_id = str(int(self.mysql(select_sql)['Id']) - 1)
         setattr(DataReplace, 'non_exist_member_id', not_exist_member_id)
         request_value = invest_parameters(request_value)
     elif precondition == '标的不存在':
         not_exist_loan_id = str(int(self.mysql(select_sql)['Id']) - 1)
         setattr(DataReplace, 'non_exist_loan_id', not_exist_loan_id)
         request_value = invest_parameters(request_value)
     elif precondition == '标的非竞标状态':
         # 设置标的为非竞标状态
         audit.audit_loan_api(method='post',
                              url=do_conf('URL', 'Host_Url') +
                              '/loan/audit',
                              data={
                                  "id": getattr(DataReplace, 'loan_id'),
                                  "status": 1
                              })
         request_value = invest_parameters(request_value)
     elif precondition == '标的金额不足':
         audit.audit_loan_api(method='post',
                              url=do_conf('URL', 'Host_Url') +
                              '/loan/audit',
                              data={
                                  "id": getattr(DataReplace, 'loan_id'),
                                  "status": 4
                              })
         request_value = invest_parameters(request_value)
     elif precondition == '标的满标':  # 这里不确定测试的对不对
         sql = invest_parameters(select_sql)
         remain_amount = float(
             self.mysql(sql=sql)["invest_amount"])  # 标的剩余金额
         setattr(DataReplace, 'remain_amount',
                 remain_amount)  # 给DataReplace添加一个剩余金额类属性
         request_value = invest_parameters(request_value)
         request(request_method, url=url, data=request_value)
     else:
         request_value = invest_parameters(request_value)
     log.info('执行竞标-测试用例"{}"开始'.format(title))
     response = request(request_method, url=url, data=request_value)
     actual_result = response.json()
     do_excel.write_cell(do_conf('SheetName', 'invest'), row,
                         do_conf('ExcelNum', 'Actual_Column'),
                         response.text)
     try:
         self.assertEqual(audit_expected,
                          actual_result,
                          msg='测试{}失败'.format(title))
     except AssertionError as e:
         do_excel.write_cell(do_conf('SheetName', 'invest'),
                             row,
                             do_conf('ExcelNum', 'Result_Column'),
                             do_conf('Result', 'Fail'),
                             color=RED)
         log.error('{}-测试[{}] :Failed\nDetails:\n{}'.format(
             inspect.stack()[0][3], title, e))
         raise e
     else:
         do_excel.write_cell(do_conf('SheetName', 'invest'),
                             row,
                             do_conf('ExcelNum', 'Result_Column'),
                             do_conf('Result', 'Pass'),
                             color=GREEN)
         log.info('{}-测试[{}] :Passed'.format(inspect.stack()[0][3], title))
     log.info('执行竞标-测试用例"{}"结束'.format(title))