Exemplo n.º 1
0
 def test_user_address_api(self):
     """用户地址信息"""
     # 获取响应对象
     res = ApiFactory.get_user_api().user_address_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 ["大王", "13888888888", "上海市", "浦东新区", "111号"]]
Exemplo n.º 2
0
 def test_verify_token(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
Exemplo n.º 3
0
 def test_product_classify(self):
     # 请求返回数据
     res = ApiFactory.get_product_api().product_classify_api()
     # 打印 请求地址 打印请求参数 打印请求响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     utils.common_assert_code(res)
     # 断言商品数量大于0
     assert len(res.json()) > 0
     # 断言关键字 id name topic_img_id
     assert "id" in res.text and "name" in res.text and "topic_img_id" in res.text
Exemplo n.º 4
0
 def test_recent_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
     # 断言关键字段
     assert "id" in res.text and "name" in res.text and "price" in res.text
Exemplo n.º 5
0
 def test_recent_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
     # 断言关键字段 name price main_img_url
     assert 'name' in res.text and "price" in res.text and "main_img_url" in res.text
Exemplo n.º 6
0
 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)
     # 断言id和name
     assert res.json().get("id") == 1 and res.json().get("name") == '首页置顶'
     # 断言items列表长度大于0
     assert len(res.json().get("items")) > 0
Exemplo n.º 7
0
 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)
     # 断言长度大于0
     assert len(res.json()) > 0
     # 断言关键字段
     assert "id" in res.text and "name" in res.text and "topic_img_id" in res.text
Exemplo n.º 8
0
 def test_get_token_api(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)
     # 断言token存在
     assert len(res.json().get("token")) > 0
     # 保存token
     app.headers["token"] = res.json().get("token")
     print("app.headers:{}".format(app.headers))
Exemplo n.º 9
0
 def test_classify_product(self):
     # 请求返回数据
     res = ApiFactory.get_product_api().classify_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 stock
     assert False not in [
         i in res.text for i in ['id', 'name', 'price', 'stock']
     ]
Exemplo n.º 10
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)
     # 断言token存在
     assert len(res.json().get("token")) > 0
     # 保存token
     app.headers['token'] = res.json().get("token")
     print('返回token:{}'.format(app.headers))
Exemplo n.º 11
0
 def test_product_detail(self):
     # 请求返回数据
     res = ApiFactory.get_product_api().product_detail_api()
     # 打印 请求地址 打印请求参数 打印请求响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     utils.common_assert_code(res)
     # 断言id
     assert res.json().get("id") == 2
     # 断言name
     assert res.json().get('name') == "梨花带雨 3个"
     # 断言 price
     assert res.json().get("price") == "0.01"
Exemplo n.º 12
0
 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)
     # 断言长度大于0
     assert len(res.json()) > 0
     # 断言关键字段
     assert False not in [
         i in res.text for i in ["id", "name", "price", "stock"]
     ]
Exemplo n.º 13
0
 def test_product_detail_api(self):
     """商品信息"""
     # 获取响应对象
     res = ApiFactory.get_product_api().product_detail_api()
     # 打印请求地址 打印请求参数  打印请求响应数据
     logging.info("请求地址:{}".format(res.url))
     logging.info("响应数据:{}".format(res.json()))
     # 断言状态码
     utils.common_assert_code(res)
     # 断言id
     assert res.json().get("id") == 2
     # 断言price
     assert res.json().get("price") == "0.01"
     # 断言name
     assert res.json().get("name") == "梨花带雨 3个"
Exemplo n.º 14
0
 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 =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']
     ]
Exemplo n.º 15
0
 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=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"]
     ]
Exemplo n.º 16
0
    def test_query_order_api(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") == "13888888888"
Exemplo n.º 17
0
    def test_order_list_api(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"]
        ]
Exemplo n.º 18
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
Exemplo n.º 19
0
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_detail_api().json()))

# 获取token
# 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(12,
                                                                   6).json()))
print("查看订单:{}".format(ApiFactory.get_order_api().query_order_api(43).json()))
Exemplo n.º 20
0
from Api.apifactory 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_product_api().json()))

# # 调用商品分类
# print("分类:{}".format(ApiFactory.get_product_api().product_classify_api().json()))
#
# # 调用分类下商品
# print("分类下商品:{}".format(ApiFactory.get_product_api().classify_product_api(5).json()))
#
# # 调用商品信息
# print("商品信息:{}".format(ApiFactory.get_product_api().product_detail_api(26).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(80).json()))