def test_add_addr(self): """测试添加收货地址""" login = LoginInterface() login_data = {"name": "a123", "password": "******"} session = login.get_session(login_data) add = Add_Addr() add_data = { "address": { "default_address": 0, "consignee": "土豆粉", "tel": "1888065189", "zipcode": "610000", "country": "1", "city": "271", "id": 0, "email": "*****@*****.**", "address": "天府新谷", "province": "24", "district": "2716", "mobile": "" }, "session": session } # print(add.add_addr(add_data)) """断言""" expect = {'succeed': 1} # status_1 = {"session": session} status = add.get_status(add_data) actual = status self.assertEqual(expect, actual) # 断言收货人姓名 addr = AddrListInter() name1 = "土豆粉" name2 = addr.get_addr_name(add_data) self.assertEqual(name1, name2)
def test_update_addr(self): """测试修改收货地址""" login = LoginInterface() login_data = {"name": "a123", "password": "******"} session = login.get_session(login_data) add_list = AddrListInter() addr_id = {"session": session} id = add_list.get_addr_id(addr_id) update = Updateaddr() update_data = { "address": { "default_address": 0, "consignee": "陈良", "tel": "151", "zipcode": "610000", "country": "1", "city": "271", "id": 0, "email": "*****@*****.**", "address": "广西壮族自治区淮安县大兴王街z座 892317", "province": "24", "district": "2714", "mobile": "" }, "address_id": id, "session": session } print(update.update_addr(update_data)) """断言""" expect = {'succeed': 1} status = update.get_status(update_data) actual = status self.assertEqual(expect, actual)
class Test_Collection(unittest.TestCase): def setUp(self): self.login = LoginInterface() # 实例化登录 self.collection = CollectionList() # 实例化收藏 def test_add_collection(self): '''测试添加收藏''' login_data = {"name": "yehong", "password": "******"} session = self.login.get_session(data=login_data) url = "?url=/user/collect/create" result = self.collection.add_collection(url=url, session=session) self.assertTrue(result, login_data) def test_show_list(self): '''测试查看收藏列表''' login_data = {"name": "yehong", "password": "******"} session = self.login.get_session(data=login_data) url = "?url=/user/collect/list" result = self.collection.collection_list(url=url, session=session) self.assertTrue(result, session) def test_collection_news(self): '''测试查看收藏商品详情''' login_data = {"name": "yehong", "password": "******"} session = self.login.get_session(data=login_data) url = "?url=/goods" result = self.collection.collection_news(url=url, session=session) self.assertTrue(result, session) def test_delete_collection(self): '''测试删除收藏''' login_data = {"name": "yehong", "password": "******"} session = self.login.get_session(data=login_data) url = "?url=/user/collect/delete" urll = "?url=/user/collect/list" rec_id = self.collection.get_rec_id(url=urll, session=session) result = self.collection.delect_collection(url=url, session=session, rec_id=rec_id) self.assertTrue(result, self.collection.get_rec_id)
def test_select_addr(self): """测试查看收货地址""" login = LoginInterface() login_data = {"name": "a123", "password": "******"} session = login.get_session(login_data) select = AddrListInter() data = {"session": session} print(select.addr_list(data)) """断言""" expect = {'succeed': 1} status = select.get_status(data) actual = status self.assertEqual(expect, actual)
def test_delete_addr(self): """测试删除收货地址""" login = LoginInterface() login_data = {"name": "a123", "password": "******"} data = login.get_session(login_data) delete = Delete_Addr() add_list = AddrListInter() addr_id = {"session": data} id = add_list.get_addr_id(addr_id) delete_data = {"address_id": id, "session": data} print(delete.delete_addr(delete_data)) """断言""" expect = {'succeed': 1} status = delete.get_status(delete_data) actual = status self.assertEqual(expect, actual)
class TestShopping(unittest.TestCase): def setUp(self): """购物前先登录""" self.login = LoginInterface() login_data = {"name": "user11", "password": "******"} self.session = self.login.get_session(data=login_data) self.shoppingcart = ShoppingCart() def test_create_cart(self): """测试添加购物车""" url = "?url=/cart/create" create_data = {"spec": [], "session": self.session, "goods_id": 84, "number": 1} self.shoppingcart.create_cart(url=url, data=create_data) """断言""" succeed = self.shoppingcart.get_goods_succeed(url=url, data=create_data) self.assertEqual(succeed, 1) def test_get_cart(self): """测试查看购物车""" url = "?url=/cart/list" get_cart_data = {"session": self.session} self.shoppingcart.get_cart(url=url, data=get_cart_data) """断言""" self.shoppingcart.get_goods_goods_list(url=url,data=get_cart_data) def test_upcart(self): """测试更新购物车""" url = "?url=/cart/update" upcart_data = {"new_number": 3, "session": self.session, "rec_id": 21819} self.shoppingcart.upcart(url=url, data=upcart_data) def test_del_cart(self): """测试删除购物车""" url = "?url=/cart/delete" delcart_data = {"session": self.session, "rec_id": 11385} self.shoppingcart.delcart(url=url, data=delcart_data)
def cancel_order_is_success(self, cancel_order_id, new_order_ids): "判断删除的order_id是否还在未支付订单的order_ids中" if cancel_order_id in new_order_ids: return False else: return True if __name__ == '__main__': from interface.login_interface import LoginInterface from interface.unpaid_order_interface import Unpaid_order_interface from common.getkeyword import get_keywords login = LoginInterface() import random login_data = {"name": "xiaohei666", "password": "******"} session = login.get_session(data=login_data) print(session) data = { "session": session, "type": "await_pay", "pagination": { "count": 10, "page": 1 } } unpaid = Unpaid_order_interface() print(unpaid.get_order_id(data=data)) depids = unpaid.get_order_id(data=data) random_num = random.randint(0, len(depids)) dep_id = depids[random_num] data = {"session": session, "order_id": dep_id}