示例#1
0
def case_run(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'POST':
            data = {}
            data['uri_params_value'] = None
            for key in request.POST:
                if strClean(request.POST.get(key)) != '':
                    data[key] = strClean(request.POST.get(key))
                elif key in ['host', 'path']:
                    return HttpResponse(key)

            url = common.urlHandle(host=data['host'],
                                   path=data['path'],
                                   uri_params_value=data['uri_params_value'])
            if url == 'uri参数个数不匹配':
                return HttpResponse('uri参数个数不匹配')
            data['url'] = url
            case_list = []
            case_list.append(data)
            res = common.runTest(case_list)
            if type(res) is str:
                return HttpResponse(res)
            else:
                return JsonResponse(res[0][0])
    else:
        return HttpResponseRedirect('/')
示例#2
0
def task_query(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'GET':
            page = request.GET.get('page')
            limit = request.GET.get('limit')
            query_str = request.GET.get('query_str')
            sql = "SELECT * FROM pro_task WHERE state=1 "

            if query_str is not None and strClean(query_str) != '':
                query_str = strClean(query_str)
                sql += " AND (task_id like'{query_str}' or task_name LIKE'%{query_str}%')".format(
                    query_str=query_str)
            contact_list = MySQLEngine('pro_task').defined(type='query',
                                                           sql=sql)
            paginator = Paginator(contact_list,
                                  limit)  # Show 25 contacts per page
            try:
                contacts = paginator.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                contacts = paginator.page(1)
            except EmptyPage:
                # If page is out of range (e.g. 9999), deliver last page of results.
                contacts = paginator.page(paginator.num_pages)
            data = contacts.object_list, len(contact_list)
            print(data[0])
            return JsonResponse({
                'code': 0,
                'msg': 'ok',
                'count': data[1],
                'data': data[0]
            })
    else:
        return HttpResponseRedirect('/')
示例#3
0
def case_query(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'GET':
            page = request.GET.get('page')
            limit = request.GET.get('limit')
            main_module = request.GET.get('main_module')
            module = request.GET.get('module')
            sub_module = request.GET.get('sub_module')
            level = request.GET.get('level')
            query_str = request.GET.get('query_str')
            sql = "SELECT * FROM pro_case WHERE state=1 "

            if level is not None and level != '':
                sql += "AND level = '{level}'".format(level=level)
            if query_str is not None and strClean(query_str) != '':
                query_str = strClean(query_str)
                sql += " AND (case_id like'{query_str}' or case_name LIKE'%{query_str}%' or api_id like'{query_str}')".format(
                    query_str=query_str)

            if sub_module is not None and sub_module != '':
                sql += "AND menu_id in (select menu_id from q_boss_menu where state=1 and sys_name='产品系统' and main_module='{main_module}' and module = '{module}' and sub_module ='{sub_module}')".format(
                    main_module=main_module,
                    module=module,
                    sub_module=sub_module)
            elif module is not None and module != '':
                sql += "AND menu_id in (select menu_id from q_boss_menu where state=1 and sys_name='产品系统' and main_module='{main_module}' and module = '{module}')".format(
                    main_module=main_module, module=module)
            elif main_module is not None and main_module != '':
                sql += "AND menu_id in (select menu_id from q_boss_menu where state=1 and sys_name='产品系统' and main_module='{main_module}')".format(
                    main_module=main_module)

            contact_list = MySQLEngine('pro_case').defined(type='query',
                                                           sql=sql)
            paginator = Paginator(contact_list,
                                  limit)  # Show 25 contacts per page
            try:
                contacts = paginator.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                contacts = paginator.page(1)
            except EmptyPage:
                # If page is out of range (e.g. 9999), deliver last page of results.
                contacts = paginator.page(paginator.num_pages)
            for each in contacts.object_list:
                r = MySQLEngine('q_boss_menu').where(menu_id=each['menu_id'])
                each['main_module'] = r[0]['main_module']
                each['module'] = r[0]['module']
                each['sub_module'] = r[0]['sub_module']
            data = contacts.object_list, len(contact_list)
            return JsonResponse({
                'code': 0,
                'msg': 'ok',
                'count': data[1],
                'data': data[0]
            })
    else:
        return HttpResponseRedirect('/')
示例#4
0
 def mapping(self, **kwargs):
     # 创建赋值
     key_val_list = []
     for i in range(0, len(kwargs['list'])):
         key_list = []
         val_list = []
         key_dict = {}
         val_dict = {}
         req_params = strClean(kwargs['list'][i]['req_params'])
         req_params_dict = eval(req_params)
         for key in req_params_dict:
             key_list.append(key)
             val_list.append(req_params_dict[key])
         for num in range(len(req_params_dict)):
             key_dict['api_id'] = kwargs['list'][i]['api_id']
             key_dict['key-' + str(num + 1)] = key_list[num]
             val_dict['val-' + str(num + 1)] = req_params_dict[key_list[num]]
         key_val_list.append(dict(key_dict, **val_dict))
     # 合并
     pro_api_list = []
     for pro_api_dict in kwargs['list']:
         for req_params_dict in key_val_list:
             if pro_api_dict[self.matching] == req_params_dict[self.matching]:
                 pro_api_list.append({**pro_api_dict, **req_params_dict})
     return pro_api_list
示例#5
0
def pub_case_add(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'POST':
            data = {}
            for key in request.POST:
                if strClean(request.POST.get(key)) != '':
                    data[key] = strClean(request.POST.get(key))
                elif key in [
                        'case_name', 'level', 'expected_result', 'api_id'
                ]:
                    return HttpResponse(key)
            data['created_by'] = user_name
            res = MySQLEngine('pub_case').insert_into(**data)
            return HttpResponse(res)
    else:
        return HttpResponseRedirect('/')
示例#6
0
def case_update(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'POST':
            data = {}
            for key in request.POST:
                if strClean(request.POST.get(key)) != '':
                    data[key] = strClean(request.POST.get(key))
                elif key in [
                        'case_name', 'module', 'sub_module', 'level',
                        'expected_result'
                ]:
                    return HttpResponse(key)
            data['updated_by'] = user_name
            res = MySQLEngine('pro_case').update_set(data,
                                                     id=request.POST.get('id'))
            return HttpResponse(res)
    else:
        return HttpResponseRedirect('/')
示例#7
0
def pub_case_query(request):
    user_name = request.COOKIES.get('user_name')
    if user_name:
        if request.method == 'GET':
            page = request.GET.get('page')
            limit = request.GET.get('limit')
            level = request.GET.get('level')
            query_str = request.GET.get('query_str')
            sql = "select case_id,b.api_id,case_name,level,path,uri_params_value,req_body_value,req_params_value,expected_result, a.remark as remark " \
                  "from pub_case as a left join pub_api b on a.api_id = b.api_id " \
                  "where a.state=1 "

            if level is not None and level != '':
                sql += "AND level = '{level}'".format(level=level)
            if query_str is not None and strClean(query_str) != '':
                query_str = strClean(query_str)
                sql += " AND (case_id like'{query_str}' or case_name LIKE'%{query_str}%' or api_id like'{query_str}')".format(
                    query_str=query_str)

            contact_list = MySQLEngine('pub_case').defined(type='query',
                                                           sql=sql)
            paginator = Paginator(contact_list,
                                  limit)  # Show 25 contacts per page
            try:
                contacts = paginator.page(page)
            except PageNotAnInteger:
                # If page is not an integer, deliver first page.
                contacts = paginator.page(1)
            except EmptyPage:
                # If page is out of range (e.g. 9999), deliver last page of results.
                contacts = paginator.page(paginator.num_pages)
            data = contacts.object_list, len(contact_list)
            return JsonResponse({
                'code': 0,
                'msg': 'ok',
                'count': data[1],
                'data': data[0]
            })
    else:
        return HttpResponseRedirect('/')
示例#8
0
 def mapping(self, **kwargs):
     # 创建赋值
     key_val_dict = {}
     for i in range(0, len(kwargs['list'])):
         key_list = []
         val_list = []
         key_dict = {}
         val_dict = {}
         req_params = strClean(kwargs['list'][i]['req_params'])
         req_params_dict = eval(req_params)
         for key in req_params_dict:
             key_list.append(key)
             val_list.append(req_params_dict[key])
         for num in range(len(req_params_dict)):
             key_dict['api_id'] = kwargs['list'][i]['api_id']
             key_dict['key_' + str(num + 1)] = key_list[num]
             val_dict['val_' + str(num + 1)] = req_params_dict[key_list[num]]
         key_val_dict=dict(key_dict, **val_dict)
     return key_val_dict
 def api_add(self, QueryDict, create_by):
     try:
         key_list = []
         val_list = []
         module_val = None
         for key in QueryDict:
             if key[:-2] == 'key':
                 key_list.append(str(QueryDict[key]))
             elif key[:-2] == 'val':
                 val_list.append(str(QueryDict[key]))
         params_dict = dict(zip(key_list, val_list))
         query = add_query_menu()
         query['sys_name'] = QueryDict['sys_name']
         query['main_module'] = QueryDict['main_module']
         query['module'] = module_val
         query['sub_module'] = QueryDict['sub_module']
         query['state'] = 1
         menu_id_list = MySQLEngine('q_boss_menu').where(**query)
         if len(menu_id_list) is 0:
             menu_id = 0
         else:
             menu_id = menu_id_list[0]['menu_id']
         insert_dict = api_add_info()
         insert_dict['menu_id'] = menu_id,
         insert_dict['api_name'] = QueryDict.get('api_name', None),
         insert_dict['api_type'] = QueryDict.get('api_type', None),
         insert_dict['method'] = QueryDict.get('method', None),
         insert_dict['path'] = QueryDict.get('path', None),
         insert_dict['headers'] = QueryDict.get('headers', None),
         insert_dict['uri_params'] = QueryDict.get('uri_params', None),
         insert_dict['req_params'] = strClean(str(params_dict)),
         insert_dict['req_body'] = QueryDict.get('req_body', None),
         insert_dict['created_by'] = create_by,
         insert_dict['remark'] = QueryDict.get('remark', None),
         insert_dict['state'] = QueryDict.get('state', None),
         rslt = MySQLEngine('pro_api').insert_into(**insert_dict)
         return rslt
     except BaseException as e:
         print(e)