147 lines
3.6 KiB
Plaintext
147 lines
3.6 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
debug(f'get_sd_test_cases.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
|
|
ns['sort'] = ["priority desc","created_at desc"]
|
|
|
|
|
|
|
|
sql = '''select a.*, b.plan_id_text, c.case_type_text, d.status_text, e.priority_text
|
|
from (select * from sd_test_cases where 1=1 [[filterstr]]) a left join (select id as plan_id,
|
|
plan_name as plan_id_text from sd_test_plans where 1 = 1) b on a.plan_id = b.plan_id left join (select k as case_type,
|
|
v as case_type_text from appcodes_kv where parentid='sd_test_case_type') c on a.case_type = c.case_type left join (select k as status,
|
|
v as status_text from appcodes_kv where parentid='sd_test_case_status') d on a.status = d.status left join (select k as priority,
|
|
v as priority_text from appcodes_kv where parentid='sd_priority') e on a.priority = e.priority'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if filterjson and isinstance(filterjson, str):
|
|
try:
|
|
filterjson = json.loads(filterjson)
|
|
except (json.JSONDecodeError, TypeError):
|
|
filterjson = None
|
|
fields_str=r'''[
|
|
{
|
|
"name": "id",
|
|
"title": "主键ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "plan_id",
|
|
"title": "方案ID",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "case_name",
|
|
"title": "用例名称",
|
|
"type": "str",
|
|
"length": 200,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "case_type",
|
|
"title": "用例类型",
|
|
"type": "str",
|
|
"length": 20,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "priority",
|
|
"title": "优先级",
|
|
"type": "str",
|
|
"length": 10,
|
|
"nullable": "no",
|
|
"default": "'P2'"
|
|
},
|
|
{
|
|
"name": "precondition",
|
|
"title": "前置条件",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "steps",
|
|
"title": "测试步骤(JSON数组)",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "expected_result",
|
|
"title": "预期结果",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "actual_result",
|
|
"title": "实际结果",
|
|
"type": "text"
|
|
},
|
|
{
|
|
"name": "status",
|
|
"title": "用例状态",
|
|
"type": "str",
|
|
"length": 20,
|
|
"nullable": "no",
|
|
"default": "'pending'"
|
|
},
|
|
{
|
|
"name": "executed_by",
|
|
"title": "执行人",
|
|
"type": "str",
|
|
"length": 32
|
|
},
|
|
{
|
|
"name": "executed_at",
|
|
"title": "执行时间",
|
|
"type": "timestamp"
|
|
},
|
|
{
|
|
"name": "duration_ms",
|
|
"title": "执行耗时(毫秒)",
|
|
"type": "int"
|
|
},
|
|
{
|
|
"name": "created_at",
|
|
"title": "创建时间",
|
|
"type": "timestamp",
|
|
"nullable": "no"
|
|
}
|
|
]'''
|
|
ori_fields = json.loads(fields_str)
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in ori_fields ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'{sql=}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('pipeline_sdlc')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |