def edit_case(self, name, info, url, method, submit, header, data, deal, condition, expect, assertion, type): old_case = Case(self.case_group, self.name, self.info, self.url, self.method, self.submit, self.header, self.data, self.deal, self.condition, self.expect, self.assertion, self.type) old_case.id = self.id if self.name != name: if Case.query.filter_by(name=name, case_group=self.case_group, delete_time=None).first(): raise ParameterException(msg='当前组已存在同名用例,请更改用例名称') # 用例名称暂时不允许修改 # self.name = name self.info = info self.url = url self.method = CaseMethodEnum(method) self.submit = CaseSubmitEnum(submit) self.header = header self.data = data self.deal = CaseDealEnum(deal) self.condition = condition self.expect = expect self.assertion = CaseAssertEnum(assertion) self.type = CaseTypeEnum(type) self.update_user = get_current_user().id db.session.commit() self.edit_log(old_case)
def __init__(self, project_id, order, case_id, name, is_run=True, info=None, url=None, method=1, submit=1, header=None, data=None, deal=1, condition=None, expect=None, assertion=1, case_type=1): super().__init__() self.project_id = project_id self.order = order self.case_id = case_id self.name = name self.is_run = is_run self.info = info self.url = url self.method = CaseMethodEnum(method) self.submit = CaseSubmitEnum(submit) self.header = header self.data = data self.deal = CaseDealEnum(deal) self.condition = condition self.expect = expect self.assertion = CaseAssertEnum(assertion) self.type = CaseTypeEnum(case_type)
def __init__(self, case_group, name=None, info=None, url=None, method=1, submit=1, header=None, data=None, deal=1, condition=None, expect=None, assertion=1, case_type=1): super().__init__() self.name = name self.info = info self.url = url self.method = CaseMethodEnum(method) self.submit = CaseSubmitEnum(submit) self.header = header self.data = data self.deal = CaseDealEnum(deal) self.condition = condition self.expect = expect self.assertion = CaseAssertEnum(assertion) self.type = CaseTypeEnum(case_type) self.case_group = case_group self.create_user = get_current_user().id if get_current_user( ) else None self.update_user = get_current_user().id if get_current_user( ) else None self.actual_result = False self.reason = None self.result = {}
def enum_type(): form = EnumTypeForm().validate_for_api() if form.type.data == 'METHOD': return CaseMethodEnum.data() elif form.type.data == 'SUBMIT': return CaseSubmitEnum.data() elif form.type.data == 'DEAL': return CaseDealEnum.data() elif form.type.data == 'TYPE': return CaseTypeEnum.data() elif form.type.data == 'ASSERT': return CaseAssertEnum.data() else: return { 'METHOD': CaseMethodEnum.data(), 'SUBMIT': CaseSubmitEnum.data(), 'DEAL': CaseDealEnum.data(), 'TYPE': CaseTypeEnum.data(), 'ASSERT': CaseAssertEnum.data(), }
def updateConfig(self, url, method, submit, header, data, deal, condition, expect, assertion): try: self.url = url self.method = CaseMethodEnum(method) self.submit = CaseSubmitEnum(submit) self.header = header self.data = data self.deal = CaseDealEnum(deal) self.condition = condition self.expect = expect self.assertion = CaseAssertEnum(assertion) db.session.commit() except Exception: db.session.rollback() raise UnknownException(msg='修改配置异常')
def write_case_excel(cls, cases, file_path): excel = OperationExcel(file_path) excel.get_sheet_write() for row in range(len(cases)): for col in range(len(cases[row])): if col == CaseExcelEnum.METHOD.value: excel.write_execel(row + 1, col, CaseMethodEnum(cases[row][col]).name) elif col == CaseExcelEnum.SUBMIT.value: excel.write_execel(row + 1, col, CaseSubmitEnum(cases[row][col]).name) elif col == CaseExcelEnum.DEAL.value: excel.write_execel(row + 1, col, CaseDealEnum(cases[row][col]).name) elif col == CaseExcelEnum.ASSERTION.value: excel.write_execel(row + 1, col, CaseAssertEnum(cases[row][col]).name) else: excel.write_execel(row + 1, col, cases[row][col]) excel.write_save()
def deal(self): return CaseDealEnum(self._deal).value
def log(case, project, task, user): case_log = { 'id': case.id, 'case_group': case.case_group, 'case_group_name': case.case_group_name, 'name': case.name, 'actual_result': case.actual_result, 'assertion_text': CaseAssertEnum.data()[case.assertion], 'assertion': case.assertion, 'condition': case.condition, 'create_time': task.create_time, # celery 中获取不到当前用户 只能从dealy传入 'create_user': user.id, 'username': user.username, 'data': case.data, 'deal_text': CaseDealEnum.data()[case.deal], 'deal': case.deal, 'expect': case.expect, 'header': case.header, 'info': case.info, 'method_text': CaseMethodEnum.data()[case.method], 'method': case.method, 'reason': case.reason, 'submit_text': CaseSubmitEnum.data()[case.submit], 'submit': case.submit, 'type': CaseTypeEnum.data()[case.type], 'url': case.url, 'result': case.result, 'project_id': project.id, 'project_name': project.name, 'project_type': project.type,