Пример #1
0
def module_list(request):
    if request.method == 'GET':
        return render(request, 'api/module_list.html')
    elif request.method == 'POST':
        index = int(request.POST.get('index'))
        project_name_dic = {}
        # 根据用户权限筛选模块
        objects = filter_modules_for_user(request.user,
                                          ModuleInfo.objects.order_by('-id'),
                                          AUTH_VIEW)
        modules = pagination_for_objects(objects, index)
        if modules is not None and len(modules) > 0:
            for module in modules:
                project_id = module.belong_project_id
                project_name = module.belong_project.project_name
                project_name_dic[str(project_id)] = project_name
        count = len(objects)
        data = dataToJson([model_to_dict(i) for i in modules])
        return JsonResponse(
            get_ajax_msg(
                1, 1, '获取模块列表成功', {
                    'modules': data,
                    'count': count,
                    'currPage': index,
                    'proInfo': project_name_dic
                }))
Пример #2
0
def task_list(request):
    if request.method == "GET":
        return render(request, 'api/task_list.html')
    elif request.method == "POST":
        index = int(request.POST.get('index'))
        env_name_dic = {}
        project_name_dic = {}
        module_name_dic = {}
        results = filter_tasks_for_user(
            request.user,
            TaskInfo.objects.filter().order_by('-id'), AUTH_VIEW)
        tasks = pagination_for_objects(results, index)
        if tasks is not None and len(tasks) > 0:
            for task in tasks:
                append_env_dict(task, env_name_dic)
                append_project_dict(task, project_name_dic)
                append_module_dict(task, module_name_dic)
        count = len(results)
        task_info_list = []
        for task in tasks:
            task_dict = task2Dict(task)
            task_info_list.append(task_dict)

        data = dataToJson(task_info_list)
        return JsonResponse(
            get_ajax_msg(
                1, 1, '获取任务列表成功', {
                    'tasks': data,
                    'count': count,
                    'currPage': index,
                    'envInfo': env_name_dic,
                    'proInfo': project_name_dic,
                    'moduleInfo': module_name_dic
                }))
Пример #3
0
def project_search(request):
    if request.method == "POST":
        project_name = request.POST.get('project_name')
        person_name = request.POST.get('person_name')
        index = int(request.POST.get('index'))
        if len(project_name) == 0 and len(person_name) == 0:
            return JsonResponse(get_ajax_msg(0, 0, '搜索条件无效'))
        else:
            projects = ProjectInfo.objects.all()
            if len(project_name) > 0:
                projects = projects.filter(project_name__contains=project_name)
            if len(person_name) > 0:
                projects = projects.filter(
                    responsible_name__contains=person_name)
        if projects is None:
            return JsonResponse(get_ajax_msg(0, 0, '查询出错'))
        objects = get_objects_for_user(request.user, AUTH_VIEW,
                                       projects)  # 根据用户权限筛选项目对象
        projects = pagination_for_objects(objects, index)
        count = objects.count()
        data = dataToJson([model_to_dict(i) for i in projects])
        return JsonResponse(
            get_ajax_msg(1, 1, '搜索成功', {
                'projects': data,
                'count': count,
                'currPage': index
            }))
Пример #4
0
def module_search(request):
    if request.method == 'POST':
        # 当要搜索某个项目下的模块时,可通过传入项目id进行获取
        project_id = request.POST.get('project_id')
        if project_id != None:
            modules = ModuleInfo.objects.all().filter(
                belong_project_id=project_id)
            count = modules.count()
            data = dataToJson([model_to_dict(i) for i in modules])
            return JsonResponse(
                get_ajax_msg(1, 1, '搜索成功', {
                    'modules': data,
                    'count': count
                }))

        index = int(request.POST.get('index'))
        project_name = request.POST.get('project_name')
        module_name = request.POST.get('module_name')
        test_person = request.POST.get('test_person')
        project_name_dic = {}
        if len(project_name) == 0 and len(module_name) == 0 and len(
                test_person) == 0:
            return JsonResponse(get_ajax_msg(0, 0, '搜索条件无效'))
        else:
            modules = ModuleInfo.objects.all()
            if len(project_name) != 0 and project_name != '项目名称':
                modules = modules.filter(
                    belong_project__project_name__contains=project_name)
            if len(module_name) != 0:
                modules = modules.filter(module_name__contains=module_name)
            if len(test_person) != 0:
                modules = modules.filter(test_user__contains=test_person)
        if modules is None:
            return JsonResponse(get_ajax_msg(0, 0, '查询出错'))
        if modules is not None and len(modules) > 0:
            modules = filter_modules_for_user(request.user,
                                              modules.order_by('-id'),
                                              AUTH_VIEW)  # 根据用户权限筛选模块
            for module in modules:
                proID = module.belong_project_id
                proName = module.belong_project.project_name
                project_name_dic[str(proID)] = proName
        count = len(modules)
        modules = pagination_for_objects(modules, index)
        data = dataToJson([model_to_dict(i) for i in modules])
        return JsonResponse(
            get_ajax_msg(
                1, 1, '搜索成功', {
                    'modules': data,
                    'count': count,
                    'currPage': index,
                    'proInfo': project_name_dic
                }))
Пример #5
0
def task_search(request):
    if request.method == 'POST':
        index = int(request.POST.get('index'))
        task_name = request.POST.get('task_name')
        project_name = request.POST.get('project_name')
        module_name = request.POST.get('module_name')
        tasks = None
        env_name_dic = {}
        project_name_dic = {}
        module_name_dic = {}
        count = 0
        if len(task_name) == 0 and len(project_name) == 0 and len(
                module_name) == 0:
            return JsonResponse(get_ajax_msg(0, 0, '搜索条件无效'))
        else:
            tasks = TaskInfo.objects.all()
            if len(module_name) != 0 and module_name != '模块名称':
                tasks = tasks.filter(
                    belong_module__module_name__contains=module_name)
            if len(project_name) != 0 and project_name != '项目名称':
                tasks = tasks.filter(
                    belong_project__project_name__contains=project_name)
            if len(task_name) != 0:
                tasks = tasks.filter(task_name__contains=task_name)
        if tasks == None:
            return JsonResponse(get_ajax_msg(0, 0, '查询出错'))
        if tasks != None and len(tasks) > 0:
            tasks = filter_tasks_for_user(request.user, tasks.order_by('-id'),
                                          AUTH_VIEW)  # 根据用户权限筛选模块
            for task in tasks:
                append_env_dict(task, env_name_dic)
                append_project_dict(task, project_name_dic)
                append_module_dict(task, module_name_dic)
        count = len(tasks)
        tasks = pagination_for_objects(tasks, index)
        task_info_list = []
        for task in tasks:
            task_dict = task2Dict(task)
            task_info_list.append(task_dict)

        data = dataToJson(task_info_list)
        return JsonResponse(
            get_ajax_msg(
                1, 1, '搜索成功', {
                    'tasks': data,
                    'count': count,
                    'currPage': index,
                    'envInfo': env_name_dic,
                    'proInfo': project_name_dic,
                    'moduleInfo': module_name_dic
                }))
Пример #6
0
def project_list(request):
    if request.method == "GET":
        return render(request, 'api/project_list.html')
    elif request.method == "POST":
        index = int(request.POST.get('index'))
        objects = get_objects_for_user(request.user, AUTH_VIEW).all()
        projects = pagination_for_objects(objects, index)
        count = objects.count()
        data = dataToJson([model_to_dict(i) for i in projects])
        return JsonResponse(
            get_ajax_msg(1, 1, '获取工程列表成功', {
                'projects': data,
                'count': count,
                'currPage': index
            }))
Пример #7
0
def case_list(request):
    if request.method == "GET":
        # 拼装项目信息返回前端使用(编辑用例的模态框内使用)
        projects = ProjectInfo.objects.all().order_by('id')
        context = {}
        context['projects'] = []
        for project in projects:
            context['projects'].append({
                'project_name': project.project_name,
                'project_id': project.id
            })
        return render(request, 'api/case_list.html', context)
    elif request.method == 'POST':
        index = int(request.POST.get('index'))
        project_name_dic = {}
        module_name_dic = {}
        # 根据用户权限筛选用例
        results = filter_cases_for_user(
            request.user,
            TestCaseInfo.objects.filter().order_by('-id'), AUTH_VIEW)
        cases = pagination_for_objects(results, index)

        if cases is not None and len(cases) > 0:
            for case in cases:
                # 所属模块id对应模块名称
                module_id = case.belong_module_id
                module_name = case.belong_module.module_name
                module_name_dic[str(module_id)] = module_name
                # 所属模块id对应项目名称
                project_name = case.belong_module.belong_project.project_name
                project_name_dic[str(module_id)] = project_name
        count = len(results)
        tempData = [model_to_dict(i) for i in cases]
        del_fields(tempData, [
            'variables', 'parameters', 'hooks', 'url', 'request_data',
            'headers', 'extract', 'validate', 'include'
        ])
        data = dataToJson(tempData)
        return JsonResponse(
            get_ajax_msg(
                1, 1, '获取用例列表成功', {
                    'cases': data,
                    'count': count,
                    'currPage': index,
                    'proInfo': project_name_dic,
                    'moduleInfo': module_name_dic
                }))
Пример #8
0
def env_list(request):
    if request.method == "GET":
        return render(request, 'api/environment_manage.html')
    elif request.method == "POST":
        index = int(request.POST.get('index'))
        objects = EnvInfo.objects.filter().order_by('-id')
        envs = pagination_for_objects(objects, index)

        project_id_to_name = {}
        count = objects.count()
        for env in envs:
            project_id_to_name[
                env.belong_project_id] = env.belong_project.project_name
        data = dataToJson([model_to_dict(i) for i in envs])
        return JsonResponse(
            get_ajax_msg(
                1, 1, '获取环境列表成功', {
                    'envs': data,
                    'count': count,
                    'currPage': index,
                    'id_to_name': project_id_to_name
                }))
Пример #9
0
def case_search(request):
    if request.method == 'POST':
        # 当要搜索某个模块下的用例时,可通过传入模块id进行获取
        module_id = request.POST.get('module_id')
        if module_id != None:
            cases = TestCaseInfo.objects.all().filter(
                belong_module_id=module_id)
            count = cases.count()
            data = dataToJson([model_to_dict(i) for i in cases])
            return JsonResponse(
                get_ajax_msg(1, 1, '搜索成功', {
                    'cases': data,
                    'count': count
                }))
        index = int(request.POST.get('index'))
        project_name = request.POST.get('project_name', '')
        module_name = request.POST.get('module_name', '')
        case_name = request.POST.get('case_name', '')
        author = request.POST.get('author', '')
        project_name_dic = {}
        module_name_dic = {}
        if len(project_name) == 0 and len(module_name) == 0 and len(
                case_name) == 0 and len(author) == 0:
            return JsonResponse(get_ajax_msg(0, 0, '搜索条件无效'))
        else:
            cases = TestCaseInfo.objects.all()
            if len(module_name) != 0 and module_name != '模块名称':
                cases = cases.filter(
                    belong_module__module_name__contains=module_name)
            if len(project_name) != 0 and project_name != '项目名称':
                cases = cases.filter(
                    belong_module__belong_project__project_name__contains=
                    project_name)
            if len(case_name) != 0:
                cases = cases.filter(name__contains=case_name)
            if len(author) != 0:
                cases = cases.filter(author__contains=author)
        if cases is None:
            return JsonResponse(get_ajax_msg(0, 0, '查询出错'))
        if cases is not None and len(cases) > 0:
            cases = filter_cases_for_user(request.user, cases.order_by('-id'),
                                          AUTH_VIEW)  # 根据用户权限筛选用例
            for case in cases:
                # 所属模块id对应模块名称
                module_id = case.belong_module_id
                module_name = case.belong_module.module_name
                module_name_dic[str(module_id)] = module_name
                # 所属模块id对应项目名称
                project_name = case.belong_module.belong_project.project_name
                project_name_dic[str(module_id)] = project_name
        count = len(cases)
        cases = pagination_for_objects(cases, index)
        tempData = [model_to_dict(i) for i in cases]
        del_fields(tempData, [
            'variables', 'parameters', 'hooks', 'url', 'request_data',
            'headers', 'extract', 'validate', 'include'
        ])
        data = dataToJson(tempData)
        return JsonResponse(
            get_ajax_msg(
                1, 1, '搜索成功', {
                    'cases': data,
                    'count': count,
                    'currPage': index,
                    'proInfo': project_name_dic,
                    'moduleInfo': module_name_dic
                }))