Exemplo n.º 1
0
 def delete_case_by_id(cls, case_id, user):
     obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None)
     if obj:
        obj.delete_at = datetime.datetime.utcnow()
        obj.user = user
     else:
         raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')
Exemplo n.º 2
0
 def delete_suit_by_suit_id(cls, suit_id, user):
     obj = get(n for n in TestSuit if n.id == suit_id and n.delete_at == None)
     if obj:
         obj.delete_at = datetime.datetime.utcnow()
         obj.user = user
     else:
         raise IsNotExist(title='测试套件不存在', detail=f'id为{suit_id}的测试套件不存在')
Exemplo n.º 3
0
 def copy_case_by_id(cls, case_id, user):
     obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None)
     if obj:
         TestCase(method=obj.method, path=obj.path, case=f'{obj.case}_copy', setup=obj.setup, parameters=obj.parameters,
                  body=obj.body, teardown=obj.teardown, validator=obj.validator, user=user, gitfile=obj.gitfile.id)
     else:
         raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')
Exemplo n.º 4
0
 def get_data_variable_by_env_id(cls, env_id):
     obj = get(n for n in Variable if n.env.id == env_id and n.env.delete_at == None
               and n.delete_at == None)
     if obj:
         return obj.data
     else:
         raise IsNotExist(title='环境里没有设置项目变量', detail=f'环境id为{env_id}的环境下没有找到项目变量')
Exemplo n.º 5
0
 def delete_env_by_id(cls, env_id, user):
     obj = get(n for n in Env if n.id == env_id and n.delete_at == None)
     if obj:
         obj.delete_at = datetime.datetime.utcnow()
         obj.user = user
     else:
         raise IsNotExist(title='删除的环境不存在', detail=f'环境id为{env_id}的环境不存在')
Exemplo n.º 6
0
 def get_obj_pk_by_project_id_and_file_path(cls, project_id, file_path):
     obj = get(n for n in GitFile if n.project_id == project_id
               and n.delete_at == None and n.file_path == file_path)
     if obj:
         return obj.id
     else:
         raise IsNotExist(title='获取文件不存在',
                          detail=f'项目{project_id}下的文件{file_path}不存在')
Exemplo n.º 7
0
 def get_global_variable(cls, project_id):
     obj = get(n for n in GlobalVariable
               if n.project_id == project_id and n.delete_at == None)
     if obj:
         return obj.data
     else:
         raise IsNotExist(title='全部变量不存在',
                          detail=f'repo id为{project_id}的全局变量不存在')
Exemplo n.º 8
0
 def delete(cls, script_id, user):
     obj = get(n for n in Script if n.delete_at == None and n.id == script_id)
     if obj:
         obj.user = user
         obj.delete_at = datetime.datetime.utcnow()
         return obj.script_file, obj.project_id
     else:
         raise IsNotExist(title='脚本不存在', detail=f'脚本id为{script_id}的脚本不存在')
Exemplo n.º 9
0
 def get_project_detail_by_id(cls, namespace_id, project_id):
     obj = get(
         n for n in Project
         if n.id == project_id and n.delete_at == None and n.namespace.id ==
         namespace_id and n.namespace.delete_at == None)
     if obj:
         return obj.project_content
     else:
         raise IsNotExist(title='项目不存在', detail=f'id为{project_id}的项目不存在')
Exemplo n.º 10
0
 def delete_namespace_by_id(cls, namespace_id, user):
     obj = get(n for n in Namespace
               if n.delete_at == None and n.id == namespace_id)
     if obj:
         obj.delete_at = datetime.datetime.utcnow()
         obj.user = user
     else:
         raise IsNotExist(title='Namespace不存在',
                          detail=f'id为{namespace_id}的接口不存在')
Exemplo n.º 11
0
 def update_content_by_suit_id(cls, suit_id, suit, description, suit_content, user):
     obj = get(n for n in TestSuit if n.id == suit_id and n.delete_at == None)
     if obj:
         obj.suit = suit
         obj.description = description
         obj.suit_content = suit_content
         obj.user = user
         obj.update_at = datetime.datetime.utcnow()
     else:
         raise IsNotExist(title='测试套件不存在', detail=f'id为{suit_id}的测试套件不存在')
Exemplo n.º 12
0
 def delete_project_by_id(cls, namespace_id, project_id, user):
     obj = get(
         n for n in Project
         if n.id == project_id and n.delete_at == None and n.namespace.id ==
         namespace_id and n.namespace.delete_at == None)
     if obj:
         obj.delete_at = datetime.datetime.utcnow()
         obj.user = user
     else:
         raise IsNotExist(title='项目不存在', detail=f'id为{project_id}的项目不存在')
Exemplo n.º 13
0
 def get_content_by_script_id(cls, script_id):
     obj = get(n for n in Script if n.delete_at == None and n.id == script_id)
     if obj:
         return {
             'id': obj.id,
             'script': obj.script,
             'script_file': obj.script_file,
             'description': obj.description,
             'content': obj.content
         }
     else:
         raise IsNotExist(title='脚本不存在', detail=f'脚本id为{script_id}的脚本不存在')
Exemplo n.º 14
0
 def get_content_by_suit_id(cls, suit_id):
     obj = get(n for n in TestSuit if n.id == suit_id and n.delete_at == None)
     if obj:
         return {
             'id': obj.id,
             'project_id': obj.project_id,
             'suit': obj.suit,
             'description': obj.description,
             'suit_content': obj.suit_content
         }
     else:
         raise IsNotExist(title='测试套件不存在', detail=f'id为{suit_id}的测试套件不存在')
Exemplo n.º 15
0
 def get_namespace_detail_by_id(cls, namespace_id):
     obj = get(n for n in Namespace
               if n.delete_at == None and n.id == namespace_id)
     if obj:
         return [{
             'id': obj.id,
             'name': obj.namespace,
             'description': obj.description
         }]
     else:
         raise IsNotExist(
             title='查询的namespace不存在',
             detail=f'namespace_id为{namespace_id}的namespace不存在')
Exemplo n.º 16
0
 def sync_swagger_by_id(cls, namespace_id, project_content, swagger_json,
                        user, project_id):
     obj = get(
         n for n in Project
         if n.delete_at == None and n.id == project_id and n.namespace.id ==
         namespace_id and n.namespace.delete_at == None)
     if obj:
         obj.project_content = project_content
         obj.swagger_json = swagger_json
         obj.user = user
         obj.update_at = datetime.datetime.utcnow()
     else:
         raise IsNotExist(title='项目不存在', detail=f'id为{project_id}的项目不存在')
Exemplo n.º 17
0
 def retag_project_by_id(cls, namespace_id, project_id, new_tag, user):
     obj = get(
         n for n in Project
         if n.id == project_id and n.delete_at == None and n.namespace.id ==
         namespace_id and n.namespace.delete_at == None)
     if obj:
         content = obj.project_content
         content['tag'] = new_tag
         obj.project_content = content
         obj.user = user
         obj.update_at = datetime.datetime.utcnow()
     else:
         raise IsNotExist(title='项目不存在', detail=f'id为{project_id}的项目不存在')
Exemplo n.º 18
0
 def get_case_content_by_id(cls, case_id):
     obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None)
     if obj:
         return {
             'case': obj.case,
             'method': obj.method,
             'path': obj.path,
             'description': obj.description,
             'setup': obj.setup,
             'parameters': obj.parameters,
             'body': obj.body,
             'teardown': obj.teardown,
             'validator': obj.validator,
         }
     else:
         raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')
Exemplo n.º 19
0
    def update(cls, namespace_id, env_id, env, url, description, user):
        obj = get(n for n in Env if n.env == env and n.delete_at == None and
                  n.namespace.id == namespace_id and n.namespace.delete_at == None)
        if obj:
            raise IsExist(title='修改的环境名已经存在', detail=f'{env}已经存在, uuid为{obj.uid}')

        obj = get(n for n in Env if n.id == env_id and n.delete_at == None and
                  n.namespace.id == namespace_id and n.namespace.delete_at == None)
        if obj:
            obj.env = env
            obj.url = url
            obj.description = description
            obj.update_at = datetime.datetime.utcnow()
            obj.user = user
        else:
            raise IsNotExist(title='修改的环境不存在', detail=f'id为{env_id}的环境不存在')
Exemplo n.º 20
0
 def get_obj_by_project_id_and_file_path_and_update_content(
         cls, project_id, file_path, blob_id, commit_id, last_commit_id,
         content, user):
     obj = get(n for n in GitFile if n.project_id == project_id
               and n.delete_at == None and n.file_path == file_path)
     if obj:
         if obj.blob_id != blob_id:
             obj.blob_id = blob_id
             obj.commit_id = commit_id
             obj.last_commit_id = last_commit_id
             obj.content = content
             obj.user = user
             obj.update_at = datetime.datetime.utcnow()
         return obj.id
     else:
         raise IsNotExist(title='获取文件不存在',
                          detail=f'项目{project_id}下的文件{file_path}不存在')
Exemplo n.º 21
0
    @classmethod
    @db_session
    def update(cls, case_id, case, description, setup, parameters, body, teardown, validator, user):
        obj = get(n for n in TestCase if n.id == case_id and n.delete_at == None)
        if obj:
            obj.case = case
            obj.description = description
            obj.setup = setup
            obj.parameters = parameters
            obj.body = body
            obj.teardown = teardown
            obj.validator = validator
            obj.user = user
            obj.update_at = datetime.datetime.utcnow()
        else:
            raise IsNotExist(title='测试用例不存在', detail=f'id为{case_id}的测试用例不存在')

    @classmethod
    @db_session
    def get_case_list_by_git_file_id(cls, file_id, method, path):
        case_list = []
        objs = select(n for n in TestCase if n.gitfile.id == file_id and n.delete_at == None and
                      n.method == method and n.path == path)
        for obj in objs:
            tmp_dict = {
                'id': obj.id,
                'case': obj.case,
                'description': obj.description
            }
            case_list.append(tmp_dict)
        return case_list
Exemplo n.º 22
0
 def get_project_id_by_env_id(cls, env_id):
     obj = get(n for n in Env if n.id == env_id and n.delete_at == None)
     if obj:
         return obj.gitfile.project_id
     else:
         raise IsNotExist(title='查询的环境不存在', detail=f'环境id为{env_id}的环境不存在')