def test02_theme(self, theme_code, theme_ids, theme_length_url, theme_name): # 状态码 # theme_code = 200 # # id=1, id=2, id=3 # theme_ids = ['id":1', 'id":2', 'id":3'] # # 长度-url # theme_length_url = 0 # # name # theme_name = "专题栏位一" # 请求 print( "theme_code:{}, theme_ids:{}, theme_length_url:{}, theme_name:{}". format(theme_code, theme_ids, theme_length_url, theme_name)) response = ApiFactory.home_api().theme() # 断言-状态码 auto(self, response.status_code, theme_code) # 断言- id=1, id=2, id=3 for i in theme_ids: auto(self, i, response.text, tag="in") # 断言-长度 auto(self, len(response.json()), theme_length_url, tag="more") # 断言-name auto(self, response.json()[0].get("name"), theme_name) # 断言-url auto(self, len(response.json()[0].get("topic_img").get("url")), theme_length_url, tag="more")
def test03_commodity(self, commodity_id, commodity_code, commodity_name, commodity_price, commodity_length_url): print( "commodity_id:{}, commodity_code:{}, commodity_name:{}, commodity_price:{}, commodity_length_url:{}" .format(commodity_id, commodity_code, commodity_name, commodity_price, commodity_length_url)) # # id # commodity_id = 17 # # 状态码 # commodity_code = 200 # # name # commodity_name = "油炸花生 300克" # # 价格-price # commodity_price = "0.01" # # 长度url # commodity_length_url = 0 # 请求 response = ApiFactory.category_api().commodity(commodity_id) # 断言状态码 auto(self, response.status_code, commodity_code) # 断言-id auto(self, response.json().get("id"), commodity_id) # 断言-name auto(self, response.json().get("name"), commodity_name) # 断言-price auto(self, response.json().get("price"), commodity_price) # 断言长度-url auto(self, len(response.json().get("main_img_url")), commodity_length_url, "more")
def test01_banner(self, banner_code, banner_id, banner_name, banner_length): # # 状态码 # banner_code = 200 # # id # banner_id = 1 # # name # banner_name = "首页置顶" # # items长度大于0 # banner_length = 0 # 请求 print("banner_code:{}, banner_id:{}, banner_name:{}, banner_length:{}". format(banner_code, banner_id, banner_name, banner_length)) response = ApiFactory.home_api().banner() # 断言-状态码 auto(self, response.status_code, banner_code) # 断言-id auto(self, response.json().get("id"), banner_id) # 断言-name auto(self, response.json().get("name"), banner_name) # 断言items长度大于0 auto(self, len(response.json().get("items")), banner_length, tag="more") # 断言图片url不为空 auto(self, len(response.json().get("items")[0].get("img").get("url")), banner_length, tag="more")
def test2_verify(self, verify_code, verify_isValid): print("verify_code:{}, verify_isValid:{}".format( verify_code, verify_isValid)) # verify_code = 200 # verify_isValid = True response = ApiFactory.user_api().verify_token() auto(self, response.status_code, verify_code) auto(self, response.json().get("isValid"), verify_isValid)
def test3_address(self, address_code, address_name, address_mobile): print("address_code:{}, address_name:{}, address_mobile:{}".format( address_code, address_name, address_mobile)) # address_code = 200 # address_name = "李白" # address_mobile = "13012345678" response = ApiFactory.user_api().address_user() auto(self, response.status_code, address_code) auto(self, response.json().get("name"), address_name) auto(self, response.json().get("mobile"), address_mobile)
def test1_token(self, token_code, token_length): print("token_code:{}, token_length:{}".format(token_code, token_length)) # token_code = 200 # token_length = 0 response = ApiFactory.user_api().create_token() auto(self, response.status_code, token_code) auto(self, len(response.json()), token_length, "more") app.header["token"] = response.json().get("token") print("app:{}".format(app.header))
def test01_category(self, category_code, category_length, category_name): print("category_code:{}, category_length:{}, category_name:{}".format( category_code, category_length, category_name)) # # 状态码 # category_code = 200 # # 长度-url # category_length = 0 # # name # category_name = "炒货" # 请求 response = ApiFactory.category_api().category() # 断言-状态码 auto(self, response.status_code, category_code) # 断言-长度 auto(self, len(response.json()), category_length, "more") # 断言-name auto(self, category_name, response.text, "in")
def test03_product(self, product_code, product_length, product_keys): # # 状态码 # product_code = 200 # # 长度 # product_length = 0 # # 关键字段 # product_keys = ["id", "name", "price", "main_img_url"] print("product_code:{}, product_length:{}, product_keys:{}".format( product_code, product_length, product_keys)) response = ApiFactory.home_api().product() # 断言-状态码 auto(self, response.status_code, product_code) # 断言-长度 auto(self, len(response.json()), product_length, tag="more") # 断言-关键字段 for i in product_keys: auto(self, i, response.text, tag="in")
def test02_classify(self, classify_code, classify_id, classify_length_url, classify_name): print( "classify_code:{}, classify_id:{}, classify_length_url:{}, classify_name:{}" .format(classify_code, classify_id, classify_length_url, classify_name)) # 状态码 # classify_code = 200 # # id # classify_id = 4 # # url # classify_length_url = 0 # # name # classify_name = "油炸花生 300克" # 请求 response = ApiFactory.category_api().classify(classify_id) # 断言状态码 auto(self, response.status_code, classify_code) # 断言-长度 auto(self, len(response.json()), classify_length_url, "more") # 断言-name auto(self, classify_name, response.text, "in")
def test3_user(self, user_code, user_page, user_list, user_keys): print("user_code:{}, user_page:{}, user_list:{}, user_keys:{}".format( user_code, user_page, user_list, user_keys)) # # 状态码 # user_code = 200 # # 当前页码 # user_page = 1 # # 订单列表长度 # user_list = 0 # # 关键字段 # user_keys = ["id", "order_no", "total_price"] # 请求 response = ApiFactory.order_api().user_order(user_page) # 断言-状态码 auto(self, response.status_code, user_code) # 断言-当前页数 auto(self, response.json().get("current_page"), user_page) # 断言-订单列表长度 auto(self, len(response.json().get("data")), user_list, "more") # 断言关键字段 for i in user_keys: auto(self, i, response.text, "in")
def test2_query(self, query_id, query_code, query_order_no, query_total_price): print( "query_id:{}, query_code:{}, query_order_no:{}, query_total_price:{}" .format(query_id, query_code, query_order_no, query_total_price)) # 订单id # query_id = 103 # # 状态码 # query_code = 200 # # 订单no # query_order_no = "DC20665823292544" # # 订单price # query_total_price = "0.01" # 请求 response = ApiFactory.order_api().query_order(query_id) # 断言-状态码 auto(self, response.status_code, query_code) # 断言-id auto(self, response.json().get("id"), query_id) # 断言-order_no auto(self, response.json().get("order_no"), query_order_no) # 断言-total_price auto(self, response.json().get("total_price"), query_total_price)
def test1_create(self, produtc_id, count, create_code, create_length, create_pass): print( "produtc_id:{}, count:{}, create_code:{}, create_length:{}, create_pass:{}" .format(produtc_id, count, create_code, create_length, create_pass)) # produtc_id = 2 # count = 1 # # 状态码 # create_code = 200 # # 长度不为空 # create_length = 0 # # pass等于ture # create_pass = True # 请求 response = ApiFactory.order_api().create_order(produtc_id, count) # 断言-状态码 auto(self, response.status_code, create_code) # 断言-order_id长度 auto(self, len(response.json().get("order_id")), create_length, "more") # 断言 - order_no长度 auto(self, len(response.json().get("order_no")), create_length, "more") # 断言-pass等于ture auto(self, response.json().get("pass"), create_pass)
from api.test5_apiFactory import ApiFactory # 首页-轮播图 print("首页:{}".format(ApiFactory.home_api().banner().json())) # 首页-专题栏 print("专题栏:{}".format(ApiFactory.home_api().theme().json())) # 首页-新品 print("新品:{}".format(ApiFactory.home_api().product().json()))