def test_scene02(self): cookie = Common.getcookies(self.user) list_result = SendHttp().sent_get_bycookies(self.listurl, cookie) id_num = int(list_result['result']['total']) id_list = list(range(id_num)) for index in range(len(id_list)): id_list[index] = list_result['result']['list'][index]['id'] self.assertEqual(list_result['code'], 200) para = {"id": id_list[id_num - 1]} del_result = SendHttp().send_post_bycookies(self.delurl, para, cookie) self.assertEqual(del_result['code'], 200) add_para = { "id": "", "receiverName": "测试用户", "cellPhone": "12345678900", "province": "浙江省", "city": "杭州市", "area": "滨江市", "addressDetail": "浙江大学" } add_result = SendHttp().send_post_bycookies(self.addurl, add_para, cookie) self.assertEqual(add_result['code'], 200)
def test_scene2(self): # 登录成功 user = { "phoneArea": "86", "phoneNumber": "200000000044", "password": "******" } result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 新建订单 para = { "receiverName": "张三", "cellPhone": "12345678901", 'addressDetail': "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江区" } SendHttp().sent_post_bycookies(self.NewAddressUrl, Common.getcookies(user), para) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 删除订单 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) aid = address_result['result']['list'][0]['id'] para = {"id": aid} SendHttp().sent_post_bycookies(self.DeleteAddress, Common.getcookies(user), para) self.assertEqual(address_result['code'], 200) self.assertEqual(address_result['message'], 'success')
def test_scene3(self): user = { "phoneArea": "86", "phoneNumber": "200000000033", "password": "******" } delete_id = {"id": "82317363"} newaddress = { "id": "", "receiverName": "杨", "cellPhone": "15226541128", "province": "河北省", "city": "石家庄市", "area": "裕华区", "addressDetail": "新校区" } login_result = SendHttp().run_http(self.login_url, 'POST', user) self.assertEqual(login_result['message'], "success") skulist_result = SendHttp().sent_get(self.skulist_url) self.assertEqual(skulist_result['message'], "success") delete_result = SendHttp().sent_post_bycookies(self.delete_url, Common.getcookies(user), delete_id) self.assertEqual(delete_result['code'], 400) newaddress_result = SendHttp().sent_post_bycookies( self.addAddress_url, Common.getcookies(user), newaddress) self.assertEqual(newaddress_result['code'], 200)
def test_scene3(self): # 登录 user = {"phoneArea": "86", "phoneNumber": "200000000011", "password": "******"} result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 获取所有商品的sku列表 sku_result = SendHttp().run_http(self.Skulisturl, "GET") # 查询获取地址 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) pro = address_result['result']['list'][0]['province'] city = address_result['result']['list'][0]['city'] area = address_result['result']['list'][0]['area'] # 计算运费 addressDetails = address_result['result']['list'][0]['addressDetail'] para = {"id": 1, "addressDetail": addressDetails} SendHttp().run_http(self.TransportFeeUrl, "GET", para) # 提交订单 submit_data = {"skuIds": "1", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": "张三", "cellPhone": "200000000011", "addressDetail": addressDetails, "province": pro, "city": city, "area": area, "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 0, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0} SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user), submit_data)
def test_scene03(self): result = SendHttp().sent_get(self.skuurl) self.assertEqual(result['code'], 200) result = SendHttp().sent_get(self.skuurl + "?goodsId=1") self.assertEqual(result['code'], 200) result = SendHttp().sent_get(self.skuurl + "?goodsId=2") self.assertEqual(result['code'], 200) result = SendHttp().sent_get(self.skuurl + "?goodsId=3") self.assertEqual(result['code'], 200)
def test_scene1(self): # 登录 user = {"phoneArea": "86", "phoneNumber": "200000000044", "password": "******"} result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 查询获取地址 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) # 删除收获地址 aid = address_result['result']['list'][0]['id'] print(id) para = {"id": aid} delete_result = SendHttp().sent_post_bycookies(self.Deleteurl, Common.getcookies(user), para)
def test_scene04(self): log_result = SendHttp().send_post(self.logurl, self.user) self.assertEqual(log_result['code'], 200) cookie = Common.getcookies(self.user) list_result = SendHttp().sent_get_bycookies(self.listurl, cookie) id_num = int(list_result['result']['total']) id_list = list(range(id_num)) for index in range(len(id_list)): id_list[index] = list_result['result']['list'][index]['id'] self.assertEqual(list_result['code'], 200) para = {"id": id_list[id_num - 1]} del_result = SendHttp().send_post_bycookies(self.delurl, para, cookie) self.assertEqual(del_result['code'], 200) add_para = { "id": "", "receiverName": "测试用户", "cellPhone": "12345678900", "province": "浙江省", "city": "杭州市", "area": "滨江市", "addressDetail": "浙江大学" } add_result = SendHttp().send_post_bycookies(self.addurl, add_para, cookie) self.assertEqual(add_result['code'], 200) submit_data = { "skuIds": "2,3", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": "测试用户", "cellPhone": "12345678900", "addressDetail": "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江市", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 0, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } sub_result = SendHttp().send_post_bycookies(self.suburl, submit_data, self.cookie) self.assertEqual(sub_result['code'], 200)
def test_scene2(self): # 登录 user = {"phoneArea": "86", "phoneNumber": "200000000066", "password": "******"} login_result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(login_result['code'], 200) self.assertEqual(login_result['message'], 'success') # 查询收货地址 cookie = Common.getcookies(user) address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, cookie) self.assertEqual(address_result['code'], 200) self.assertEqual(address_result['message'], 'success') # 计算运费 address_list1 = address_result['result']['list'][0] province = address_list1['province'] city = address_list1['city'] area = address_list1['area'] address_id = address_list1["id"] addresstoDetial = province + "_" + city + "_" + area para = {"id": address_id, "addressDetail": addresstoDetial} fee_result = SendHttp().run_http(self.TransportFeeUrl, "GET", para) fee = fee_result['result'] print("运费为:", fee) self.assertEqual(fee_result['code'], 200) self.assertEqual(fee_result['message'], 'success') # 提交订单 receiverName = address_list1['receiverName'] cellPhone = address_list1['cellPhone'] addressDetail = address_list1['addressDetail'] submit_para = { "skuIds": "2,3", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": receiverName, "cellPhone": cellPhone, "addressDetail": addressDetail, "province": province, "city": city, "area": area, "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": fee, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } submit_result = SendHttp().sent_post_bycookies(self.SubmitUrl, cookie, submit_para) self.assertEqual(submit_result['code'], 200) self.assertEqual(submit_result['message'], 'success')
def test_scene4(self): # 登录失败 user = { "phoneArea": "86", "phoneNumber": "200000000044", "password": "******" } result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 400) self.assertEqual(result['message'], '用户名或者密码错误') # 查询收货地址list失败 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) self.assertEqual(address_result['code'], 403) self.assertEqual(address_result['message'], '请重新登录')
def test_scene4(self): # 登录失败 user = {"phoneArea": "86", "phoneNumber": "200000000011", "password": "******"} result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 400) self.assertEqual(result['message'], '用户名或者密码错误') # 查询获取地址 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) # 计算运费 try: addressDetails = address_result['result']['list'][0]['addressDetail'] para = {"id": 1, "addressDetail": addressDetails} SendHttp().run_http(self.TransportFeeUrl, "GET", para) except KeyError: print("获取运费失败")
def test_address_by_Login(self): user = { "phoneArea": "86", "phoneNumber": "20000000000", "password": "******" } SendHttp().sent_get_bycookies(self.url, Common.getcookies(user))
def test_skuList(self): user = { "phoneArea": "86", "phoneNumber": "200000000044", "password": "******" } submit_data = { "skuIds": "2,3", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": "张三", "cellPhone": "12615813537", "addressDetail": "1 栋 3 单元", "province": "1", "city": "1", "area": "1", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 0, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } resultSubmit = SendHttp().sent_post_bycookies(self.SubmitUrl, Common.getcookies(user), submit_data)
def test_listFail_by_WrongPwd(self): user = { "phoneArea": "86", "phoneNumber": "20000000000", "password": "******" } SendHttp().sent_get_bycookies(self.url, Common.getcookies(user))
def test_scene4(self): user = { "phoneArea": "86", "phoneNumber": "200000000033", "password": "******" } skulist = {"goodsId": 1} delete_id = {"id": "82317363"} login_result = SendHttp().run_http(self.login_url, 'POST', user) self.assertEqual(login_result['message'], "success") skulist_result = SendHttp().run_http(self.skulist_url, 'GET', skulist) self.assertEqual(skulist_result['message'], "success") delete_result = SendHttp().sent_post_bycookies(self.delete_url, Common.getcookies(user), delete_id) self.assertEqual(delete_result['code'], 400)
def test_scene3(self): # 登录成功 user = { "phoneArea": "86", "phoneNumber": "200000000044", "password": "******" } result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 新建订单 para = { "receiverName": "张三", "cellPhone": "12345678901", 'addressDetail': "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江区" } SendHttp().sent_post_bycookies(self.NewAddressUrl, Common.getcookies(user), para) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 提交订单 submit_data = { "skuIds": "2,3", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": "张三", "cellPhone": "12615813537", "addressDetail": "1 栋 3 单元", "province": "1", "city": "1", "area": "1", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 0, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } resultSubmit = SendHttp().sent_post_bycookies(self.SubmitUrl, Common.getcookies(user), submit_data) self.assertEqual(resultSubmit['code'], 200) self.assertEqual(resultSubmit['message'], 'success')
def test_login_fail(self): user = { "phoneArea": "86", "phoneNumber": "20000000000", "password": "******" } result = SendHttp().run_http(self.url, "POST", user) self.assertEqual(result['code'], 400)
def getIdList(self): cookie = Common.getcookies(self.user) list_result = SendHttp().sent_get_bycookies(self.listurl, cookie) id_num = int(list_result['result']['total']) id_list = list(range(id_num)) for index in range(len(id_list)): id_list[index] = list_result['result']['list'][index]['id'] return id_list
def test_fee9(self): address = { "addressDetail": "浙江省_杭州市_滨江区", "id": "8", "tm": "1545038153217" } result = SendHttp().sent_get(self.url, address) self.assertEqual(result['code'], 200)
def test_Scene1(self): user = { "phoneArea": "86", "phoneNumber": "200000000033", "password": "******" } newaddress = { "id": "", "receiverName": "小飞龙", "cellPhone": "15226541128", "province": "河北省", "city": "石家庄市", "area": "裕华区", "addressDetail": "新校区" } submit = { "skuIds": "3", "skuNumbers": "1", "stockIds": "74966313", "receiverName": "小飞龙", "cellPhone": "15226541128", "addressDetail": "新校区", "province": "河北省", "city": "石家庄市", "area": "裕华区", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 6, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } login_result = SendHttp().run_http(self.login_url, "POST", user) self.assertEqual(login_result['code'], 200) self.assertEqual(login_result['message'], "success") skulist_result = SendHttp().sent_get(self.skulist_url) self.assertEqual(skulist_result['message'], "success") newaddress_result = SendHttp().sent_post_bycookies( self.addAddress_url, Common.getcookies(user), newaddress) self.assertEqual(newaddress_result['code'], 200) submit_result = SendHttp().sent_post_bycookies(self.submit_url, Common.getcookies(user), submit) self.assertEqual(submit_result['message'], "success")
def test_login_success(self): user = { "phoneArea": "86", "phoneNumber": "20000000000", "password": "******" } result = SendHttp().run_http(self.url, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success')
def test_second(self): user = { "phoneArea": "86", "phoneNumber": "200000000055", "password": "******" } address = { "addressDetail": "浙江省_杭州市_滨江区", "id": "\"1\"", "tm": "1545038153217" } detial = { "skuIds": "3", "skuNumbers": "1", "stockIds": "74966313", "receiverName": "小飞龙", "cellPhone": "12345678909", "addressDetail": "河北师范", "province": "四川省", "city": "成都市", "area": "锦江区", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 6, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } login_result = SendHttp().run_http(self.loginurl, "POST", user) self.assertEqual(login_result['code'], 200) self.assertEqual(login_result['message'], "success") fee_result = SendHttp().sent_get(self.feeurl, address) self.assertEqual(fee_result['code'], 400) self.assertEqual(fee_result['message'], "请求失败") list_result = SendHttp().sent_get_bycookies(self.listurl, Common.getcookies(user)) self.assertEqual(list_result['code'], 200) self.assertEqual(list_result['message'], "success") submit_result = SendHttp().sent_post_bycookies(self.submiturl, Common.getcookies(user), detial) self.assertEqual(submit_result['code'], 200) self.assertEqual(submit_result['message'], "success")
def test_scene1(self): # 获取所有商品的列表 skulist_result = SendHttp().run_http(self.SkulistUrl, "GET") # result=SendHttp().sent_get(self.SkulistUrl) self.assertEqual(skulist_result['code'], 200) self.assertEqual(skulist_result['message'], 'success') # 获取goodsId=1的商品信息 para1 = {"goodsId": 1} skulist_result1 = SendHttp().run_http(self.SkulistUrl, "GET", para1) self.assertEqual(skulist_result1['code'], 200) self.assertEqual(skulist_result1['message'], 'success') # 获取goodsId=2的商品信息 para2 = {"goodsId": 2} skulist_result2 = SendHttp().run_http(self.SkulistUrl, "GET", para2) self.assertEqual(skulist_result2['code'], 200) self.assertEqual(skulist_result2['message'], 'success') # 获取goodsId=3的商品信息 para3 = {"goodsId": 1} skulist_result3 = SendHttp().run_http(self.SkulistUrl, "GET", para3) self.assertEqual(skulist_result3['code'], 200) self.assertEqual(skulist_result3['message'], 'success')
def test_login_by_para(self): sheet = readExcel( r"F:\PycharmProjects\Request\testcase\qgdata\userdata.xlsx", 0) # 忽略第一行的列名 for i in range(1, sheet.nrows): user = { "phoneArea": "86", "phoneNumber": sheet.cell_value(i, 0), "password": "******" } result = SendHttp().run_http(self.url, "POST", user) self.assertEqual(result['code'], 200)
def test_scene2(self): # 登录 user = {"phoneArea": "86", "phoneNumber": "200000000011", "password": "******"} result = SendHttp().run_http(self.LoginUrl, "POST", user) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success') # 查询获取地址 address_result = SendHttp().sent_get_bycookies(self.AddressListUrl, Common.getcookies(user)) pro = address_result['result']['list'][0]['province'] city = address_result['result']['list'][0]['city'] area = address_result['result']['list'][0]['area'] # 添加收获地址 address = {"id": "", "receiverName": "李四", "cellPhone": "200000000011", "province": "江苏省", "city": "南京市", "area": "鼓楼区", "addressDetail": "南京大学"} add_result = SendHttp().sent_post_bycookies(self.Addurl, Common.getcookies(user), address) # 删除收获地址 id = address_result['result']['list'][0]['id'] delete_result = SendHttp().sent_post_bycookies(self.Deleteurl, Common.getcookies(user), id)
def test_scene2(self): user = { "phoneArea": "86", "phoneNumber": "200000000033", "password": "******" } fee = { "addressDetail": "浙江省_杭州市_滨江区", "id": "1", "tm": "1545038153217" } submit = { "skuIds": "3", "skuNumbers": "1", "stockIds": "74966313", "receiverName": "小飞龙", "cellPhone": "15226541128", "addressDetail": "新校区", "province": "河北省", "city": "石家庄市", "area": "裕华区", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 6, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } skulist_result = SendHttp().sent_get(self.skulist_url) self.assertEqual(skulist_result['message'], "success") fee_result = SendHttp().sent_get(self.fee_url, fee) self.assertEqual(fee_result['code'], 200) submit_result = SendHttp().sent_post_bycookies(self.submit_url, Common.getcookies(user), submit) self.assertEqual(submit_result['message'], "success")
def test_scene01(self): log_result = SendHttp().send_post(self.logurl, self.user) self.assertEqual(log_result['code'], 200) list_result = SendHttp().sent_get_bycookies(self.listurl, self.cookie) self.assertEqual(list_result['code'], 200) para = { "id": "1", "addressDetail": "浙江省_杭州市_滨江市", "tm": "1545553765731" } fee_result = SendHttp().sent_get_bycookies(self.feeurl, self.cookie, para) self.assertEqual(fee_result['code'], 200) submit_data = { "skuIds": "2,3", "skuNumbers": "1,1", "stockIds": "74966312,74966313", "receiverName": "测试用户", "cellPhone": "12345678900", "addressDetail": "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江市", "voiceStatus": 0, "needInvoice": 0, "invoiceHead": "", "transportFee": 0, "logisticsCompanyId": 1, "accessSource": "noSource", "accessDevice": 0 } sub_result = SendHttp().send_post_bycookies(self.suburl, submit_data, self.cookie) self.assertEqual(sub_result['code'], 200)
def test_addressnew1(self): user = { "phoneArea": "86", "phoneNumber": "200000000066", "password": "******" } para = { "id": "", "receiverName": "张三", "cellPhone": "12345678901", "addressDetail": "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江区" } result = SendHttp().sent_post_bycookies(self.url, Common.getcookies(user), para) self.assertEqual(result['code'], 200) self.assertEqual(result['message'], 'success')
def test_addressnew21(self): user = { "phoneArea": "86", "phoneNumber": "200000000066", "password": "******" } para = { "id": "", "receiverName": "张三", "cellPhone": "12345678901", "addressDetail": "浙江大学", "province": "浙江省", "city": "杭州市", "area": "滨江区" } result = SendHttp().sent_post_bycookies(self.url, Common.getcookies(user), para) # self.assertEqual(result['code'], 400) # self.assertEqual(result['message'], '请求参数不正确') # 用例失败,code:200 message:success if self.assertEqual(result['code'], 200): print('添加重复的地址成功,用例失败')
def tearDown(self): SendHttp().sent_get_bycookies(self.url, Common.getcookies(self.user), self.lists)
def test_fee12(self): address = {"addressDetail": "1", "id": "\"1\"", "tm": "1545038153217"} result = SendHttp().sent_get(self.url, address) self.assertEqual(result['code'], 400)