提交所有代码到 qiaoxinjiu 分支
This commit is contained in:
BIN
app/api/dao/__pycache__/automationDao.cpython-38.pyc
Normal file
BIN
app/api/dao/__pycache__/automationDao.cpython-38.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
129
app/api/dao/automationDao.py
Normal file
129
app/api/dao/automationDao.py
Normal file
@@ -0,0 +1,129 @@
|
||||
# encoding: UTF-8
|
||||
from sqlalchemy import func
|
||||
|
||||
from logger import logger
|
||||
from ..model.automationModel import AutoExecution, AutoExecutionCase
|
||||
from ..model.caseModel import TestCase
|
||||
from ..model.planModel import PlanCase, TestPlan
|
||||
|
||||
|
||||
class AutomationDao(object):
|
||||
@staticmethod
|
||||
def create_execution(session, add_info):
|
||||
obj = AutoExecution(**add_info)
|
||||
session.add(obj)
|
||||
err = session.done(close=False)
|
||||
if err:
|
||||
logger.warning(f'AutoExecution新增失败!{err}')
|
||||
return 0, f'新增失败!{err}'
|
||||
return obj, ''
|
||||
|
||||
@staticmethod
|
||||
def batch_create_execution_cases(session, batch_info_list):
|
||||
if not batch_info_list:
|
||||
return [], ''
|
||||
objs = [AutoExecutionCase(**info) for info in batch_info_list]
|
||||
session.add_all(objs)
|
||||
err = session.done(close=False)
|
||||
if err:
|
||||
logger.warning(f'AutoExecutionCase批量新增失败!{err}')
|
||||
return [], f'批量新增失败!{err}'
|
||||
return objs, ''
|
||||
|
||||
@staticmethod
|
||||
def update_execution_by_id(session, execution_id, update_info):
|
||||
update_res = session.query(AutoExecution).filter(AutoExecution.id == int(execution_id)).update(update_info)
|
||||
err = session.done(close=False)
|
||||
if err:
|
||||
logger.error(f'AutoExecution更新失败!id: {execution_id}, err: {err}')
|
||||
return 0, f'更新失败!{err}'
|
||||
if not update_res:
|
||||
return 0, '未查询到对应执行记录!'
|
||||
return int(execution_id), ''
|
||||
|
||||
@staticmethod
|
||||
def get_execution_by_id(session, execution_id):
|
||||
return session.query(AutoExecution).filter(AutoExecution.id == int(execution_id)).first()
|
||||
|
||||
@staticmethod
|
||||
def list_execution_by_filters(session, filters, page=1, limit=20):
|
||||
query = session.query(AutoExecution).filter(*filters)
|
||||
total = query.count()
|
||||
items = query.order_by(AutoExecution.created_time.desc()).offset((int(page) - 1) * int(limit)).limit(int(limit)).all()
|
||||
return items, total
|
||||
|
||||
@staticmethod
|
||||
def get_execution_case_by_id(session, execution_case_id):
|
||||
return session.query(AutoExecutionCase).filter(AutoExecutionCase.id == int(execution_case_id)).first()
|
||||
|
||||
@staticmethod
|
||||
def get_execution_case_by_unique(session, execution_id, case_id, plan_case_id=None):
|
||||
filters = [AutoExecutionCase.execution_id == int(execution_id), AutoExecutionCase.case_id == int(case_id)]
|
||||
if plan_case_id:
|
||||
filters.append(AutoExecutionCase.plan_case_id == int(plan_case_id))
|
||||
return session.query(AutoExecutionCase).filter(*filters).order_by(AutoExecutionCase.id.asc()).first()
|
||||
|
||||
@staticmethod
|
||||
def update_execution_case_by_id(session, execution_case_id, update_info):
|
||||
update_res = session.query(AutoExecutionCase).filter(AutoExecutionCase.id == int(execution_case_id)).update(update_info)
|
||||
err = session.done(close=False)
|
||||
if err:
|
||||
logger.error(f'AutoExecutionCase更新失败!id: {execution_case_id}, err: {err}')
|
||||
return 0, f'更新失败!{err}'
|
||||
if not update_res:
|
||||
return 0, '未查询到对应执行明细!'
|
||||
return int(execution_case_id), ''
|
||||
|
||||
@staticmethod
|
||||
def list_execution_case_by_filters(session, filters, page=1, limit=20):
|
||||
query = session.query(AutoExecutionCase).filter(*filters)
|
||||
total = query.count()
|
||||
items = query.order_by(AutoExecutionCase.id.asc()).offset((int(page) - 1) * int(limit)).limit(int(limit)).all()
|
||||
return items, total
|
||||
|
||||
@staticmethod
|
||||
def count_execution_case_summary(session, execution_id):
|
||||
rows = session.query(AutoExecutionCase.status, func.count(AutoExecutionCase.id)).filter(
|
||||
AutoExecutionCase.execution_id == int(execution_id)
|
||||
).group_by(AutoExecutionCase.status).all()
|
||||
summary = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 0}
|
||||
for status, count in rows:
|
||||
summary[int(status)] = int(count)
|
||||
summary['total'] = sum(summary.values())
|
||||
return summary
|
||||
|
||||
@staticmethod
|
||||
def query_case_auto_item(session, case_id):
|
||||
return session.query(TestCase).filter(
|
||||
TestCase.id == int(case_id), TestCase.is_delete == 0, TestCase.is_auto == 1
|
||||
).first()
|
||||
|
||||
@staticmethod
|
||||
def query_plan_auto_cases(session, plan_id, round_no=None, case_ids=None):
|
||||
query = session.query(PlanCase, TestCase).join(
|
||||
TestCase, PlanCase.case_id == TestCase.id
|
||||
).filter(
|
||||
PlanCase.plan_id == int(plan_id),
|
||||
TestCase.is_delete == 0,
|
||||
TestCase.is_auto == 1
|
||||
)
|
||||
if round_no not in (None, ''):
|
||||
query = query.filter(PlanCase.round_no == int(round_no))
|
||||
if case_ids:
|
||||
query = query.filter(PlanCase.case_id.in_([int(case_id) for case_id in case_ids]))
|
||||
return query.order_by(PlanCase.id.asc()).all()
|
||||
|
||||
@staticmethod
|
||||
def update_plan_case_result(session, plan_case_id, update_info):
|
||||
update_res = session.query(PlanCase).filter(PlanCase.id == int(plan_case_id)).update(update_info)
|
||||
err = session.done(close=False)
|
||||
if err:
|
||||
logger.error(f'PlanCase更新失败!id: {plan_case_id}, err: {err}')
|
||||
return 0, f'更新失败!{err}'
|
||||
if not update_res:
|
||||
return 0, '未查询到对应计划用例!'
|
||||
return int(plan_case_id), ''
|
||||
|
||||
@staticmethod
|
||||
def get_plan_by_id(session, plan_id):
|
||||
return session.query(TestPlan).filter(TestPlan.id == int(plan_id), TestPlan.is_delete == 0).first()
|
||||
@@ -56,9 +56,166 @@ class CaseDao(object):
|
||||
return CaseDao.update_by_id(session, model_cls, obj_id, {'is_delete': 1})
|
||||
|
||||
@staticmethod
|
||||
def next_case_key(session, project_id):
|
||||
count_num = session.query(func.count(TestCase.id)).filter(TestCase.project_id == int(project_id)).scalar() or 0
|
||||
return 'TC-{:03d}'.format(count_num + 1)
|
||||
def next_case_key(session, project_id, module_id=None, product_id=None):
|
||||
from ..model.productModel import Product
|
||||
from ..model.projectModel import Project
|
||||
from ..model.caseModel import Module
|
||||
|
||||
product_abbr = ''
|
||||
if product_id:
|
||||
product = session.query(Product).filter(Product.id == int(product_id), Product.is_delete == 0).first()
|
||||
if product and product.name:
|
||||
product_abbr = CaseDao._generate_abbreviation(product.name)
|
||||
|
||||
project_abbr = ''
|
||||
project = session.query(Project).filter(Project.id == int(project_id), Project.is_delete == 0).first()
|
||||
if project and project.name:
|
||||
project_abbr = CaseDao._generate_abbreviation(project.name)
|
||||
|
||||
module_abbr = ''
|
||||
if module_id:
|
||||
module = session.query(Module).filter(Module.id == int(module_id), Module.is_delete == 0).first()
|
||||
if module and module.name:
|
||||
module_abbr = CaseDao._generate_abbreviation(module.name)
|
||||
|
||||
parts = ['TC']
|
||||
if product_abbr:
|
||||
parts.append(product_abbr)
|
||||
if project_abbr:
|
||||
parts.append(project_abbr)
|
||||
if module_abbr:
|
||||
parts.append(module_abbr)
|
||||
|
||||
prefix = '-'.join(parts)
|
||||
|
||||
count_num = session.query(func.count(TestCase.id)).filter(
|
||||
TestCase.project_id == int(project_id),
|
||||
TestCase.is_delete == 0,
|
||||
TestCase.case_key.like(f'{prefix}-%')
|
||||
).scalar() or 0
|
||||
|
||||
return '{}-{:03d}'.format(prefix, count_num + 1)
|
||||
|
||||
@staticmethod
|
||||
def _generate_abbreviation(name):
|
||||
import re
|
||||
chinese_pattern = re.compile(r'[\u4e00-\u9fff]+')
|
||||
english_pattern = re.compile(r'[a-zA-Z]+')
|
||||
|
||||
chinese_chars = chinese_pattern.findall(name)
|
||||
if chinese_chars:
|
||||
full_chinese = ''.join(chinese_chars)
|
||||
abbr = ''.join([CaseDao._get_pinyin_first_char(c) for c in full_chinese[:4]])
|
||||
abbr = abbr.lower()
|
||||
if len(abbr) < 2:
|
||||
abbr = abbr.ljust(2, 'n')
|
||||
return abbr
|
||||
|
||||
english_words = english_pattern.findall(name)
|
||||
if english_words:
|
||||
abbr = english_words[0].lower()[:4]
|
||||
if len(abbr) < 2:
|
||||
abbr = abbr.ljust(2, 'x')
|
||||
return abbr
|
||||
|
||||
abbr = name.lower()[:4]
|
||||
if len(abbr) < 2:
|
||||
abbr = abbr.ljust(2, 'x')
|
||||
return abbr
|
||||
|
||||
@staticmethod
|
||||
def _get_pinyin_first_char(char):
|
||||
pinyin_map = {
|
||||
'智': 'Z', '慧': 'H', '运': 'Y', '营': 'Y',
|
||||
'报': 'B', '关': 'G', '工': 'G', '作': 'Z', '台': 'T',
|
||||
'测': 'C', '试': 'S', '用': 'Y', '例': 'L',
|
||||
'产': 'C', '品': 'P', '项': 'X', '目': 'M',
|
||||
'模': 'M', '块': 'K', '管': 'G', '理': 'L',
|
||||
'系': 'X', '统': 'T', '功': 'G', '能': 'N',
|
||||
'页': 'Y', '面': 'M', '查': 'C', '询': 'X',
|
||||
'添': 'T', '加': 'J', '编': 'B', '辑': 'J',
|
||||
'删': 'S', '除': 'C', '导': 'D', '入': 'R',
|
||||
'导': 'D', '出': 'C', '批': 'P', '量': 'L',
|
||||
'设': 'S', '置': 'Z', '配': 'P', '置': 'Z',
|
||||
'权': 'Q', '限': 'X', '角': 'J', '色': 'S',
|
||||
'用': 'Y', '户': 'H', '组': 'Z', '织': 'Z',
|
||||
'计': 'J', '划': 'H', '执': 'Z', '行': 'X',
|
||||
'报': 'B', '告': 'G', '统': 'T', '计': 'J',
|
||||
'首': 'S', '页': 'Y', '仪': 'Y', '表': 'B',
|
||||
'烟': 'Y', '冒': 'M', '回': 'H', '归': 'G',
|
||||
'集': 'J', '成': 'C', '接': 'J', '口': 'K',
|
||||
'安': 'A', '全': 'Q', '日': 'R', '志': 'Z',
|
||||
'监': 'J', '控': 'K', '优': 'Y', '化': 'H',
|
||||
'性': 'X', '能': 'N', '首': 'S', '尾': 'W',
|
||||
'开': 'K', '发': 'F', '测': 'C', '运': 'Y',
|
||||
'维': 'W', '设': 'S', '计': 'J', '研': 'Y',
|
||||
'发': 'F', '部': 'B', '组': 'Z', '个': 'G',
|
||||
'人': 'R', '公': 'G', '司': 'S', '有': 'Y',
|
||||
'限': 'X', '责': 'Z', '任': 'R', '股': 'G',
|
||||
'份': 'F', '集': 'J', '团': 'T', '科': 'K',
|
||||
'技': 'J', '网': 'W', '络': 'L', '信': 'X',
|
||||
'息': 'X', '软': 'R', '件': 'J', '系': 'X',
|
||||
'统': 'T', '解': 'J', '决': 'J', '方': 'F',
|
||||
'案': 'A', '服': 'F', '务': 'W', '支': 'Z',
|
||||
'持': 'C', '培': 'P', '训': 'X', '咨': 'Z',
|
||||
'询': 'X', '销': 'X', '售': 'S', '市': 'S',
|
||||
'场': 'C', '运': 'Y', '营': 'Y', '管': 'G',
|
||||
'理': 'L', '财': 'C', '务': 'W', '人': 'R',
|
||||
'力': 'L', '资': 'Z', '源': 'Y', '行': 'X',
|
||||
'政': 'Z', '法': 'F', '律': 'L', '合': 'H',
|
||||
'规': 'G', '质': 'Z', '量': 'L', '安': 'A',
|
||||
'全': 'Q', '环': 'H', '境': 'J', '职': 'Z',
|
||||
'能': 'N', '模': 'M', '块': 'K', '页': 'Y',
|
||||
'面': 'M', '窗': 'C', '口': 'K', '表': 'B',
|
||||
'单': 'D', '按': 'A', '钮': 'N', '链': 'L',
|
||||
'接': 'J', '图': 'T', '标': 'B', '菜': 'C',
|
||||
'单': 'D', '导': 'D', '航': 'H', '搜': 'S',
|
||||
'索': 'S', '过': 'G', '滤': 'L', '排': 'P',
|
||||
'序': 'X', '分': 'F', '页': 'Y', '导': 'D',
|
||||
'入': 'R', '导': 'D', '出': 'C', '打': 'D',
|
||||
'印': 'Y', '导': 'D', '出': 'C', '删': 'S',
|
||||
'除': 'C', '复': 'F', '制': 'Z', '粘': 'N',
|
||||
'贴': 'T', '剪': 'J', '切': 'Q', '保': 'B',
|
||||
'存': 'C', '取': 'Q', '消': 'X', '确': 'Q',
|
||||
'认': 'R', '提': 'T', '交': 'J', '审': 'S',
|
||||
'核': 'H', '批': 'P', '准': 'Z', '拒': 'J',
|
||||
'绝': 'J', '返': 'F', '回': 'H', '修': 'X',
|
||||
'改': 'G', '查': 'C', '看': 'K', '详': 'X',
|
||||
'情': 'Q', '列': 'L', '表': 'B', '统': 'T',
|
||||
'计': 'J', '图': 'T', '表': 'B', '报': 'B',
|
||||
'告': 'G', '日': 'R', '志': 'Z', '备': 'B',
|
||||
'注': 'Z', '描': 'M', '述': 'S', '名': 'M',
|
||||
'称': 'C', '编': 'B', '号': 'H', '类': 'L',
|
||||
'型': 'X', '状': 'Z', '态': 'T', '优': 'Y',
|
||||
'先': 'X', '级': 'J', '标': 'B', '签': 'Q',
|
||||
'关': 'G', '键': 'J', '词': 'C', '描': 'M',
|
||||
'述': 'S', '附': 'F', '件': 'J', '链': 'L',
|
||||
'接': 'J', '时': 'S', '间': 'J', '日': 'R',
|
||||
'期': 'Q', '数': 'S', '量': 'L', '金': 'J',
|
||||
'额': 'E', '价': 'J', '格': 'G', '数': 'S',
|
||||
'据': 'J', '库': 'K', '服': 'F', '务': 'W',
|
||||
'器': 'Q', '线': 'X', '程': 'C', '进': 'J',
|
||||
'度': 'D', '速': 'S', '度': 'D', '效': 'X',
|
||||
'率': 'L', '性': 'X', '能': 'N', '稳': 'W',
|
||||
'定': 'D', '可': 'K', '靠': 'K', '安': 'A',
|
||||
'全': 'Q', '兼': 'J', '容': 'R', '扩': 'K',
|
||||
'展': 'Z', '升': 'S', '级': 'J', '更': 'G',
|
||||
'新': 'X', '修': 'X', '补': 'B', '修': 'X',
|
||||
'复': 'F', '优': 'Y', '化': 'H', '重': 'Z',
|
||||
'构': 'G', '改': 'G', '造': 'Z', '移': 'Y',
|
||||
'植': 'Z', '集': 'J', '成': 'C', '接': 'J',
|
||||
'口': 'K', '调': 'T', '试': 'S', '测': 'C',
|
||||
'试': 'S', '验': 'Y', '证': 'Z', '确': 'Q',
|
||||
'认': 'R', '回': 'H', '归': 'G', '演': 'Y',
|
||||
'示': 'S', '培': 'P', '训': 'X', '指': 'Z',
|
||||
'导': 'D', '支': 'Z', '持': 'C', '帮': 'B',
|
||||
'助': 'Z', '反': 'F', '馈': 'K', '投': 'T',
|
||||
'诉': 'S', '建': 'J', '议': 'Y', '评': 'P',
|
||||
'独': 'D', '立': 'L', '站': 'Z', '采': 'C',
|
||||
'购': 'G', '供': 'G', '应': 'Y', '商': 'S',
|
||||
'价': 'J', '满': 'M', '意': 'Y', '度': 'D'
|
||||
}
|
||||
return pinyin_map.get(char, 'N')
|
||||
|
||||
@staticmethod
|
||||
def next_snapshot_version(session, case_id):
|
||||
|
||||
@@ -183,3 +183,23 @@ class RbacDao(object):
|
||||
def get_role_name_map(session):
|
||||
items = session.query(Role).filter(Role.is_delete == 0, Role.status == 1).all()
|
||||
return {item.id: item.name for item in items}
|
||||
|
||||
@staticmethod
|
||||
def get_menu_permission_codes(session, menu_ids):
|
||||
if not menu_ids:
|
||||
return []
|
||||
items = session.query(Menu.permission_code).filter(
|
||||
Menu.id.in_(menu_ids),
|
||||
Menu.is_delete == 0
|
||||
).all()
|
||||
return [item[0] for item in items if item[0]]
|
||||
|
||||
@staticmethod
|
||||
def get_permission_ids_by_codes(session, permission_codes):
|
||||
if not permission_codes:
|
||||
return []
|
||||
items = session.query(Permission.id).filter(
|
||||
Permission.code.in_(permission_codes),
|
||||
Permission.is_delete == 0
|
||||
).all()
|
||||
return [item[0] for item in items]
|
||||
|
||||
Reference in New Issue
Block a user