大家好~我是回顾米洛!
我正在从0到1打造一个开源的接口测试平台, 也在编写一套与之对应的完整教程,希望大家多多支持。
欢迎关注我的公众号测试开发坑货,获取最新文章教程!
前置条件,但其实有个特别不友好的地方:复制,所以说这样是十分不友好的。
查询接口:[
{
"title": "用例",
"key": "caseid",
"children": [
{
"title": "数据构造器A",
"key":
"constructor_id"
}
]}
]
造起来吧~前置条件,接着就能拿到所有case_id了,再用case_id去查出case的信息,岂不美哉?defaultdict了。@staticmethod
async def get_case_and_constructor(constructor_type: int):
# 最终返回结果树
ans = list()
async with async_session() as session:
# 此处存放case_id => 前置条件的映射
constructors = defaultdict(list)
# 根据传入的前置条件类型,找出所有前置条件, 类型一致,共享开关打开,并未被删除
query = await session.execute(
select(Constructor).where(
Constructor.type == constructor_type,
Constructor.public == True,
Constructor.deleted_at == None))
# 并把这些前置条件放到constructors里面
for q in query.scalars().all():
constructors[q.case_id].append({
"title": q.name,
"key": f"{q.id}",
"isLeaf": True,
# 这里是为了拿到具体的代码,因为树一般只有name和id,我们这还需要其他数据
"constructor_json": q.constructor_json,
})# 二次查询,查出有前置条件的case
query = await session.execute(
select(TestCase).where(TestCase.id.in_(constructors.keys()), TestCase.deleted_at == None))
# 构造树,要知道children已经构建好了,就在constructors里面
for q in query.scalars().all():
# 把用例id放入cs_list,这里就不用原生join了
ans.append({
"title": q.name,
"key": f"case_{q.id}",
"disabled": True,
"children": constructors[q.id]
})
return ans很清楚。# 获取所有数据构造器
@router.get("/constructor/list")
async def list_case_and_constructor(constructor_type: int):
try:
ans = await ConstructorDao.get_case_and_constructor(constructor_type)
return PityResponse.success(ans)
except Exception as e:
return PityResponse.failed(str(e))
大一点。仔细比对了这个接口,发现它的逻辑是:import {Col, Row, TreeSelect} from "antd";
import {connect} from 'umi';
import {useEffect} from "react";
const CopyTreeSelect = ({construct, dispatch}) => {const {constructorData, searchConstructor, constructorType} = construct;
const save = (data) => {
dispatch({
type: 'construct/save',
payload: data,
})
}const getConstructorData = https://www.it610.com/article/() => {
dispatch({
type: 'construct/getConstructorTree',
payload: {
constructor_type: constructorType
}
})
}useEffect(() => {
getConstructorData();
}, [constructorType])return (
{
return treeNode.title.toLowerCase().indexOf(inputValue.toLowerCase()) > -1
}}
dropdownStyle={{maxHeight: 600, overflow: 'auto'}}
treeData=https://www.it610.com/article/{constructorData}
placeholder="通过搜索构造条件,可以快速复制参数哦!"
treeDefaultExpandAll
onChange={(e) => {
save({searchConstructor: e})
if (e !== undefined) {
dispatch({
type: 'construct/getConstructorData',
payload: {id: e.split("_")[1]}
})
} else {
dispatch({
type: 'construct/save',
payload: {testCaseConstructorData: {type: constructorType, public: true, enable: true}},
})
}
}}
/>
)
}export default connect(({loading, construct}) => ({loading, construct}))(CopyTreeSelect);
copy组件。并在前置条件类型变化的时候,自动更换数据源。测试报告邮件通知功能。(其实说简单也不简单,如果要设计到样式,还挺麻烦)大家好~我是也在编写一套与之对应的完整米洛!
我正在从0到1打造一个开源的接口测试平台
教程,希望大家多多支持。测试开发坑货,获取最新文章教程!前置条件
上一篇:记忆里的昨天【序】
下一篇:游乐园系统,助力游乐园管理