Пример #1
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)
Пример #2
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)
Пример #3
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)
Пример #4
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)
Пример #5
0
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)
Пример #7
0
class IsExemptPayTestCase(unittest.TestCase):
    '''余额密码支付设置'''
    excel = ReadExcel(os.path.join(DATA_DIR, 'api_user.xlsx'), 'is_exempt_pay')
    cases = excel.read_data_obj()
    http = HttpRequest()
    data_res = GetUseridToken()
    data_register = data_res.random_register_data()
    com = Common()


    @classmethod
    def setUpClass(cls):
        data_modify_pwd = Md5().sign(cls.data_register)
        res_register = cls.http.requests(method='post', url=apiURL+'/users/register', data=data_modify_pwd)
        print('是否注册成功', res_register.json())


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

        data_1 = eval(myconf.get('data', 'data_login'))
        if status == 'no':
            username = self.data_register.get('username')
            password = self.data_register.get('password')
            data_3 = {'username': username, 'password': password}
            print(data_3)

            get_data = self.data_res.get_userid_token(data_3)
            case.data = case.data.replace(eval(case.data).get('user_id'), get_data.get('user_id'))
            case.data = case.data.replace(eval(case.data).get('token'), get_data.get('token'))

        else:
            get_data = self.data_res.get_userid_token(data_1)
            case.data = case.data.replace(eval(case.data).get('user_id'), get_data.get('user_id'))
            case.data = case.data.replace(eval(case.data).get('token'), get_data.get('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)
        print('返回的数据是:', response.json())
        res = response.json().get('msg')
        print('接口请求返回的结果为:', res, type(res))
        print('--------期望结果为:', excepted, type(excepted))

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

    def tearDown(self):
        # data_1 = {'username': '******', 'password': '******'}
        data = {'user_id': '*userid*', 'token': '*token*', 'password': '******', 'new_password': '******',
                'password_two': '123456'}
        url = apiURL + '/users/pay_password'
        # data_modify_pwd = Md5().sign(data_1)
        # res = self.http.requests(method='post', url=apiURL+'/users/login', data=data_modify_pwd)
        # resdata = res.json().get('data')
        # data.update({'user_id': resdata.get('user_id'), 'token': resdata.get('token')})
        user_data = self.com.login()
        data.update(user_data)
        data_ = Md5().sign(data)
        response = self.http.requests(method='post', url=url, data=data_)
        print('------修改支付密码------', response.json())