def test_008(self): '''加入购物车后-商品已售罄(未下架)--新增数量''' #a、查看可以添加到购物车的商品 token = MyMethod().readToken(path) goodIdListCode = Shopping().GouWuChe_add(token) self.logger.info('goodIdListCode商品列表为:%s' % goodIdListCode) #这里可能需要修改一下数据库商品库存,暂未修改 id=str(goodIdListCode[0]) dict=H5Method().Excel_Dict('H5商城','首页',10,4,3,2) #商品加入购物车 dict['headers']['token']=token[-1] dict['data']['goodId']=id H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data']))###商品加入购物车 self.logger.info('分销商商品id为:%s,已加入购物车'%id) #根据商品id找到购物车商品id GouWuCheId=Shopping().categoryIdMethod(id) self.logger.info('根据分销商商品id,获取加入购物车后的购物车id为:%s'%GouWuCheId) dict=H5Method().Excel_Dict('H5商城','购物车',8,4,3,2,) dict['headers']['token']=token[-1] dict['data']['id']=GouWuCheId H5Method().updateSQl(id,455454,3) #修改商品库存为0,商品状态为“上架中” response=H5Method().Post_H5(dict['url'],dict['headers'],json.dumps(dict['data'])) H5Method().updateSQl(id,445464, 1) # 修改商品库存为0,商品状态为“上架中” self.logger.info('分销商商品id为:%s的商品,增加商品数量'%id) Shopping().GouWuChe_delete(GouWuCheId, token[-1]) self.assertEqual(eval(table.cell(8,8).value)['msg'],response.json()['msg'],msg='添加购物车商品数量成功')
def test_002(self): '''购买0件商品,确认订单''' goodsId = Shopping().GouWuChe_add(self.token) # goodsId为商品id列表,len()之后为2 goodId = goodsId[0] self.logger.info('确认订单页面的id为:%s' % goodId) dict = H5Method().Excel_Dict('H5商城', '确认订单', 2, 4, 3, 2) dict['headers']['token'] = self.token dict['headers']['Referer'] = dict['headers']['Referer'] + str(goodId) dict['data']['goodsId'] = goodId # 购买请求商品id 购买请求商品数量默认为1 response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) self.logger.info('返回内容为:\n%s' % response.json()) self.assertEqual(eval(table.cell(2, 8).value)['msg'], response.json()['msg'], msg='跳转确认订单页面未成功') # 断言是否成功
def test_005(self): '''购物车多个商品删除''' #先添加两个个商品到购物车 token=MyMethod().readToken(path) goodIdListCode=Shopping().GouWuChe_add(token) self.logger.info('goodIdListCode商品列表为:%s'%goodIdListCode) for goodId in goodIdListCode: #添加两个商品加入购物车 dict=H5Method().Excel_Dict('H5商城','首页',10,4,3,2) dict['headers']['token']=token[-1] dict['data']['goodId']=str(goodId) H5Method().Post_H5(dict['url'],dict['headers'],json.dumps(dict['data'])) dict=H5Method().Excel_Dict('H5商城','购物车',5,4,3,2) dict['headers']['token']=token[-1] for id in goodIdListCode: #分销商商品表id #根据分销商商品id找到,购物车商品id print(id) id=Shopping().categoryIdMethod(id) self.logger.info('购物车商品id为:%s'%id) dict['data']['id']=id # dict['data'].pop('shopId') response=H5Method().Post_H5(dict['url'],dict['headers'],json.dumps(dict['data'])) print(response.json()) self.assertEqual(eval(table.cell(5,8).value)['msg'],response.json()['msg'],msg='删除购物车内容不成功')
def test_005(self): goodsId = Shopping().GouWuChe_add(self.token) # goodsId为商品id列表,len()之后为2 goodId = goodsId[0] self.logger.info('确认订单页面的id为:%s' % goodId) dict = H5Method().Excel_Dict('H5商城', '确认订单', 5, 4, 3, 2) dict['headers']['token'] = self.token dict['headers']['Referer'] = dict['headers']['Referer'] + str(goodId) dict['data']['goodsId'] = goodId # 购买请求商品id 购买请求商品数量默认为1 H5Method().updateSQl(goodId, 1, 1) # 修改商品库存以及状态 response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) H5Method().updateSQl(goodId, 4546545, 1) # 还原商品库存以及状态 self.logger.info('返回内容为:\n%s' % response.json()) # self.assertEqual(eval(table.cell(2, 8).value)['msg'], response.json()['msg'], msg='跳转确认订单页面未成功') # 断言是否成功 self.assertEqual(eval(table.cell(5, 8).value), response.json(), msg='购买数量大于库存数量,该接口判断异常')
def test_001(self): '''查看状态和库存正常的商品''' productIdList = Shopping().GouWuChe_add(self.token) productId = productIdList[0] self.logger.info('获取的分销商商品id为:%s' % productId) dict = H5Method().Excel_Dict('H5商城', '商品详情', 1, 4, 3, 2) dict['headers']['token'] = self.token dict['data']['goodsId'] = productId response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) self.logger.info('获取的商品id为:%s,获取的商品状态为:%s' % (productId, response.json()['data']['status'])) self.assertEqual(ProductDetails().productParam(productId)[0], response.json()['data']['goodsTitle'], msg='返回商品名称不正确') self.assertEqual(ProductDetails().productParam(productId)[1], response.json()['data']['status'], msg='返回的商品状态不正确') self.logger.info('获取商品状态为:1---上架中')
def test_007(self): '''购买一件商品,可选优惠券列表''' goodsId = Shopping().GouWuChe_add(self.token) # goodsId为商品id列表,len()之后为2 self.logger.info('确认订单页面的商品id为:%s' % goodsId) dict = H5Method().Excel_Dict('H5商城', '确认订单',7,4,3,2) dict['headers']['token'] = self.token products=dict['data']['products'] for a in goodsId: products.append({"buyCount":1,"goodsId":str(a)}) print(products) dict['data']['products'] = products # 购买请求商品id 购买请求商品数量默认为1 self.logger.info('请求参数为:%s'%dict['data']) response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) self.logger.info('返回内容为:\n%s' % response.json()) # self.assertEqual(eval(table.cell(2, 8).value)['msg'], response.json()['msg'], msg='跳转确认订单页面未成功') # 断言是否成功 self.assertEqual(eval(table.cell(7, 8).value)['msg'], response.json()['msg'], msg='购买数量大于库存数量,该接口判断异常') self.assertEqual(eval(table.cell(7, 8).value)['statusCode'], response.json()['statusCode'], msg='购买数量大于库存数量,该接口判断异常')
def test_002(self): '''库存已售罄查看商品详情''' productIdList = Shopping().GouWuChe_add(self.token) productId = productIdList[0] self.logger.info('获取的分销商商品id为:%s' % productId) dict = H5Method().Excel_Dict('H5商城', '商品详情', 2, 4, 3, 2) dict['headers']['token'] = self.token dict['data']['goodsId'] = productId H5Method().updateSQl(productId, 0, 2) # 根据分销商商品id修改一下商品库存 response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) self.logger.info('获取的商品id为:%s,获取的商品状态为:%s' % (productId, response.json()['data']['status'])) self.assertEqual(ProductDetails().productParam(productId)[0], response.json()['data']['goodsTitle'], msg='返回商品名称不正确') self.assertEqual(ProductDetails().productParam(productId)[1], response.json()['data']['status'], msg='返回的商品状态不正确') self.logger.info('获取商品状态为:2---已售罄') H5Method().updateSQl(productId, 456455, 1) # 还原分销商商品库存和状态
def test_001(self): '''购物车列表请求''' token=MyMethod().readToken(path) dict=H5Method().Excel_Dict('H5商城','购物车',1,4,3,2) dict['headers']['token']=token[-1] response=H5Method().Get_H5(dict['url'],dict['headers'],json.dumps(dict['data'])) self.logger.info('购物车列表请求返回内容:%s'%response.json()) self.assertEqual(eval(table.cell(1,8).value)['msg'],response.json()['msg'],msg='购物车列表请求未成功') #判断购物车返回数量 body=eval(H5Method().token_code(token[-1])) #解析toke json格式取出字典 self.logger.info('解析token得到:%s'%body) user_id=body['user']['id'] #根据解析的token获取到user_id return_list=Shopping().GouWuChe_number(user_id) self.logger.info('获取购物车商品数量列表:%s'%str(return_list)) if len(return_list)==0: db_number=0 self.logger.info('购物车商品数量为:0') else: db_number=return_list[-1][-1] #数据库该用户购物车商品数量 self.logger.info('购物车商品数量为:%s'%db_number) number=len(response.json()['data']) self.logger.info('接口返回购物车商品数量为:%s'%number) self.assertEqual(db_number,number,msg='数据该用户购物车商品数量与接口返回不一致!')
def test_001(self): '''商品库存充足,提交订单''' #从该店铺任意获取一个商品,并修改其库存,保证其库存充足,没然后提交订单 ID = Shopping().GouWuChe_add(self.token)[0] #ID商品id print(ID) H5Method().updateSQl(ID, 5000, 1) #修改该供应商对应的商品库存
def test_003(self): '''商品加入购物车,验证购物车数量增加以及删除购物车商品''' token=MyMethod().readToken(path) dict=H5Method().Excel_Dict('H5商城','首页',11,4,3,2) #sheet首页,获取接口请求数据 shop_id=dict['data']['mallId'] #获取店铺id dict1 = H5Method().Excel_Dict('H5商城', '购物车', 3, 4, 3, 2) dict1['headers']['token'] = token[-1] # 加入商品到购物车之前 response = H5Method().Get_H5(dict1['url'], dict1['headers'], json.dumps(dict1['data'])) shop_number_old = len(response.json()['data']) self.logger.info('加入购物车之前的商品数量是:%s'%shop_number_old) list_old=response.json()['data'] GouWuCheListShopId=[] for goods_id_dict in list_old: #列表取出原来购物车中已售罄的商品 if goods_id_dict['status']=='1': goods_id=goods_id_dict['goodId'] GouWuCheListShopId.append(goods_id) self.logger.info('原来的购物车中有效商品列表为:%s'%GouWuCheListShopId) al=IfiCation().selectSQL(shop_id) #查询店铺下所有分类id self.logger.info('该店铺下所有的分类列表为:%s'%str(al)) list_id=[] for al_1 in al: # mp=al_1[0] #mp所有的分类id su=IfiCation().SumShopping(mp) #根据分类id找出下面的商品id if len(su)>0: # 根据分类id找出商品数量大于1的分类 for shop_list in su: shop_id_code=shop_list[0] #取出分销商 商品id list_id.append(shop_id_code) self.logger.info('根据分类id找出商品库存大于1的分类为:%s' % list_id) for a in list_id: #将所有的商品id加入到一个list if a=='sum': list_id.remove('sum') print(list_id) for LL in GouWuCheListShopId: #将购物车中已经存在的商品,从可添加的商品id列表剔除 if LL in list_id: list_id.remove(LL) for b in list_id: #判断商品库存是否大于1 stock_number=Shopping().GouWuChe_stock(b)[0][0] if stock_number<=0: list_id.remove(b) print(stock_number) b=random.choice(list_id) self.logger.info('添加的商品id为:%s'%b) dict['data']['goodId']=b #修改添加到购物车的分销商品id dict['headers']['Referer'] = dict['headers']['Referer'] + b dict['headers']['token']=token[-1] H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) # 加入商品到购物车 response=H5Method().Get_H5(dict1['url'],dict1['headers'],json.dumps(dict1['data'])) shop_number_new=len(response.json()['data']) self.logger.info('加入商品到购物车之后,购物车现存商品数量为:%s'%shop_number_new) self.assertEqual(shop_number_old,shop_number_new-1,msg='新加入一个商品进入购物车之后,购物车商品数量没变,加入购物车未成功') #根据商品id获取购物车id GouWuCheShopId=Shopping().categoryIdMethod(b) # MyMethod().selectSQL('select category_id from seller_goods_info where id=%s'%GouWuCheShopId) #删除购物车上 response=Shopping().GouWuChe_delete(GouWuCheShopId,token[-1]) #删除购物车商品成功 print(response.json()) self.logger.info('删除加入购物车的商品,购物车id:%s'%GouWuCheShopId)
def test_009(self): '''购买多件商品,可选择优惠券''' goodsId = Shopping().GouWuChe_add(self.token) # goodsId为商品id列表,len()之后为2 self.logger.info('确认订单页面的id为:%s' % goodsId) dict = H5Method().Excel_Dict('H5商城', '确认订单',7,4,3,2) dict['headers']['token'] = self.token products=dict['data']['products'] classList=[] #商品分类id列表 for a in goodsId: code=ProductDetails().productCoupon(a) classList.append(code) #根据商品id 得出 商品金额 以及商品所属分类id products.append({"buyCount":1,"goodsId":str(a)}) print(products) dict['data']['products'] = products # 购买请求商品id 购买请求商品数量默认为1 self.logger.info('请求参数为:%s'%dict['data']) response = H5Method().Post_H5(dict['url'], dict['headers'], json.dumps(dict['data'])) self.logger.info('返回内容为:\n%s' % response.json()) # self.assertEqual(eval(table.cell(2, 8).value)['msg'], response.json()['msg'], msg='跳转确认订单页面未成功') # 断言是否成功 self.assertEqual(eval(table.cell(7, 8).value)['msg'], response.json()['msg'], msg='购买数量大于库存数量,该接口判断异常') self.assertEqual(eval(table.cell(7, 8).value)['statusCode'], response.json()['statusCode'], msg='购买数量大于库存数量,该接口判断异常') print(ProductDetails.CouponYes('62302675','17700000000')) #获取出该用户所有可用的优惠券列表 listCode=ProductDetails.CouponYes('62302675','17700000000') print(len(listCode)) CouponList=[] #创建优惠券可使用列表 '''以下获取两个商品的可用优惠券列表''' for code in listCode: if code[1]==0: #判断使用门槛 CouponList.append(str(code[0])) if code[1]==1: if code[3]==0: #判断时间 为绝对时间 nowTime = datetime.datetime.now() if code[4]<nowTime or nowTime<code[5] or code[4]==None: #如果优惠券最后使用期限<当前时间或者小于开始时间 pass #则pass if code[4]>=nowTime>=code[5]: #最小时间《当前时间《结束时间 if code[2]>classList[0][0][1]+classList[1][0][1]: pass else: if code[7]==0: #判断使用范围:0,全场商品|all;1,分类商品|category;2,指定商品|appoint', CouponList.append(str(code[0])) ###需求逻辑有问题 ,需要咨询产品 if code[7]==1: #根据分类时,则要求确认订单页面的所有商品都是属于同一分类,则展示该对应的有优惠券 if classList[0][0][0]==classList[1][0][0] and classList[0][0][0]==code[8]: CouponList.append(str(code[0])) else: pass if code[7]==2: ##指定商品id if goodsId[0]==goodsId[1] and goodsId[0]==code[-1]: CouponList.append(str(code[0])) else: pass if code[3]==1: #判断linux时间戳 相对时间 nowTime=int(time.time()) if int(code[6])<nowTime or code[6]==None or code[6]==0: pass if int(code[6])>=nowTime: if code[2] > classList[0][0][1] + classList[1][0][1]: pass else: if code[7]==0: #判断使用范围:0,全场商品|all;1,分类商品|category;2,指定商品|appoint', CouponList.append(str(code[0])) ###需求逻辑有问题 ,需要咨询产品 if code[7]==1: #根据分类时,则要求确认订单页面的所有商品都是属于同一分类,则展示该对应的有优惠券 if classList[0][0][0]==classList[1][0][0] and classList[0][0][0]==code[8]: CouponList.append(str(code[0])) else: pass if code[7]==2: ##指定商品id if goodsId[0]==goodsId[1] and goodsId[0]==code[-1]: CouponList.append(str(code[0])) else: pass self.logger.info('商品id列表为:%s;商品分类id和库存为:%s'%(goodsId,classList)) self.logger.info('可以用的优惠券id列表为:%s'%CouponList) responseIdList=[] for a in response.json()['data']['list']: responseIdList.append(a['couponId']) self.assertEqual(CouponList,responseIdList,msg='返回可使用优惠券不对')