コード例 #1
0
ファイル: test1.py プロジェクト: tudaozi/APITest
class ApiTest:
    for i in range(3):
        method = 'post'
        url = do_config.get_value('request', 'default_address') + '/member/register'
        data = '{"mobilephone": "${not_existed_tel}", "pwd": 123456, "regname": "刀刀"}'
        setattr(Context, 'existed', do_mysql.not_existed_tel())
        request_data = Context.mobilephone(data)
        res = do_request.send_request(method, url, data=request_data)
        print(res.text)
コード例 #2
0
ファイル: cw_0711_project_re.py プロジェクト: tudaozi/APITest
 def test_register(self):
     method = 'POST'
     url = do_config.get_value('request', 'default_address')
     path = '/member/register'
     data = {"mobilephone": "${not_existed_tel}", "pwd": self.pwd, "regname": self.reg_name}
     tel_list = []
     for i in range(3):
         not_existed_tel = str(self.not_existed_tel())
         tel_list.append(not_existed_tel)
         data_re = re.sub(r'\${not_existed_tel}', not_existed_tel, str(data))
         request_result = do_request.send_request(method, url=url + path, data=eval(data_re))
     do_request.request_close()
     return tel_list
コード例 #3
0
 def test_invest(self, case_list):
     case_list_str = str(case_list)
     context_data = HandleContext.manager_user_tel(case_list_str)
     context_data = HandleContext.manager_user_pwd(context_data)
     context_data = HandleContext.borrower_user_id(context_data)
     context_data = HandleContext.loan_id(context_data)
     context_data = HandleContext.investors_user_tel(context_data)
     context_data = HandleContext.investors_user_id(context_data)
     context_data = HandleContext.investors_user_pwd(context_data)
     context_data = HandleContext.not_existed_user_id(context_data)
     context_data = HandleContext.not_exitsed_loan_id(context_data)
     case_list_dict = eval(context_data)
     request_data = case_list_dict['data']
     method = case_list_dict['method']
     url = do_config.get_value(
         'request', 'default_address') + case_list_dict['url_path']
     res = do_request.send_request(method, url, data=request_data)
     add_success_msg = do_config.get_value('request', 'add_success_msg')
     actual = res.text
     if add_success_msg in actual:
         check_sql = case_list_dict['check_sql']
         if check_sql:
             loan_id_sql = do_mysql.sql_search(check_sql)
             loan_id_value = loan_id_sql['Id']
             setattr(HandleContext, 'loan_idw', loan_id_value)
     result = str(case_list_dict['expected'])
     msg = case_list_dict['title']
     true_result = do_config.get_value('msg', 'true_result')
     fail_result = do_config.get_value('msg', 'fail_result')
     try:
         self.assertIn(result, actual, msg)
         print('{},执行结果为:{}'.format(msg, true_result))
         my_excel.write_result(case_list_dict['case_id'] + 1, actual,
                               true_result)
         do_logger.error("{}, 执行结果为: {}".format(msg, true_result))
     except AssertionError as e:
         print('具体异常为{}'.format(e))
         my_excel.write_result(case_list_dict['case_id'] + 1, actual,
                               fail_result)
         do_logger.error("{}, 执行结果为: {},具体异常为{}".format(
             msg, fail_result, e))
         raise e
コード例 #4
0
 def test_login(self, case_list):
     self.my_HandleExcel = HandleExcel(DATA_COMMON_FILE_PATH, 'login')
     request_result = do_request.send_request(case_list['method'],
                                              do_config.get_value('request', 'default_address') + case_list[
                                                  'url_path'],
                                              case_list['data'])
     actual_text = request_result.text
     actual_value = json.loads(actual_text)['code']
     actual = 'code: "{}",'.format(actual_value)
     result = case_list['expected']
     msg = case_list['title']
     try:
         self.assertEqual(result, actual, msg)
         print('{},执行结果为:{}'.format(msg, true_result))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual, true_result)
         do_logger.error("{}, 执行结果为: {}".format(msg, true_result))
     except AssertionError as e:
         print('具体异常为{}'.format(e))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual, fail_result)
         do_logger.error("{}, 执行结果为: {},具体异常为{}".format(msg, fail_result, e))
         raise e
コード例 #5
0
 def test_recharge(self, case_list):
     self.my_HandleExcel = HandleExcel(DATA_COMMON_FILE_PATH, 'recharge')
     if case_list['check_sql']:
         before_sql_data = do_mysql.sql_search(
             case_list['check_sql'],
             virtue=eval(case_list['data'])['mobilephone'])
         self.before_leaveamount = float(before_sql_data['LeaveAmount'])
     request_result = do_request.send_request(
         case_list['method'],
         do_config.get_value('request', 'default_address') +
         case_list['url_path'], case_list['data'])
     actual = int(request_result.json().get('code'))
     result = case_list['expected']
     msg = case_list['title']
     try:
         self.assertEqual(result, actual, msg)
         if case_list['check_sql']:
             after_sql_data = do_mysql.sql_search(
                 case_list['check_sql'],
                 virtue=eval(case_list['data'])['mobilephone'])
             after_leaveamount = float(after_sql_data['LeaveAmount'])
             true_results = after_leaveamount - self.before_leaveamount
             self.assertEqual(
                 eval(case_list['data'])['amount'], round(true_results, 2),
                 msg)
         print('{},执行结果为:{}'.format(msg, true_result))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual,
                                          true_result)
         do_logger.error("{}, 执行结果为: {}".format(msg, true_result))
     except AssertionError as e:
         print('具体异常为{}'.format(e))
         self.my_HandleExcel.write_result(case_list['case_id'] + 1, actual,
                                          fail_result)
         do_logger.error("{}, 执行结果为: {},具体异常为{}".format(
             msg, fail_result, e))
         raise e