Files
apiautotest/utils/requests_utils/case_dependence.py

70 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
# @Time : 2023/12/18 9:16
# @Author : floraachy
# @File : case_denpence_handle
# @Software: PyCharm
# @Desc:
# 第三方库导入
import allure
from loguru import logger
# 本地应用/模块导入
from utils.requests_utils.request_control import RequestControl
from utils.data_utils.data_handle import data_handle
from config.path_config import INTERFACE_DIR
from utils.report_utils.allure_handle import allure_step
def case_dependence_handle(case_dependence, source):
"""
处理用例依赖支持接口依赖环境变量依赖SQL依赖。关键字interface, sql, env_vars
先处理环境变量依赖再处理接口依赖最后处理SQL依赖
"""
results = {}
if case_dependence is None:
logger.debug(f"跳过用例依赖处理 --> case_dependence={case_dependence}")
allure_step(f"跳过用例依赖处理 --> case_dependence={case_dependence}")
return results
# 环境变量处理
if case_dependence.get("env_vars"):
if isinstance(case_dependence["env_vars"], dict):
for key, value in case_dependence["env_vars"].items():
new_value = data_handle(value, source)
with allure.step(f"依赖环境变量 --> {key}={new_value}"):
results.update({key: new_value})
else:
allure_step(f"依赖环境变量格式错误,跳过依赖环境变量处理~ --> env_vars仅支持dict格式")
logger.warning(f"依赖环境变量格式错误,跳过依赖环境变量处理~ --> env_vars仅支持dict格式")
else:
allure_step(f"依赖环境变量为空,跳过依赖环境变量处理~")
logger.warning(f"依赖环境变量为空,跳过依赖环境变量处理~")
if case_dependence.get("interface"):
interfaces = case_dependence["interface"]
if isinstance(interfaces, str):
api_data = RequestControl().get_api_data(api_file_path=INTERFACE_DIR, key=interfaces)
with allure.step(f"依赖接口:{api_data['title']}({interfaces})"):
result = RequestControl().api_request_flow(request_data=api_data, global_var=source)
results.update(result)
elif isinstance(interfaces, list):
for interface in interfaces:
api_data = RequestControl().get_api_data(api_file_path=INTERFACE_DIR, key=interface)
with allure.step(f"依赖接口:{api_data['title']}({interface})"):
result = RequestControl().api_request_flow(request_data=api_data, global_var=source)
results.update(result)
else:
allure_step(f"依赖接口格式错误,跳过依赖接口处理~ --> interface 仅支持str和list格式")
logger.warning(f"依赖接口格式错误,跳过依赖接口处理~ --> interface 仅支持str和list格式")
else:
allure_step(f"依赖接口为空,跳过依赖接口处理~")
logger.warning(f"依赖接口为空,跳过依赖接口处理~")
# 依赖SQL处理
if case_dependence.get("sql"):
allure_step(f"依赖SQL暂不支持跳过依赖SQL处理~")
logger.warning(f"暂时不支持依赖sql处理后续更新")
pass
return results