コード例 #1
0
 def test_case(self, case_value):
     # print('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     do_log.info('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     # data_namedtuple = cases_list.pop(0)
     case_id = case_value.case_id
     msg = case_value.title
     new_url = do_config("api", 'prefix_url') + case_value.url
     new_data = Context.add_parameterization(case_value.data)
     method = case_value.method
     expect_result = case_value.expected
     actual_result = self.do_request(method, new_url, new_data).text
     # 将实际结果写入excel
     # ws.cell(row=case_id + 1, column=6, value=actual_result)
     try:
         self.assertEqual(actual_result,
                          expect_result,
                          msg='测试{}失败'.format(msg))
     except AssertionError as e:
         # print('具体异常为:{}'.format(e))
         do_log.error('具体异常为:{}'.format(e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'Fail', e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, do_config('msg', 'fail_result'), e))
         # ws.cell(row=case_id + 1, column=7, value='Fail')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Fail')
         do_excel.write_result(case_id + 1, actual_result,
                               do_config('msg', 'fail_result'))
         raise e
     else:
         # self.file.write('{},执行结果:{}\n'.format(msg, 'Pass'))
         # self.file.write('{},执行结果:{}\n'.format(msg, do_config('msg', 'success_result')))
         # ws.cell(row=case_id + 1, column=7, value='Pass')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Pass')
         do_excel.write_result(case_id + 1, actual_result,
                               do_config('msg', 'success_result'))
コード例 #2
0
 def test_case(self, case_value):
     # print('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     do_log.info('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     # data_namedtuple = cases_list.pop(0)
     case_id = case_value.case_id
     msg = case_value.title
     new_url = do_config("api", 'prefix_url') + case_value.url
     new_data = Context.login_parameterization(case_value.data)
     method = case_value.method
     expect_result = case_value.expected
     check_sql = case_value.check_sql
     if check_sql:
         check_sql = Context.login_parameterization(check_sql)
         mysql_result = self.do_mysql.sql_execute(check_sql)
         # decimal类型数据,需要转化为float
         money_before_recharge = float(mysql_result['LeaveAmount'])
         money_before_recharge = round(money_before_recharge, 2)  # 四舍五入保留两位小数
     actual_result = self.do_request(method, new_url, new_data)
     try:
         self.assertEqual(200,
                          actual_result.status_code,
                          msg='测试{}时,请求失败!状态码为{}'.format(case_value.title, actual_result.status_code))
     except AssertionError as e:
         do_log.error('具体异常为:{}'.format(e))
         raise e
     # 将实际结果写入excel
     # ws.cell(row=case_id + 1, column=6, value=actual_result)
     try:
         self.assertEqual(int(actual_result.json()['code']), expect_result, msg='测试{}失败'.format(msg))
         if check_sql:
             check_sql = Context.login_parameterization(check_sql)
             mysql_result = self.do_mysql.sql_execute(check_sql)
             # decimal类型数据,需要转化为float
             money_after_recharge = float(mysql_result['LeaveAmount'])
             money_after_recharge = round(money_after_recharge, 2)  # 四舍五入保留两位小数
             new_data_dict = json.loads(new_data, encoding='utf8')
             current_recharge_money = float(new_data_dict['amount'])
             actual_money = round(current_recharge_money+money_before_recharge, 2)
             self.assertEqual(actual_money, money_after_recharge, msg="数据库中充值后的金额有误")
     except AssertionError as e:
         # print('具体异常为:{}'.format(e))
         do_log.error('具体异常为:{}'.format(e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'Fail', e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, do_config('msg', 'fail_result'), e))
         # ws.cell(row=case_id + 1, column=7, value='Fail')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Fail')
         do_excel.write_result(case_id + 1, int(actual_result.json()['code']), do_config('msg', 'fail_result'))
         raise e
     else:
         # self.file.write('{},执行结果:{}\n'.format(msg, 'Pass'))
         # self.file.write('{},执行结果:{}\n'.format(msg, do_config('msg', 'success_result')))
         # ws.cell(row=case_id + 1, column=7, value='Pass')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Pass')
         do_excel.write_result(case_id + 1, int(actual_result.json()['code']), do_config('msg', 'success_result'))
コード例 #3
0
    def test_case(self, case_value):
        # print('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
        do_log.info('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
        # data_namedtuple = cases_list.pop(0)
        case_id = case_value.case_id
        setattr(Context, 'case_id', 1)
        msg = case_value.title
        url = case_value.url
        data3 = Context.user_verify_parameterization(case_value.data)
        method = case_value.method
        expect_result = case_value.expected
        actual_result = str(Webservice(url, data3, method).result_output())
        if case_id == 1:
            user_data = {'user_auth': data3}
            do_config.write_config(user_data, "user_data2.ini")
        if case_id == 2:
            sql = "DELETE f1,f2 FROM `t_user_info` AS f1 LEFT JOIN `t_user_auth_info` AS f2 ON f1.Fuid=f2.Fuid WHERE f2.Fuid=%s"
            self.do_mysql.sql_execute(sql,
                                      args=(do_config2("user_auth", "uid")))

        if case_id == do_excel.ws.max_row - 1:
            os.remove(CONFIG_USER_FILE_PATH2)
        # try:
        #     self.assertEqual(200,
        #                      actual_result.status_code,
        #                      msg='测试{}时,请求失败!状态码为{}'.format(case_value.title, actual_result.status_code))
        # except AssertionError as e:
        #     do_log.error('具体异常为:{}'.format(e))
        #     raise e
        # 将实际结果写入excel
        # ws.cell(row=case_id + 1, column=6, value=actual_result)
        try:
            self.assertEqual(actual_result,
                             expect_result,
                             msg='测试{}失败'.format(msg))
        except AssertionError as e:
            # print('具体异常为:{}'.format(e))
            do_log.error('具体异常为:{}'.format(e))
            # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'Fail', e))
            # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, do_config('msg', 'fail_result'), e))
            # ws.cell(row=case_id + 1, column=7, value='Fail')
            # self.handle_excel.write_result(case_id + 1, actual_result, 'Fail')
            do_excel.write_result(case_id + 1, actual_result,
                                  do_config('msg', 'fail_result'))
            raise e
        else:
            # self.file.write('{},执行结果:{}\n'.format(msg, 'Pass'))
            # self.file.write('{},执行结果:{}\n'.format(msg, do_config('msg', 'success_result')))
            # ws.cell(row=case_id + 1, column=7, value='Pass')
            # self.handle_excel.write_result(case_id + 1, actual_result, 'Pass')
            do_excel.write_result(case_id + 1, actual_result,
                                  do_config('msg', 'success_result'))
コード例 #4
0
    def test_case(self, case_value):
        # print('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
        do_log.info('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
        # data_namedtuple = cases_list.pop(0)
        case_id = case_value.case_id
        msg = case_value.title
        url = case_value.url
        data2 = Context.register_parameterization(case_value.data)
        if case_id == 1:
            if os.path.exists(CONFIG_USER_FILE_PATH):
                pass
            else:
                user_data = {
                    'user_info': {
                        'mobile': data2['mobile'],
                        'user_id': data2['user_id'],
                        'verify_code': data2['verify_code']
                    }
                }
                do_config.write_config(user_data, "user_data.ini")
                do_config.write_config(user_data, "user_data2.ini")
        method = case_value.method
        expect_result = case_value.expected
        actual_result = str(Webservice(url, data2, method).result_output())

        if case_id == do_excel.ws.max_row - 1:
            os.remove(CONFIG_USER_FILE_PATH)
        # 将实际结果写入excel
        # ws.cell(row=case_id + 1, column=6, value=actual_result)
        try:
            self.assertEqual(actual_result,
                             expect_result,
                             msg='测试{}失败'.format(msg))
        except AssertionError as e:
            # print('具体异常为:{}'.format(e))
            do_log.error('具体异常为:{}'.format(e))
            # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'Fail', e))
            # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, do_config('msg', 'fail_result'), e))
            # ws.cell(row=case_id + 1, column=7, value='Fail')
            # self.handle_excel.write_result(case_id + 1, actual_result, 'Fail')
            do_excel.write_result(case_id + 1, actual_result,
                                  do_config('msg', 'fail_result'))
            raise e
        else:
            # self.file.write('{},执行结果:{}\n'.format(msg, 'Pass'))
            # self.file.write('{},执行结果:{}\n'.format(msg, do_config('msg', 'success_result')))
            # ws.cell(row=case_id + 1, column=7, value='Pass')
            # self.handle_excel.write_result(case_id + 1, actual_result, 'Pass')
            do_excel.write_result(case_id + 1, actual_result,
                                  do_config('msg', 'success_result'))
コード例 #5
0
 def __call__(self, method, url, params=None, is_json=False, **kwargs):
     method = method.lower()
     if isinstance(params, str):
         try:
             params = json.loads(params)
         except Exception as e:
             do_log.error('将json格式数据转换字典时出现异常:{}'.format(e))
             params = eval(params)
     if method == 'get':
         resp = self.a_session.request(method=method, url=url, params=params, **kwargs)
     elif method == 'post':
         if is_json:
             resp = self.a_session.request(method=method, url=url, json=params, **kwargs)
         else:
             resp = self.a_session.request(method=method, url=url, data=params, **kwargs)
     else:
         do_log.error('不支持{}请求方法'.format(method))
         resp = None
     return resp
コード例 #6
0
 def test_case(self, case_value):
     """
     注册功能用例
     :param case_value:
     :return:
     """
     # print('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     do_log.info('\nRunning Test Method: {}'.format(inspect.stack()[0][3]))
     # data_namedtuple = cases_list.pop(0)
     case_id = case_value.case_id
     msg = case_value.title
     url = case_value.url
     data1 = eval(Context.mobile_replace(case_value.data))
     method = case_value.method
     expect_result = case_value.expected
     actual_result = str(Webservice(url, data1, method).result_output())
     # 将实际结果写入excel
     # ws.cell(row=case_id + 1, column=6, value=actual_result)
     try:
         self.assertEqual(actual_result,
                          expect_result,
                          msg='测试{}失败'.format(msg))
     except AssertionError as e:
         # print('具体异常为:{}'.format(e))
         do_log.error('具体异常为:{}'.format(e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, 'Fail', e))
         # self.file.write('{},执行结果:{},具体异常为:{}\n'.format(msg, do_config('msg', 'fail_result'), e))
         # ws.cell(row=case_id + 1, column=7, value='Fail')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Fail')
         do_excel.write_result(case_id + 1, actual_result,
                               do_config('msg', 'fail_result'))
         raise e
     else:
         # self.file.write('{},执行结果:{}\n'.format(msg, 'Pass'))
         # self.file.write('{},执行结果:{}\n'.format(msg, do_config('msg', 'success_result')))
         # ws.cell(row=case_id + 1, column=7, value='Pass')
         # self.handle_excel.write_result(case_id + 1, actual_result, 'Pass')
         do_excel.write_result(case_id + 1, actual_result,
                               do_config('msg', 'success_result'))