def test_verify_token_api(self): """验证token""" res = Apifactory.get_user_api().verify_token_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert res.json().get("isValid") is True
def test_product_datail_api(self): """商品信息""" res = Apifactory.get_product_api().product_datail_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert res.json().get("id") == 2 assert res.json().get("price") == '0.01' assert res.json().get("name") == '梨花带雨 3个'
def test_user_addr_api(self): res = Apifactory.get_user_api().user_addr_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert False not in [ i in res.text for i in ["司马狗剩", "13866666666", "上海市", "浦东新区", "110号"] ]
def test_product_classify_api(self): """商品分类""" res = Apifactory.get_product_api().product_classify_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert len(res.json()) > 0 assert "id" in res.text and "name" in res.text and "topic_img_id" in res.text
def test_home_api(self): """轮播图""" res = Apifactory.get_home_api().banner_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言状态码 utils.common_assert_code(res) # 断言items列表长度大于0 assert len(res.json().get("items")) > 0
def test_get_token(self): """获取token""" res = Apifactory.get_user_api().get_token_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert len(res.json().get("token")) > 0 app.headers["token"] = res.json().get("token") print("headers", app.headers)
def test_classify_product_api(self): """分类下商品""" res = Apifactory.get_product_api().classify_product_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) utils.common_assert_code(res) assert len(res.json()) > 0 assert False not in [ i in res.text for i in ["id", "name", "price", "stock"] ]
def test_product_api(self): """最近新品""" res = Apifactory.get_home_api().recent_product_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言状态码 utils.common_assert_code(res) # 断言新品数量大于0 assert len(res.json()) > 0 # 断言关键字段 id name price assert "id" in res.text and "name" in res.text and "price" in res.text
def test_theme_api(self): """专题栏""" res = Apifactory.get_home_api().theme_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言状态码 utils.common_assert_code(res) # 断言id assert False not in [ i in res.text for i in ['id":1', 'id":2', 'id":3'] ] # 断言关键字段name description topic_img head_img assert False not in [ i in res.text for i in ["name", "description", "topic_img", "head_img"] ]
def test_query_order(self): """查询订单""" # 订单id order_id = 114 # 响应对象 res = Apifactory.get_order_api().query_order_api(order_id) logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言 状态码 utils.common_assert_code(res) # 断言订单id assert res.json().get("id") == 114 # 断言地址 用户名 手机号 assert res.json().get("snap_address").get("name") == "司马狗剩" assert res.json().get("snap_address").get("mobile") == "13866666666"
def test_order_list(self): """订单列表""" # 响应对象 res = Apifactory.get_order_api().order_list_api() logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言 状态码 utils.common_assert_code(res) # 断言页面是否是第一个 assert res.json().get("current_page") == 1 # 断言 订单数据大于0 根据用户数据决定 assert len(res.json()) > 0 # 断言关键字段 assert False not in [ i in res.text for i in ["id", "order_no", "total_price"] ]
def test_order_api(self): """创建订单""" # 商品id product_id = 7 # 购买数量 count = 3 # 响应对象 res = Apifactory.get_order_api().create_order_api(product_id, count) logging.info("请求地址{}".format(res.url)) logging.info("响应数据{}".format(res.json())) # 断言 状态码 utils.common_assert_code(res) # 订单编号 和 订单id 不为空 assert len(res.json().get("order_no")) > 0 and len( res.json().get("order_id")) > 0 # 断言订单是否通过 assert res.json().get("pass") is True
from Api.apifactory import Apifactory # print("轮播图{}".format(Apifactory.get_home_api().banner_api().json())) # # print("专题栏{}".format(Apifactory.get_home_api().theme_api().json())) # # print("最近新品{}".format(Apifactory.get_home_api().recent_product_api().json())) # # print("商品分类{}".format(Apifactory.get_product_api().product_classify_api().json())) # # print("分类下商品{}".format(Apifactory.get_product_api().classify_product_api().json())) # # print("商品详情{}".format(Apifactory.get_product_api().product_datail_api().json())) # print("token{}".format(Apifactory.get_user_api().get_token_api().json())) print("订单列表{}".format(Apifactory.get_order_api().order_list_api().json())) print("创建订单{}".format(Apifactory.get_order_api().create_order_api(19, 7).json())) print("查看订单详情{}".format(Apifactory.get_order_api().query_order_api(71).json()))