def delete(case_id): try: testcase.delete_testcase_by_id(case_id, g.username) except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'删除测试用例异常', detail=f'{e}')
def sync(project_id): try: pass except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'同步swagger异常', detail=f'{e}')
def content(case_id): try: content = testcase.get_content_by_case_id(case_id) return {'case_id': case_id, 'content': content} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取测试用例内容异常', detail=f'{e}')
def update(script_id, body): try: script.update_script_content_by_script_id(script_id, body, g.username) return {'title': '更新脚本成功', 'detail': '更新脚本成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'更新脚本异常', detail=f'{e}')
def create(project_id, body): try: script.create_script(project_id, body, g.username) return {'title': '创建脚本成功', 'detail': '创建脚本成功'} except IsExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'创建脚本异常', detail=f'{e}')
def update(suit_id, body): try: testsuit.update_testsuit_content_by_suit_id(suit_id, body, g.username) return {'title': '更新测试套件成功', 'detail': '更新测试套件成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'更新测试套件异常', detail=f'{e}')
def update(case_id, body): try: testcase.update_testcase(case_id, body, g.username) return {'title': '更新测试用例成功', 'detail': '更新测试用例成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'更新测试用例异常', detail=f'{e}')
def content(script_id): try: data = script.get_content_by_script_id(script_id) return {'data': data} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取脚本详情异常', detail=f'{e}')
def create(project_id, file_path, ref, body): try: env.create_env(project_id, file_path, ref, body, g.username) return {'title': '创建环境成功', 'detail': '创建环境成功'} except IsExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'创建环境异常', detail=f'{e}')
def delete(env_id): try: env.delete_env_by_id(env_id, g.username) return {'title': '删除环境成功', 'detail': '删除环境成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'删除环境异常', detail=f'{e}')
def content(suit_id): try: data = testsuit.get_testsuit_content_by_suit_id(suit_id) return {'data': data} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取测试套件异常', detail=f'{e}')
def delete(script_id): try: script.delete_script_by_script_id(script_id, g.username) return {'title': '删除脚本成功', 'detail': '删除脚本成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'删除脚本异常', detail=f'{e}')
def run(suit_id): try: report_path = testsuit.run_testsuit_by_suit_id(suit_id, g.username) return {'data': {'report_path': report_path}} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'运行测试套件异常', detail=f'{e}')
def delete(suit_id): try: testsuit.delete_testsuit_by_suit_id(suit_id, g.username) return {'title': '删除测试套件成功', 'detail': '删除测试套件成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取测试套件异常', detail=f'{e}')
def copy(case_id): try: testcase.copy_case_by_id(case_id, g.username) return {'title': '复制测试用例成功', 'detail': '复制测试用例成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'复制测试用例异常', detail=f'{e}')
def run(case_id, env_id): try: results = testcase.run_test_case(case_id, env_id) return results except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'执行测试用例异常', detail=f'执行id为{case_id}的测试用例异常:{e}')
def globalvar(project_id): try: data = variable.get_global_variable_by_id(project_id) return { 'data': data } except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'更新全局变量异常', detail=f'{e}')
def create(project_id, body): try: testsuit.create_testsuit(project_id=project_id, body=body, user=g.username) return {'title': '创建测试套件成功', 'detail': '创建测试套件成功'} except IsExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'创建测试套件异常', detail=f'{e}')
def list(project_id, file_path, ref, method, path): try: token = connexion.request.headers.get('Authorization') case_list = testcase.get_testcase_list_by_method_and_path( project_id, file_path, ref, method, path, token, g.username) return {'data': case_list} except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取测试用例列表异常', detail=f'{e}')
def list(env_id): try: data = variable.get_project_variable_by_env(env_id) return { 'data': data } except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'获取项目变量列表异常', detail=f'{e}')
def create(project_id, file_path, method, path, body): try: testcase.create_testcase(project_id, file_path, method, path, body, user=g.username) return {'title': '创建测试用例成功', 'detail': '创建测试用例成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}') except Exception as e: raise DefalutError(title=f'创建测试用例异常', detail=f'{e}')
def url(body): try: namespace_id = connexion.request.headers.get('namespace') swagger.import_swagger_by_url(namespace_id, body, g.username) return { 'title': '导入swagger成功', 'detail': '导入swagger成功' } except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'导入swagger异常', detail=f'{e}')
def login(body): ''' API接口 :param body: 登陆用户的内容 :return: 返回登陆的结果 ''' try: auth = user.login(body) return {'title': '登陆成功', 'detail': '登陆成功', 'auth': auth}, 200 except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'登陆异常', detail=f'{e}')
def register(body): ''' API接口 :param body: 注册用户的内容 :return: 返回注册的结果 ''' try: user.register(body) return {'title': '注册用户成功', 'detail': '注册用户成功'} except IsExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'注册用户异常', detail=f'{e}')
def detail(project_id): ''' API接口:获取项目的详情 :param project_id: 获取项目详情的id :return: 指定项目的详情 ''' try: namespace_id = connexion.request.headers.get('namespace') return project.project_detail(namespace_id, project_id) except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'获取项目详情异常', detail=f'{e}')
def deletes(ids): ''' :param ids: 删除项目id的列表 :return: ''' try: namespace_id = connexion.request.headers.get('namespace') project.deltet_projects_by_ids_list(namespace_id, ids, g.username) return {'title': '删除项目成功', 'detail': '删除项目成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'删除多个项目异常', detail=f'{e}')
def create(body): ''' API接口: 创建项目 :param body: 创建项目的body :return: ''' try: namespace_id = connexion.request.headers.get('namespace') data = project.create_project(namespace_id, body, g.username) return {'data': data} except DefalutError as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'创建项目异常', detail=f'{e}')
def delete(project_id): ''' API接口: 删除项目 :param project_id: 删除项目的id :return: ''' try: namespace_id = connexion.request.headers.get('namespace') project.delete_project(namespace_id, project_id, g.username) return {'title': '删除项目成功', 'detail': '删除项目成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'删除项目详情异常', detail=f'{e}')
def create(body): ''' API接口:创建环境 :param body: 创建环境的body :return: ''' try: namespace_id = connexion.request.headers.get('namespace') env.create_env(namespace_id, body, g.username) return {'title': '创建环境成功'} except IsExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'创建环境异常', detail=f'{e}')
def delete(env_id): ''' API接口: 删除指定的环境 :param env_id: 被删除环境的id :return: ''' try: namespace_id = connexion.request.headers.get('namespace') env.delet_env(namespace_id, env_id, g.username) return {'title': '删除环境成功'} except IsNotExist as e: raise DefalutError(title=f'{e.title}', detail=f'{e.detail}', type=f'{e.type}') except Exception as e: raise DefalutError(title=f'删除环境异常', detail=f'{e}')