def test_case_del_user_relation(self, case):
     data_list = {'user_id': '*userid*', 'token': '*token*'}
     url = apiURL + case.url
     method = case.method
     excepted = eval(case.excepted)
     row = case.case_id + 1
     title = case.title
     data_1 = eval(myconf.get('data', 'data_login'))
     data_modify_pwd = Md5().sign(data_1)
     res = self.http.requests(method=method, url=apiURL + '/users/login', data=data_modify_pwd)
     data_ = res.json().get('data')
     try:
         data_.get('token') and data_.get('user_id')
     except AttributeError as e:
         print('\033[31m访问登录接口失败,未能获取到userid和token!!')
         log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
         raise e
     else:
         # 获取userid
         user_token = data_.get('token')
         # 获取token
         user_id = data_.get('user_id')
     # 获取关联列表,查询relationid,将测试数据中的relationid替换为查询到的id
     data_list['user_id'] = user_id
     data_list['token'] = user_token
     url2 = apiURL + '/users/relation_list'
     res_l = self.http.requests(method='post', url=url2, data=Md5().sign(data_list))
     res_list = res_l.json().get('data')
     rel_id = res_list[0].get('relation_id')
     print('获取到的relationid为', rel_id)
     rela_id = eval(case.data).get('relation_id')
     if '*' in rela_id:
         case.data = case.data.replace(rela_id, str(rel_id))
Esempio n. 2
0
    def test_case_oauth_unbind(self, case):
        data_on = {
            'user_id': '*userid*',
            'token': '*token*',
            'type': '2',
            'openid': '2',
            'nick_name': '测试',
            'head_img': 'ganm.png'
        }
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)
Esempio n. 3
0
    def test_register(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备测试数据,替换动态参数
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)

        # 第二步:发送请求到接口,获取实际结果
        res_code = self.request.http_request(method=case.method,
                                             url=self.url + case.url,
                                             data=eval(case.data)).json()

        # 第三步:比对预期结果和实际结果,断言用例是否通过
        try:
            if case.check_sql:
                case.check_sql = case.check_sql.replace("*phone*", phone)
                count = self.mysql.find_count(case.check_sql)
                log.info(f"注册后数据库期望数据条数:1,注册后数据库实际数据条数:{count}")
                self.assertEqual(1, count)
            log.info(f"请求期望返回码:{eval(case.expected)},请求实际返回码:{res_code}")
            self.assertEqual(eval(case.expected), res_code)
Esempio n. 4
0
    def test_case_audit(self, case):
        """审核接口用例执行的逻辑"""
        #准备测试用例
        url = myconf.get('url', 'url') + case.url  # 拼接完整的URL地址
        row = case.case_id + 1
        # 替换用例参数
        case.data = replace(case.data)

        # 判断是否有*memberId*的参数需要替换
        if "*loan_id*" in case.data:
            max_id = self.db.find_one("select max(id) from loan")[
                0]  # findone()返回的是元组,要加下标才能获取到元素
            loan_id = max_id + 1  # 在数据库中查找到最大的id号,加1后替换给*memberId*
            case.data = case.data.replace("*loan_id*", str(loan_id))

        #发送请求到接口,获取结果
        log.info("正在请求地址{}".format(url))
        response = self.http.request(method=case.method,
                                     url=url,
                                     data=eval(case.data))
        res = response.json()
        print(res)

        #判断是否是执行的加标用例
        if case.interface == "加标":
            loan_id = self.db.find_one(
                "select id from loan where memberId ='{}' order by id desc".
                format(myconf.get("data", "memberId")))[0]
            #"SELECT Id FROM loan WHERE MemberId='{}' ORDER BY id DESC".format(myconf.get('data', 'memberId')))
            # 将添加的标id,保存为临时变量
            setattr(ConText, 'loan_id', loan_id)  #对象(类)属性名 属性值
Esempio n. 5
0
    def test_case_relation_list(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted).get('msg')
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)
Esempio n. 6
0
    def test_recharge(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备测试数据,替换动态参数
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)
        if "*amount*" in case.data:
            # 充值金额不足时,需要先获取库中的值
            sql = f"select LeaveAmount from member where MobilePhone = '{eval(case.data)['mobilephone']}'"
            money = float(self.mysql.find_one(sql)[0])
            case.data = case.data.replace("*amount*", str(money + 1000))

        # 未登录时取现/充值,没有返回码
        if case.expected_code:
            expected_code = str(case.expected_code)
        else:
            expected_code = None

        # 数据库校验
        if case.check_sql:
            case.check_sql = sub_conf(case.check_sql)
            old_money = float(self.mysql.find_one(case.check_sql)[0])
Esempio n. 7
0
    def test_bidloan(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备用例数据
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)
        if "*memberId*" in case.data:
            # 想要用户id不存在,先找到最大用户id,加1即可
            member_id = self.mysql.find_one(
                "select max(id) as memberId from member")[0]
            case.data = case.data.replace("*memberId*", str(member_id + 1))
        if "*loanId*" in case.data:
            # 想要项目id不存在,先找到最大项目id,加1即可
            loan_id = self.mysql.find_one(
                "select max(id) as loanId from loan")[0]
            case.data = case.data.replace("*loanId*", str(loan_id + 1))
        if "*amount*" in case.data:
            # 想要可投金额不足,先找到可投金额的最大值,加大值即可
            sql = f"select Amount from loan where Id = {eval(case.data)['loanId']}"
            case.data = case.data.replace(
                "*amount*", str(self.mysql.find_one(sql)[0] + 1000))

        # 未登录时投资竞标,没有返回码
        if case.expected_code:
            case.expected_code = str(case.expected_code)
Esempio n. 8
0
class AuditTestCase(unittest.TestCase):
    """加标接口"""
    excel = ReadExcel(data_file_path, 'audit')
    cases = excel.read_data_obj()
    http = HTTPSession()
    db = ReadSQL()

    @data(*cases)
    def test_audit(self, case):
        # 第一步:准备用例数据
        # 拼接接口路径
        case.url = myconf.get('url', 'url') + case.url
        # 替换用例参数
        case.data = data_replace(case.data)

        # 判断是否有*load_id* 的参数要替换
        if "*loan_id*" in case.data:
            max_id = self.db.find_one("SELECT max(id) FROM loan")[0]
            loan_id = max_id + 1
            case.data = case.data.replace("*loan_id*", str(loan_id))

        # 第二步 发送请求,获取结果
        response = self.http.request(method=case.method,
                                     url=case.url,
                                     data=eval(case.data))
        res = response.json()
        res_code = res['code']

        # 判断是否是执行的加标用例,
        if case.interface == "加标":
            loan_id = self.db.find_one(
                "SELECT Id FROM loan WHERE MemberId='{}' ORDER BY id DESC".
                format(myconf.get('data', 'memberId')))
            # 将添加的标id,保存为临时变量
            setattr(ConText, 'loan_id', loan_id[0])
Esempio n. 9
0
class RemoveCart(unittest.TestCase):
    '''删除购物车'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'jc_api.xlsx'), 'remove_cart')
    cases = excel.read_data_obj()
    http = HttpRequest()

    @data(*cases)
    def test_case_remove_cart(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted).get('msg')
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method, url=myconf.get('url', 'url3'), data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')
        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
class QueryPointResultTestCase(unittest.TestCase):
    """try积分接口"""
    excel = ReadExcel(data_file_path, 'queryPointResult')
    cases = excel.read_data_obj()
    http = HTTPRequest()
    db = ReadSQL()

    @data(*cases)
    def test_case_pointpark(self, case):
        # 准备测试用例数据
        url = case.url
        # data = eval(case.data)
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        headers = eval(case.headers)

        # 处理case用例里需要替换的uid参数
        if "#uid#" in case.data:
            case.data = data_replace(case.data)

        # 处理case用例里需要替换的serialNo参数
        serialNo = self.random_serialNo()
        if "*serialNo*" in case.data:
            case.data = case.data.replace("*serialNo*", serialNo)
Esempio n. 11
0
class GoodCollectCancelTestCase(unittest.TestCase):
    '''取消商品收藏'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'),
                      'goods_collect_cancel')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()

    @data(*cases)
    def test_case_goods_collect_cancel(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/login',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        data_coll = {
            'user_id': '*userid*',
            'token': '*token*',
            'page': '1',
            'pageSize': '10'
        }
        userdata = self.com.login()
        data_coll.update(userdata)
        data_modify_pwd = Md5().sign(data_coll)
        res = self.http.requests(method='post',
                                 url=apiURL + '/users/goods_collect_list',
                                 data=data_modify_pwd)
        # print('________', res.json())
        collect_data = res.json().get('data')
        collect_list = collect_data.get('collect_list')
        goodsid = []
        for i in collect_list:
            goodsid.append(i.get('goods_id'))
        # print('00000000', goodsid)
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')
        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
Esempio n. 12
0
 def test_case_goods_collect_cancel(self, case):
     url = apiURL + case.url
     method = case.method
     excepted = eval(case.excepted)
     row = case.case_id + 1
     title = case.title
     data_1 = eval(myconf.get('data', 'data_login'))
     data_modify_pwd = Md5().sign(data_1)
     res = self.http.requests(method=method,
                              url=apiURL + '/users/login',
                              data=data_modify_pwd)
     data_ = res.json().get('data')
     data_coll = {
         'user_id': '*userid*',
         'token': '*token*',
         'page': '1',
         'pageSize': '10'
     }
     userdata = self.com.login()
     data_coll.update(userdata)
     data_modify_pwd = Md5().sign(data_coll)
     res = self.http.requests(method='post',
                              url=apiURL + '/users/goods_collect_list',
                              data=data_modify_pwd)
     # print('________', res.json())
     collect_data = res.json().get('data')
     collect_list = collect_data.get('collect_list')
     goodsid = []
     for i in collect_list:
         goodsid.append(i.get('goods_id'))
     # print('00000000', goodsid)
     try:
         data_.get('token') and data_.get('user_id')
     except AttributeError as e:
         print('\033[31m访问登录接口失败,未能获取到userid和token!!')
         log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
         raise e
     else:
         # 获取userid
         user_token = data_.get('token')
         # 获取token
         user_id = data_.get('user_id')
     user1 = eval(case.data).get('user_id')
     if '*' in user1:
         case.data = case.data.replace(user1, user_id)
Esempio n. 13
0
class OauthUnbindTestCase(unittest.TestCase):
    '''平台解绑'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'), 'oauth_unbind')
    cases = excel.read_data_obj()
    http = HttpRequest()

    def setUp(self):
        data_on = {
            'user_id': '*userid*',
            'token': '*token*',
            'type': '2',
            'openid': '2',
            'nick_name': '测试',
            'head_img': 'ganm.png'
        }

    @data(*cases)
    def test_case_oauth_unbind(self, case):
        data_on = {
            'user_id': '*userid*',
            'token': '*token*',
            'type': '2',
            'openid': '2',
            'nick_name': '测试',
            'head_img': 'ganm.png'
        }
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
Esempio n. 14
0
    def test_add(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备用例数据
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)
        if "*memberId*" in case.data:
            # 想要用户id不存在,先找到最大用户id,加1即可
            member_id = self.mysql.find_one(
                "select max(id) as memberId from member")[0]
            case.data = case.data.replace("*memberId*", str(member_id + 1))

        # 未登录时新增项目,没有返回码
        if case.expected_code:
            case.expected_code = str(case.expected_code)
Esempio n. 15
0
    def test_audit(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备用例数据
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)
        if "*loanId*" in case.data:
            # 想要项目id不存在,先找到最大项目id,加1即可
            loan_id = self.mysql.find_one(
                "select max(id) as loanId from loan")[0]
            case.data = case.data.replace("*loanId*", str(loan_id + 1))

        # 未登录时审核,没有返回码
        if case.expected_code:
            case.expected_code = str(case.expected_code)
Esempio n. 16
0
 def test_case_add(self, case):
     """加标接口用例执行的逻辑"""
     #准备测试用例
     url = myconf.get('url', 'url') + case.url  # 拼接完整的URL地址
     row = case.case_id + 1
     # 替换用例参数
     case.data = replace(case.data)
     #判断是否有*memberId*的参数需要替换
     if "*memberId*" in case.data:
         max_id = self.db.find_one("select max(id) from member")[
             0]  #findone()返回的是元组,要加下标才能获取到元素
         memberid = max_id + 1  #在数据库中查找到最大的id号,加1后替换给*memberId*
         case.data = case.data.replace(
             "*memberId*", str(memberid))  #字符串替换的方法,要记得转换类型为str,否则会报错
     #判断是否需要SQL校验
     if case.check_sql:  #如果case文件里的check_sql有数据,就做替换。
         case.check_sql = replace(
             case.check_sql)  #调用封装好的替换类,把其中含有“#memberId#"的替换为从配置文件中获取的值
         # 获取当前用户加标前的标数量
         start_count = self.db.find_count(case.check_sql)
    def test_case_pointpark(self, case):
        # 准备测试用例数据
        url = case.url
        # data = eval(case.data)
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        headers = eval(case.headers)

        # 处理case用例里需要替换的uid参数
        # if '#uid#' in case.data:
        #     case.data = data_replace(case.data)

        # 处理case用例里需要替换的serialNo参数
        serialNo = self.random_serialNo()

        if '*serialNo*' in case.data:
            case.data = case.data.replace('*serialNo*', serialNo)

            return case.data
Esempio n. 18
0
class DelSearchLogTestCase(unittest.TestCase):
    '''删除搜索记录'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'),
                      'del_search_log')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()

    @data(*cases)
    def test_case_del_search_log(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/login',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        data_s = eval(myconf.get('data', 'data_com'))
        data_user = self.com.login()
        data_s.update(data_user)
        data_modify_pwd = Md5().sign(data_s)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/search_history',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        searchid = []
        for i in data_:
            searchid.append(i.get('id'))
        print(searchid)

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
Esempio n. 19
0
    def test_case_register(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        # 用户名替换
        name1 = eval(case.data).get('username')
        if '*' in name1:
            name_rad = random_res(name1)
            case.data = case.data.replace(name1, name_rad)

        # 密码替换
        pwd1 = eval(case.data).get('password')
        if '*' in pwd1:
            pwd_rad = random_res(pwd1)
            case.data = case.data.replace(pwd1, pwd_rad)
        # 企业替换
        ent = eval(case.data).get('enterprise')
        if '*' in ent:
            ent_rad = random_res(ent)
            case.data = case.data.replace(ent, ent_rad)

        # 手机号码替换
        tel = eval(case.data).get('tel')
        if '*' in tel:
            tel_rad = random_res(tel)
            case.data = case.data.replace(tel, tel_rad)
        print('最后请求传入的数据:', case.data)

        data_1 = eval(case.data)
        data = Md5().sign(data_1)
        log.info('正在请求地址{}'.format(url))
        response = self.http.requests(method=method, url=url, data=data)
        res = response.json()
        print('接口请求返回的结果为:', res)
        print('期望结果为:', excepted)

        try:
            self.assertEqual(excepted, res)
        except AssertionError as e:
            # 测试用例没通过
            self.excel.write_data(row=row, column=8, value='未通过')
            log.debug('该条用例未通过{}'.format(title))
            raise e

        else:
            # 获取行
            self.excel.write_data(row=row, column=8, value='通过')
            log.debug('该条用例通过{}'.format(title))
    def test_case_register(self, case):
        """登注册接口用例执行的逻辑"""
        #准备测试用例
        url = myconf.get('url', 'url') + case.url  # 拼接完整的URL地址
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        # 替换用例参数
        case.data = replace(case.data)
        #随机生成手机号码
        phone = self.random_phone()
        print(phone)
        #替换动态化的参数,字符串替换方法
        case.data = case.data.replace("*phone*",
                                      phone)  #加星号是为了避免替换掉其他的同名字符,如mobilephone
        #发送请求到接口,获取结果
        log.info("正在请求地址{}".format(url))
        response = self.http.request(method=method,
                                     url=url,
                                     data=eval(case.data))
        res = response.json()

        #对比预期结果
        try:
            self.assertEqual(excepted, res)
            # 判断是否需要进行SQL校验
            if case.check_sql:  # 如果此字段有数据,条件成立
                # 用随机生成的手机号替换需要校验的SQL语句中的手机号
                case.check_sql = case.check_sql.replace('*phone*', phone)
                db_res = self.db.find_count(case.check_sql)
                self.assertEqual(1, db_res)
        except AssertionError as e:
            """测试用例未通过"""
            self.excel.write_data(row, 8, '未通过')
            log.info("{},该条用例执行未通过".format(case.title))
            log.exception(e)
            raise e
        else:
            self.excel.write_data(row, 8, '通过')
            log.info("{},该条用例执行通过".format(case.title))
Esempio n. 21
0
    def test_case_del_search_log(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/login',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        data_s = eval(myconf.get('data', 'data_com'))
        data_user = self.com.login()
        data_s.update(data_user)
        data_modify_pwd = Md5().sign(data_s)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/search_history',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        searchid = []
        for i in data_:
            searchid.append(i.get('id'))
        print(searchid)

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)
Esempio n. 22
0
class CreateOrderTestCase(unittest.TestCase):
    '''创建订单'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_order.xlsx'), 'create_order')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()
    com.append_cart()
    # 获取购物车id
    cartid = com.cart_id_list()[0]
    cartids = com.cart_id_list()[1:3]
    print('__________', cartids)

    @data(*cases)
    def test_case_create_order(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted).get('msg')
        row = case.case_id + 1
        title = case.title

        data_2 = myconf.get('data', 'data_build_ordre')
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')
        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
Esempio n. 23
0
class GoodCollectTestCase(unittest.TestCase):
    '''商品收藏'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'), 'goods_collect')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()
    goodid = com.get_goods_list()[0]
    getgoods = com.get_goods_list()[2:4]
    goodsid = ','.join(str(i) for i in getgoods)
    print(goodid, goodsid)

    @data(*cases)
    def test_case_goods_collect(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted).get('msg')
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
class OrderPayStatusTestCase(unittest.TestCase):
    '''订单支付状态验证'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_order.xlsx'),
                      'order_pay_status')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()
    ordernotpay = com.notpay_order_num()
    orderpay = com.order_list_id(3)[0]

    @data(*cases)
    def test_case_order_pay_status(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=myconf.get('url', 'url3'),
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_id = data_.get('user_id')
            # 获取token
            user_token = data_.get('token')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
class RreditOrderDetailTestCase(unittest.TestCase):
    '''资信订单详情'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_order.xlsx'),
                      'credit_order_detail')
    cases = excel.read_data_obj()
    http = HttpRequest()
    com = Common()
    order_num = com.credit_ordre()

    @data(*cases)
    def test_case_credit_order_detail(self, case):
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method,
                                 url=apiURL + '/users/login',
                                 data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_id = data_.get('user_id')
            # 获取token
            user_token = data_.get('token')

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
class StraightSendPrizeTestCase(unittest.TestCase):
    """try积分接口"""
    excel = ReadExcel(data_file_path, 'straightSendPrize')
    cases = excel.read_data_obj()
    http = HTTPRequest()

    def random_serialNo(self):
        '''随机生成serialNo'''
        while True:
            serialNo = "13"
            for i in range(9):
                num = random.randint(1, 9)
                serialNo += str(num)

            # 数据库查询serialNo是否存在
            sql = "SELECT * FROM pointpark.point_activity_info where serialNo='{}'".format(
                serialNo)
            if not self.db.find_count(sql):
                return serialNo

    @data(*cases)
    def test_case_pointpark(self, case):
        # 准备测试用例数据
        url = case.url
        # data = eval(case.data)
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        headers = eval(case.headers)
        # 处理case用例里需要替换的uid参数
        if "#uid#" in case.data:
            case.data = data_replace(case.data)

        # 处理case用例里需要替换的serialNo参数
        serialNo = self.random_serialNo()
        if "*serialNo*" in case.data:
            case.data = case.data.replace("*serialNo*", serialNo)
Esempio n. 27
0
    def test_getList(self, case):
        log.info(f"验证接口:{case.interface},接口url:{case.url}")
        # 第一步:准备测试数据,替换动态参数
        # 替换配置文件中的固定参数
        case.data = sub_conf(case.data)
        # 替换动态生成的参数
        if "*phone*" in case.data:
            # 注册时,手机号码为动态注册的号码
            phone = random_phone()
            case.data = case.data.replace("*phone*", phone)
        if "*memberId*" in case.data:
            # 想要用户id不存在,先找到最大用户id,加1即可
            member_id = self.mysql.find_one("select max(id) from member")[0]
            case.data = case.data.replace("*memberId*", str(member_id + 100))
        if "*loanId*" in case.data:
            # 想要项目id不存在,先找到最大项目id,加1即可
            loan_id = self.mysql.find_one("select max(id) from loan")[0]
            case.data = case.data.replace("*loanId*", str(loan_id + 100))

        if case.check_sql:
            # 生成回款计划前查找数据条数
            case.check_sql = sub_conf(case.check_sql)
            old_conut = self.mysql.find_count(case.check_sql)
class DelUserRalationTestCase(unittest.TestCase):
    '''删除关联用户'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'), 'del_user_relation')
    cases = excel.read_data_obj()
    http = HttpRequest()

    def setUp(self):
        data_on = {'user_id': '*userid*', 'token': '*token*', 'relation_user_id': '21625'}
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method='post', url=apiURL + '/users/login', data=data_modify_pwd)
        data_ = res.json().get('data')
        user_token = data_.get('token')
        user_id = data_.get('user_id')
        data_on['user_id'] = user_id
        data_on['token'] = user_token
        url2 = apiURL + '/users/user_relation'
        res_on = self.http.requests(method='post', url=url2, data=Md5().sign(data_on))
        print(res_on.json())
        print('------------最先执行-------')



    @data(*cases)
    def test_case_del_user_relation(self, case):
        data_list = {'user_id': '*userid*', 'token': '*token*'}
        url = apiURL + case.url
        method = case.method
        excepted = eval(case.excepted)
        row = case.case_id + 1
        title = case.title
        data_1 = eval(myconf.get('data', 'data_login'))
        data_modify_pwd = Md5().sign(data_1)
        res = self.http.requests(method=method, url=apiURL + '/users/login', data=data_modify_pwd)
        data_ = res.json().get('data')
        try:
            data_.get('token') and data_.get('user_id')
        except AttributeError as e:
            print('\033[31m访问登录接口失败,未能获取到userid和token!!')
            log.debug('访问获取userid和token的登录接口失败,未能获取到userid和token')
            raise e
        else:
            # 获取userid
            user_token = data_.get('token')
            # 获取token
            user_id = data_.get('user_id')
        # 获取关联列表,查询relationid,将测试数据中的relationid替换为查询到的id
        data_list['user_id'] = user_id
        data_list['token'] = user_token
        url2 = apiURL + '/users/relation_list'
        res_l = self.http.requests(method='post', url=url2, data=Md5().sign(data_list))
        res_list = res_l.json().get('data')
        rel_id = res_list[0].get('relation_id')
        print('获取到的relationid为', rel_id)
        rela_id = eval(case.data).get('relation_id')
        if '*' in rela_id:
            case.data = case.data.replace(rela_id, str(rel_id))

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)
        url2 = apiURL + '/users/relation_list'
        res_l = self.http.requests(method='post', url=url2, data=Md5().sign(data_list))
        res_list = res_l.json().get('data')
        rel_id = res_list[0].get('relation_id')
        print('获取到的relationid为', rel_id)
        rela_id = eval(case.data).get('relation_id')
        if '*' in rela_id:
            case.data = case.data.replace(rela_id, str(rel_id))

        user1 = eval(case.data).get('user_id')
        if '*' in user1:
            case.data = case.data.replace(user1, user_id)

        token1 = eval(case.data).get('token')
        if '*' in token1:
            case.data = case.data.replace(token1, user_token)
        data_2 = eval(case.data)
        data = Md5().sign(data_2)
        print('传入的数据为:', data)
        log.info('正在请求地址{}'.format(url))
        response = self.http.requests(method=method, url=url, data=data)
        res = response.json()
        print('接口请求返回的结果为:', res, type(res))
        print('--------期望结果为:', excepted, type(excepted))

        try:
            self.assertEqual(excepted, res)
        except AssertionError as e:
            self.excel.write_data(row=row, column=8, value='未通过')
            log.debug('该条用例未通过{}'.format(title))
            raise e