Commit f63fa345 authored by liguangyu06's avatar liguangyu06
Browse files

用例优化

parent 217b7670
...@@ -32,44 +32,46 @@ request_body = commonFuc().get_business_data(module, "payload1") ...@@ -32,44 +32,46 @@ request_body = commonFuc().get_business_data(module, "payload1")
result = requests.post(url, json=request_body, headers=headers) result = requests.post(url, json=request_body, headers=headers)
result = json.loads(result.content) result = json.loads(result.content)
# 生成随机数 # 判断是否存在商品属性信息
random_demand = random.randint(0, len(result["data"]["list"]) - 1) if result["data"]["list"]:
# 获取商品属性信息 # 生成随机数
product_code = result["data"]["list"][random_demand]["productCode"] random_demand = random.randint(0, len(result["data"]["list"]) - 1)
# 获取商品属性信息
product_code = result["data"]["list"][random_demand]["productCode"]
# 第三步进行明细导出操作 # 第三步进行明细导出操作
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url9") url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url9")
request_body = commonFuc().get_business_data(module, "payload9", product_code) request_body = commonFuc().get_business_data(module, "payload9", product_code)
# print(request_body) # print(request_body)
""" """
场景: 商品属性明细导出验证 场景: 商品属性明细导出验证
用例名称:商品属性明细导出验证 用例名称:商品属性明细导出验证
输出:{"productCode":"%s"} 输出:{"productCode":"%s"}
""" """
# 发送请求 # 发送请求
result = requests.post(url, json=request_body, headers=headers) result = requests.post(url, json=request_body, headers=headers)
# 获取接口响应时间 # 获取接口响应时间
api_time = float(result.elapsed.total_seconds()) api_time = float(result.elapsed.total_seconds())
# 获取文件 # 获取文件
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
file_path = BASE_DIR + "/data/cmdc_files/商品属性导出明细.xlsx" file_path = BASE_DIR + "/data/cmdc_files/商品属性导出明细.xlsx"
# 获取到导出文件存入cmdc_files文件中 # 获取到导出文件存入cmdc_files文件中
with open(file_path, 'wb') as f: with open(file_path, 'wb') as f:
f.write(result.content) f.write(result.content)
# 获取导出明细文件中商品code # 获取导出明细文件中商品code
excel = HandleExcel(file_path, "商品属性") excel = HandleExcel(file_path, "商品属性")
result = {"productCode": excel.read_data()[0].get("商品编码")} result = {"productCode": excel.read_data()[0].get("商品编码")}
result["api_time"] = api_time result["api_time"] = api_time
# print(result) # print(result)
# 获取预期结果 # 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict9", product_code) check_dict = commonFuc().get_business_data(module, "checkDict9", product_code)
# print(check_dict) # print(check_dict)
# 断言实际结果中是否包含预期结果的内容 # 断言实际结果中是否包含预期结果的内容
commonFuc().check_result(check_dict, result) commonFuc().check_result(check_dict, result)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment