コード例 #1
0
 def test_verify_token(self):
     """验证token"""
     # 请求返回对象
     res = ApiFactory.get_user_api().verify_api()
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言 -状态码
     assert res.status_code == 200
     # 断言有效
     assert res.json().get("isValid") is True
コード例 #2
0
ファイル: testProduct.py プロジェクト: Xuezhaoming/testego
 def test_product_classify_api(self):
     """商品分类"""
     # 请求返回参数
     res = ApiFactory.get_product_api().product_classify_api()
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     assert res.status_code == 200
     # 断言关键字
     assert "id" in res.text and "name" in res.text and "topic_img_id" in res.text
     # 断言列表长度大于0
     assert len(res.json()) > 0
コード例 #3
0
 def test_address_pai(self):
     """用户地址信息"""
     # 请求返回对象
     res = ApiFactory.get_user_api().address_pai()
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言 -状态码
     assert res.status_code == 200
     # 断言信息
     assert False not in [
         i in res.text for i in ["小明", "18888888888", "上海市", "浦东新区"]
     ]
コード例 #4
0
 def test_recent_api(self):
     # 请求返回对象
     res = ApiFactory.get_home_api().recent_api()
     # 打印请求地址,请求参数响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言 -状态码
     assert res.status_code == 200
     # 断言新品数量大于0
     assert len(res.json()) > 0
     # 断言关键字
     assert "id" in res.text and "name" in res.text and "price" in res.text
コード例 #5
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()))
     # 断言 -状态码
     assert res.status_code == 200
     # 断言token存在
     assert len(res.json().get("token")) > 0
     # 保存token
     app.headers["token"] = res.json().get("token")
     print("app.headers:{}".format(app.headers))
コード例 #6
0
 def test_home_api(self):
     """轮播图"""
     # 请求返回参数
     res = ApiFactory.get_home_api().banner_api()
     # 打印请求地址,请求参数响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     assert res.status_code == 200
     # 断言id 和 name
     assert res.json().get("id") == 1 and res.json().get("name") == "首页置顶"
     # 断言items列表长度大于0
     assert len(res.json().get("items")) > 0
コード例 #7
0
 def test_theme_api(self):
     """专题栏"""
     # 请求返回对象
     res = ApiFactory.get_home_api().theme_api()
     # 打印请求地址,请求参数响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言 -状态码
     assert res.status_code == 200
     # 断言三个id= 1 2 3
     assert 'id":1' in res.text and 'id":2' in res.text and 'id":3' in res.text
     # 断言关键字段 name description topic_img head_img
     assert False not in [i in res.text for i in ["name", "description", "topic_img", "head_img"]]
コード例 #8
0
ファイル: testProduct.py プロジェクト: Xuezhaoming/testego
 def test_product_detail_api(self):
     """商品信息"""
     # 请求返回参数
     res = ApiFactory.get_product_api().product_detail_api()
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     assert res.status_code == 200
     # 断言id
     assert res.json().get("id") == 2
     # 断言name
     assert res.json().get("name") == "梨花带雨 3个"
     # 断言price
     assert res.json().get("price") == "0.01"
コード例 #9
0
ファイル: testProduct.py プロジェクト: Xuezhaoming/testego
 def test_classify_product_api(self):
     """分类下商品"""
     # 请求返回参数
     res = ApiFactory.get_product_api().classify_product_api()
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     assert res.status_code == 200
     # 断言列表长度大于0
     assert len(res.json()) > 0
     # 断言关键字段
     assert False not in [
         i in res.text for i in ["id", "name", "price", "stock"]
     ]
コード例 #10
0
    def test_query_order(self):
        """查询订单"""
        # 订单id
        order_id = 115
        # 响应对象
        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") == 115

        # 断言地址 用户名 手机号
        assert res.json().get("snap_address").get("name") == "小明"
        assert res.json().get("snap_address").get("mobile") == "18888888888"
コード例 #11
0
    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
コード例 #12
0
    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"]
        ]
コード例 #13
0
ファイル: confirm.py プロジェクト: Xuezhaoming/testego
from Api.api import ApiFactory

# 调用轮播图api
# 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_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_detail_api().json()))

# 调用获取token方法
# print("返回值:{}".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(12, 7).json()))
# print("查看订单:{}".format(ApiFactory.get_order_api().query_order_api(114).json()))