Beispiel #1
0
    def test_audit(self, case):
        pass
        # 准备用例数据
        url = conf.get('env', 'url') + case['url']
        method = case['method']
        case['data'] = replace_data(case['data'])
        data = eval(case['data'])
        expected = eval(case['expected'])
        headers = eval(conf.get('env', 'header'))
        headers['Authorization'] = getattr(TestData, 'token_data')
        row = case['case_id'] + 1
        # 发送请求
        response = self.http.send(url=url, method=method, json=data, headers=headers)
        res = response.json()

        # 断言
        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
            if case['check_sql']:
                sql=replace_data(case['check_sql'])
                result_status=self.db.get_one(sql)[0]
                self.assertEqual(expected['status'],result_status)

        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info('用例--->{}:执行未通过'.format(case['title']))
            my_logger.error(e)
            print("预期结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info('用例--->{}:执行已通过'.format(case['title']))
Beispiel #2
0
 def test_login(self, case):
     login_data = eval(case['data'])
     expected = eval(case['expected'])
     case_id = case['case_id']
     url = case['url']
     login_url = base_url + url
     method = case['method']
     response = self.rest.send(url=login_url,
                               method=method,
                               json=login_data,
                               headers=header)
     res = response.json()
     try:
         self.assertEqual(expected['code'], res['code'])
         self.assertEqual(expected['msg'], res['msg'])
     except AssertionError as e:
         self.excel.write_excel(row=case_id + 1, column=8, value='未通过')
         my_logger.info('用例-->{}:执行未通过'.format(case['title']))
         my_logger.error(e)
         print("预期结果:{}".format(expected))
         print("实际结果:{}".format(res))
         raise e
     else:
         self.excel.write_excel(row=case_id + 1, column=8, value='已通过')
         my_logger.info('用例-->{}:执行已通过'.format(case['title']))
 def test_register(self, case):
     # 判断是否有手机号码需要替换
     if '#phone#' in case['data']:
         phone = self.random_phone()
         setattr(TestData,'phone',phone)
         case['data']=case['data'].replace('#phone#',phone)
     data = eval(case['data'])
     expected = eval(case['expected'])
     case_id = case['case_id']
     url = case['url']
     register_url = base_url + url
     method = case['method']
     response = self.rest.send(url=register_url, method=method, json=data, headers=header)
     res = response.json()
     try:
         self.assertEqual(expected['code'], res['code'])
         self.assertEqual(expected['msg'], res['msg'])
         if case['check_sql']:
             # 去数据库查询当前注册的账号是否存在
             sql=replace_data(case['check_sql'])
             my_logger.info('check_sql:{}'.format(sql))
             # 获取数据库中没有没有该用户的信息
             count = self.db.get_count(sql)
             # 数据库中返回的数据做断言,判断是否有一条数据
             self.assertEqual(count, 1)
     except AssertionError as e:
         self.excel.write_excel(row=case_id + 1, column=8, value='未通过')
         my_logger.info('用例-->{}:执行未通过'.format(case['title']))
         my_logger.error(e)
         print("预期结果:{}".format(expected))
         print("实际结果:{}".format(res))
         raise e
     else:
         self.excel.write_excel(row=case_id + 1, column=8, value='已通过')
         my_logger.info('用例-->{}:执行已通过'.format(case['title']))
    def test_withdraw(self, case):
        # 准备用例数据
        # 拼接url
        url = conf.get('env', 'url') + case['url']
        method = case['method']
        case['data'] = replace_data(case['data'])
        data = eval(case['data'])
        expected = eval(case['expected'])
        row = case['case_id'] + 1
        header = eval(conf.get('env', 'header'))
        if case['interface'] != '登录':
            header['Authorization'] = TestData.token_data

        # 判断是否需要校验
        if case['check_sql']:
            sql = case['check_sql'].format(getattr(TestData, 'phone'))
            # 获取充值前的余额
            before_amount = self.db.get_one(sql)[0]

        response = self.rest.send(url=url,
                                  method=method,
                                  json=data,
                                  headers=header)
        res = response.json()

        if case['interface'] == '登录':
            # 获取member_id
            member_id = jsonpath.jsonpath(res, '$..id')[0]
            setattr(TestData, 'member_id', str(member_id))
            # 获取token类型
            token_type = jsonpath.jsonpath(res, '$..token_type')[0]
            # 获取token值
            token = jsonpath.jsonpath(res, '$..token')[0]
            token_data = token_type + ' ' + token
            setattr(TestData, 'token_data', token_data)

        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
            if case['check_sql']:
                sql = case['check_sql'].format(getattr(TestData, 'phone'))
                after_amount = self.db.get_one(sql)[0]
                expected_amount = decimal.Decimal(str(data['amount']))
                my_logger.info('提现前余额:{}\n,提现余额:{}\n,提现后余额:{}'.format(
                    before_amount, expected_amount, after_amount))
                self.assertEqual(expected_amount,
                                 (before_amount - after_amount))

        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info('用例-->{}:执行未通过'.format(case['title']))
            my_logger.error(e)
            print("预期结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info('用例-->{}:执行已通过'.format(case['title']))
Beispiel #5
0
    def test_addloan(self, case):
        # 准备用例数据
        # 拼接完整的接口地址
        url = conf.get('env', 'url') + case['url']
        case['data']=replace_data(case['data'])
        data = eval(case['data'])
        expected = eval(case['expected'])
        row = case['case_id']+1
        header = eval(conf.get('env', 'header'))
        if case['interface'] != '登录':
            header['Authorization'] = getattr(TestData,'token_data')
        method = case['method']

        if case['check_sql']:
            sql = case['check_sql'].format(getattr(TestData, 'member_id'))
            before_count = self.db.get_count(sql)
        # 发送请求
        response = self.http.send(url=url, method=method, json=data, headers=header)
        res = response.json()

        if case['interface']=='登录':
            # 获取用户id
            member_id=jsonpath.jsonpath(res,'$..id')[0]
            setattr(TestData,'member_id',str(member_id))
            # 获取token类型
            token_type=jsonpath.jsonpath(res,'$..token_type')[0]
            # 获取token值
            token=jsonpath.jsonpath(res,'$..token')[0]
            token_data=token_type+' '+token
            setattr(TestData,'token_data',token_data)

        # 断言
        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
            if case['check_sql']:
                sql = case['check_sql'].format(getattr(TestData,'member_id'))
                after_count = self.db.get_count(sql)
                self.assertEqual(1,after_count-before_count)

        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info("用例:{}--->执行未通过".format(case["title"]))
            my_logger.error(e)
            print("预取结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info("用例:{}--->执行已通过".format(case["title"]))
Beispiel #6
0
    def test_addloan(self, case):
        # 准备用例数据
        # 拼接完整的接口地址
        url = conf.get('env', 'url') + case['url']
        if '#member_id#' in case['data']:
            case['data'] = case['data'].replace('#member_id#', str(self.member_id))
        if '#admin_phone#' in case['data']:
            case['data'] = case['data'].replace('#admin_phone#', str(self.admin_phone))
        if '#admin_pwd#' in case['data']:
            case['data'] = case['data'].replace('#admin_pwd#', str(self.admin_pwd))
        data = eval(case['data'])
        expected = eval(case['expected'])
        row = case['case_id']+1
        header = eval(conf.get('env', 'header'))
        if case['interface'] != '登录':
            header['Authorization'] = self.token_data
        method = case['method']
        # 发送请求
        response = self.http.send(url=url, method=method, json=data, headers=header)
        res = response.json()

        if case['interface']=='登录':
            # 获取用户id
            TestAddLoan.member_id=jsonpath.jsonpath(res,'$..id')[0]
            # 获取token类型
            token_type=jsonpath.jsonpath(res,'$..token_type')[0]
            # 获取token值
            token=jsonpath.jsonpath(res,'$..token')[0]
            TestAddLoan.token_data=token_type+' '+token

        # 断言
        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
            if res['msg'] == 'ok':
                sql = 'select * from futureloan.loan WHERE member_id={}'.format(self.member_id)
                count = self.db.get_count(sql)
                self.assertEqual(count, 1)
        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info("用例:{}--->执行未通过".format(case["title"]))
            my_logger.error(e)
            print("预取结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info("用例:{}--->执行已通过".format(case["title"]))
Beispiel #7
0
    def test_invest(self, case):
        # 1、准备用例数据
        url = conf.get('env', 'url') + case['url']
        method = case['method']
        case['data'] = replace_data(case['data'])
        data = eval(case['data'])
        headers = eval(conf.get('env', 'header'))
        if case['interface'] != 'login':
            headers['Authorization'] = getattr(TestData, 'token_data')
        expected = eval(case['expected'])
        row = case['case_id'] + 1

        # 2、发送请求
        response = self.http.send(url=url,
                                  method=method,
                                  json=data,
                                  headers=headers)
        res = response.json()

        if case['interface'] == 'login':
            # 提取member_id和token
            member_id = jsonpath.jsonpath(res, '$..id')[0]
            setattr(TestData, 'member_id', str(member_id))

            token_type = jsonpath.jsonpath(res, '$..token_type')[0]
            token = jsonpath.jsonpath(res, '$..token')[0]
            token_data = token_type + ' ' + token
            setattr(TestData, 'token_data', token_data)

        elif case['interface'] == 'add':
            loan_id = jsonpath.jsonpath(res, '$..id')[0]
            setattr(TestData, 'loan_id', str(loan_id))

        # 3、断言
        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info('用例:{}--->执行未通过'.format(case['title']))
            my_logger.error(e)
            print("预取结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info('用例:{}--->执行已通过'.format(case['title']))
Beispiel #8
0
    def test_recharge(self, case):
        case['data'] = replace_data(case['data'])
        data = eval(case['data'])
        expected = eval(case['expected'])
        row = case['case_id'] + 1
        url = case['url']
        recharge_url = base_url + url
        method = case['method']
        header = eval(conf.get('env', 'header'))
        header['Authorization'] = getattr(TestData, 'token_data')

        # 请求之前数据库看一下当前用户有多少钱
        # 请求后数据库看一下当前用户有多少钱
        # 然后比对增加的钱和用例中的钱
        if case['check_sql']:
            sql = case['check_sql'].format(conf.get('login_data', 'phone'))
            before_amount = self.db.get_one(sql)[0]

        response = self.rest.send(url=recharge_url,
                                  method=method,
                                  json=data,
                                  headers=header)
        res = response.json()
        leave_amount = jsonpath.jsonpath(res, '$..leave_amount')
        try:
            self.assertEqual(expected['code'], res['code'])
            self.assertEqual(expected['msg'], res['msg'])
            if case['check_sql']:
                sql = case['check_sql'].format(conf.get('login_data', 'phone'))
                after_amount = self.db.get_one(sql)[0]
                expected_amount = eval(case['data'])['amount']
                self.assertEqual(decimal.Decimal(str(expected_amount)),
                                 (after_amount - before_amount))
                my_logger.info('充值之前金额为:{}\n,充值金额为:{}\n,充值后金额为:{}'.format(
                    before_amount, expected_amount, after_amount))
        except AssertionError as e:
            self.excel.write_excel(row=row, column=8, value='未通过')
            my_logger.info('用例-->{}:执行未通过'.format(case['title']))
            my_logger.error(e)
            print("预期结果:{}".format(expected))
            print("实际结果:{}".format(res))
            raise e
        else:
            self.excel.write_excel(row=row, column=8, value='已通过')
            my_logger.info('用例-->{}:执行已通过'.format(case['title']))