示例#1
0
def bat_del(request):
    #批量删除用例
    test_list = request.body.decode('utf-8').split('&')
    for index in test_list:
        id = index.split('=')[1]
        del_test_data(id)
    return HttpResponseRedirect('/api/test_list/1/')
def config_list(request, id):
    if request.session.get('login_status'):
        if request.is_ajax():
            try:
                test_info = json.loads(request.body.decode('utf-8'))
            except ValueError:
                logging.error(
                    '配置信息解析异常:{test_info}'.format(test_info=test_info))
                return HttpResponse('配置信息解析异常')
            if 'mode' in test_info.keys():
                msg = del_test_data(test_info.pop('id'))
            return HttpResponse(get_ajax_msg(msg, 'ok'))
        else:
            filter_query = set_filter_session(request)
            test_list = get_pager_info(TestCaseInfo, filter_query,
                                       '/api/config_list/', id)
            manage_info = {
                'account': request.session["now_account"],
                'test': test_list[1],
                'page_list': test_list[0],
                'info': filter_query
            }
            return render_to_response('config_list.html', manage_info)
    else:
        return HttpResponseRedirect("/api/login/")
示例#3
0
def config_list(request, id):
    """
    配置列表
    :param request:
    :param id: str or int:当前页
    :return:
    """
    account = request.session["now_account"]
    if request.is_ajax():
        test_info = json.loads(request.body.decode('utf-8'))

        if test_info.get('mode') == 'del':
            msg = del_test_data(test_info.pop('id'))
        elif test_info.get('mode') == 'copy':
            msg = copy_test_data(test_info.get('data').pop('index'), test_info.get('data').pop('name'))
        return HttpResponse(get_ajax_msg(msg, 'ok'))
    else:
        filter_query = set_filter_session(request)
        test_list = get_pager_info(
            TestCaseInfo, filter_query, '/api/config_list/', id)
        manage_info = {
            'account': account,
            'test': test_list[1],
            'page_list': test_list[0],
            'info': filter_query,
            'project': ProjectInfo.objects.all().order_by('-update_time')
        }
        return render_to_response('config_list.html', manage_info)
示例#4
0
def config_list(request, id):
    """
    配置列表
    :param request:
    :param id: str or int:当前页
    :return:
    """
    if request.session.get('login_status'):
        acount = request.session["now_account"]
        if request.is_ajax():
            try:
                test_info = json.loads(request.body.decode('utf-8'))
            except ValueError:
                logging.error('配置信息解析异常:{test_info}'.format(test_info=test_info))
                return HttpResponse('配置信息解析异常')
            if test_info.get('mode') == 'del':
                msg = del_test_data(test_info.pop('id'))
            elif test_info.get('mode') == 'copy':
                msg = copy_test_data(test_info.get('data').pop('index'), test_info.get('data').pop('name'))
            return HttpResponse(get_ajax_msg(msg, 'ok'))
        else:
            filter_query = set_filter_session(request)
            test_list = get_pager_info(
                TestCaseInfo, filter_query, '/api/config_list/', id)
            manage_info = {
                'account': acount,
                'test': test_list[1],
                'page_list': test_list[0],
                'info': filter_query
            }
            return render_to_response('config_list.html', manage_info)
    else:
        return HttpResponseRedirect("/api/login/")
示例#5
0
def test_list(request, id):
    """
    用例列表
    :param request:
    :param id: str or int:当前页
    :return:
    """

    account = request.session["now_account"]
    if request.is_ajax():
        test_info = json.loads(request.body.decode('utf-8'))
        if test_info.get('mode') == 'del':
            msg = del_test_data(test_info.pop('id'))
            return HttpResponse(get_ajax_msg(msg, 'ok'))
        if test_info.get('mode') == 'copy':
            msg = copy_test_data(
                test_info.get('data').pop('index'),
                test_info.get('data').pop('name'))
            return HttpResponse(get_ajax_msg(msg, 'ok'))

        # 新增ajax(查询用例)逻辑处理
        filter_query = set_filter_session(request)
        test_list = get_pager_info(TestCaseInfo, filter_query,
                                   '/api/test_list/', id)
        result_list = list()
        results = serializers.serialize('json',
                                        test_list[1],
                                        ensure_ascii=False)  # 数据库对象转化json
        result = [result.get('fields')
                  for result in json.loads(results)]  # 提取数据库字段
        testcase_id = [i.get('pk') for i in json.loads(results)]
        for num, i in enumerate(result):  # 将id字段添加到字段中
            i['id'] = testcase_id[num]
            i['url'] = convert_eval_url(i.get('request'))
            i['belong_module_name'] = ModuleInfo.objects.get_module_name(
                i.get('belong_module'), type=False).module_name
        result_list.append(result)
        result_list.append(str(test_list[0]))
        return JsonResponse(result_list, safe=False)

    else:
        filter_query = set_filter_session(request)
        test_list = get_pager_info(TestCaseInfo, filter_query,
                                   '/api/test_list/', id)
        # 获取被引用用例id列表
        manage_info = {
            'account': account,
            'test': test_list[1],
            'page_list': test_list[0],
            'info': filter_query,
            'env': EnvInfo.objects.all().order_by('-create_time'),
            'project': ProjectInfo.objects.all().order_by('-update_time')
        }
        return render_to_response('test_list.html', manage_info)
示例#6
0
def test_list(request, id):
    """
    用例列表
    :param request:
    :param id: str or int:当前页
    :return:
    """

    account = request.session["now_account"]
    user_type = request.session['user_type']
    if request.is_ajax():
        test_info = json.loads(request.body.decode('utf-8'))

        if test_info.get('mode') == 'del':
            msg = del_test_data(test_info.pop('id'), account, user_type)
        elif test_info.get('mode') == 'copy':
            msg = copy_test_data(test_info.get('data').pop('index'), test_info.get('data').pop('name'), account)
        return HttpResponse(get_ajax_msg(msg, 'ok'))

    else:
        filter_query = set_filter_session(request)

        if 'case_id' in request.POST.keys():
            filter_query['case_id'] = request.POST.get('case_id')
        if 'service_name' in request.POST.keys():
            filter_query['service_name'] = request.POST.get('service_name')

        test_list = get_pager_info(
            TestCaseInfo, filter_query, '/api/test_list/', id)
        manage_info = {
            'account': account,
            'test': test_list[1],
            'page_list': test_list[0],
            'info': filter_query,
            'env': EnvInfo.objects.all().order_by('-create_time'),
            'projects': ProjectInfo.objects.all().order_by('-update_time')
        }

        # 添加模块下拉
        modules = []
        if filter_query.get('belong_project') != 'All':
            modules = ModuleInfo.objects.filter(
                belong_project__project_name=filter_query.get('belong_project')).order_by('-create_time')

        manage_info['modules'] = modules

        return render_to_response('test_list.html', manage_info)
示例#7
0
def test_list(request, id):
    """
    用例列表
    :param request:
    :param id: str or int:当前页
    :return:
    """
    if request.session.get('login_status'):
        account = request.session["now_account"]
        if request.is_ajax():
            test_info = json.loads(request.body.decode('utf-8'))

            if test_info.get('mode') == 'del':
                msg = del_test_data(test_info.pop('id'))
            elif test_info.get('mode') == 'copy':
                msg = copy_test_data(
                    test_info.get('data').pop('index'),
                    test_info.get('data').pop('name'))
            return HttpResponse(get_ajax_msg(msg, 'ok'))

        else:
            filter_query = set_filter_session(request)

            if request.POST.get('level') is not None:
                filter_query['level'] = request.POST.get('level')

            test_list = get_pager_info(TestCaseInfo, filter_query,
                                       '/api/test_list/', id)
            manage_info = {
                'account': account,
                'test': test_list[1],
                'page_list': test_list[0],
                'info': filter_query,
                'env': EnvInfo.objects.all().order_by('-create_time')
            }
            return render_to_response('test_list.html', manage_info)
    else:
        return HttpResponseRedirect("/api/login/")