Commit 06684320 authored by liguangyu06's avatar liguangyu06
Browse files

用例优化

parent f63fa345
...@@ -32,43 +32,45 @@ request_body = commonFuc().get_business_data(module, "payload11") ...@@ -32,43 +32,45 @@ request_body = commonFuc().get_business_data(module, "payload11")
result = requests.get(url, params=request_body, headers=headers) result = requests.get(url, params=request_body, headers=headers)
result = json.loads(result.content) result = json.loads(result.content)
# 生成随机数 # 判断是否存在发货单物流信息
jde_random = random.randint(0, len(result["data"]["list"]) - 1) if result["data"]["list"]:
# 获取发货单信息 # 生成随机数
demand_parent_code = result["data"]["list"][jde_random]["demandParentCode"] jde_random = random.randint(0, len(result["data"]["list"]) - 1)
# 获取发货单信息
demand_parent_code = result["data"]["list"][jde_random]["demandParentCode"]
# 第三步订单发货明细导出操作 # 第三步订单发货明细导出操作
url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url20") url = commonFuc().get_api_url() + commonFuc().get_business_data(module, "url20")
request_body = commonFuc().get_business_data(module, "payload20", demand_parent_code) request_body = commonFuc().get_business_data(module, "payload20", demand_parent_code)
# print(request_body) # print(request_body)
""" """
场景: 订单发货明细导出验证 场景: 订单发货明细导出验证
用例名称:订单发货明细导出验证 用例名称:订单发货明细导出验证
输出:{"demandParentCode":"%s"} 输出:{"demandParentCode":"%s"}
""" """
# 发送请求 # 发送请求
result = requests.get(url, params=request_body, headers=headers) result = requests.get(url, params=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)
# 获取文件中需求单号 # 获取文件中需求单号
excel = HandleExcel(file_path, "Sheet1") excel = HandleExcel(file_path, "Sheet1")
# print(excel.read_data()) # print(excel.read_data())
result = {"demandParentCode": excel.read_data()[0].get("母需求单编号\n(商城订单号)")} result = {"demandParentCode": excel.read_data()[0].get("母需求单编号\n(商城订单号)")}
# print(result) # print(result)
result["api_time"] = api_time result["api_time"] = api_time
# print(result) # print(result)
# 获取预期结果 # 获取预期结果
check_dict = commonFuc().get_business_data(module, "checkDict20", demand_parent_code) check_dict = commonFuc().get_business_data(module, "checkDict20", demand_parent_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