Beispiel #1
0
 def post(self):
     res = ResMsg()
     data = request.get_json()
     flag, mes = format_checker(edit_header_schema, data)
     if not flag:
         res.update(code=-1, data=mes, msg=param_format_error)
         return jsonify(res.data)
     interface_id = data.get('interface_id')
     header = data.get('header')
     if not is_json(header):
         res.update(code=-1, data=header, msg=param_not_json_error)
         return jsonify(res.data)
     exist_interface = Interface.query.filter_by(id=interface_id,
                                                 status=True).first()
     if not exist_interface:
         res.update(code=-1, data='', msg=interface_not_exist_error)
         return jsonify(res.data)
     exist_interface.header = header
     try:
         db.session.commit()
         res.update(code=1, data='', msg=request_success)
         return jsonify(res.data)
     except Exception as e:
         db.session.rollback()
         res.update(code=-1, data=str(e), msg=request_fail)
         return jsonify(res.data)
Beispiel #2
0
 def post(self):
     res = ResMsg()
     data = request.get_json()
     flag, mes = format_checker(edit_case_schema, data)
     if not flag:
         res.update(code=-1, data=mes, msg=param_format_error)
         return jsonify(res.data)
     case_id = data.get('case_id')
     env_id = data.get('env_id')
     case_name = data.get('case_name')
     case_desc = data.get('case_desc')
     case_type = data.get('case_type')
     method = data.get('method')
     path = data.get('path')
     params = data.get('params')
     header = data.get('header')
     has_sign = data.get('has_sign')
     ak = data.get('ak')
     sk = data.get('sk')
     res_assert = data.get('res_assert')
     has_rely = data.get('has_rely')
     rely_info = data.get('rely_info')
     has_output = data.get('has_output')
     output_para = data.get('output_para')
     has_input = data.get('has_input')
     input_para = data.get('input_para')
     input_header = data.get('input_header')
     save_result = data.get('save_result')
     use_db = data.get('use_db')
     sql = data.get('sql')
     field_value = data.get('field_value')
     exist_env = Environment.query.filter_by(id=env_id, status=True).first()
     if not exist_env:
         res.update(code=-1, data='', msg=env_not_exist_error)
         return jsonify(res.data)
     if not is_json(params):
         res.update(code=-1, data=params, msg=param_not_json_error)
         return jsonify(res.data)
     if not is_json(header):
         res.update(code=-1, data=header, msg=param_not_json_error)
         return jsonify(res.data)
     if not is_json(res_assert):
         res.update(code=-1, data=res_assert, msg=param_not_json_error)
         return jsonify(res.data)
     rely_case_list = list()
     rely_params = list()
     if has_rely:
         if not rely_info:
             res.update(code=-1, data='', msg=param_empty_error)
             return jsonify(res.data)
         if not is_json(rely_info):
             res.update(code=-1, data=rely_info, msg=param_not_json_error)
             return jsonify(res.data)
         rely_info = json.loads(rely_info)
         for rc in rely_info:
             rely_case_id = rc['rely_case_id']
             if rely_case_id == case_id:
                 res.update(code=-1, data='', msg=rely_case_self_error)
                 return jsonify(res.data)
             rely_case = TestCase.query.filter_by(id=rely_case_id, status=True).first()
             if not rely_case:
                 res.update(code=-1, data='', msg=rely_case_not_exist_error)
                 return jsonify(res.data)
             if rely_case.rely_case.all():
                 res.update(code=-1, data='', msg=rely_case_has_rely_error)
                 return jsonify(res.data)
             if rely_case in rely_case_list:
                 res.update(code=-1, data='', msg=rely_case_same_error)
                 return jsonify(res.data)
             rely_case_list.append(rely_case)
             rely_params.append(rc['rely_param'])
     if has_output == 1:
         if not output_para:
             res.update(code=-1, data='', msg=output_param_empty_error)
             return jsonify(res.data)
     else:
         output_para = ''
     if has_input == 1:
         if not input_para and not input_header:
             res.update(code=-1, data='', msg=input_param_empty_error)
             return jsonify(res.data)
     else:
         input_para = ''
         input_header = ''
     # save_result = True if save_result == 1 else False
     use_db = True if use_db == 1 else False
     if use_db:
         if sql and field_value:
             pass
         else:
             res.update(code=-1, data='', msg=db_info_empty_error)
             return jsonify(res.data)
     else:
         sql = field_value = ''
     exist_case = TestCase.query.filter_by(id=case_id, status=True).first()
     if not exist_case:
         res.update(code=-1, data='', msg=case_not_exist_error)
         return jsonify(res.data)
     exist_case.case_name = case_name
     exist_case.case_desc = case_desc
     exist_case.case_type = case_type
     exist_case.method = method
     exist_case.path = path
     exist_case.params = params
     exist_case.header = header
     exist_case.has_sign = has_sign
     exist_case.ak = ak
     exist_case.sk = sk
     exist_case.res_assert = res_assert
     exist_case.has_output = has_output
     exist_case.output_para = output_para
     exist_case.has_input = has_input
     exist_case.input_para = input_para
     exist_case.input_header = input_header
     # exist_case.save_result = save_result
     exist_case.use_db = use_db
     exist_case.sql = sql
     exist_case.field_value = field_value
     exist_case.env_id = env_id
     for exist_rc in exist_case.rely_case.all():
         exist_case.rely_case.remove(exist_rc)
     if has_rely:
         for rely_case in rely_case_list:
             exist_case.rely_case.append(rely_case)
         exist_case.rely_params = json.dumps(rely_params, ensure_ascii=False)
     try:
         db.session.commit()
         res.update(code=1, data='', msg=request_success)
         return jsonify(res.data)
     except Exception as e:
         db.session.rollback()
         res.update(code=-1, data=str(e), msg=request_fail)
         return jsonify(res.data)
Beispiel #3
0
 def post(self):
     res = ResMsg()
     data = request.get_json()
     flag, mes = format_checker(add_case_schema, data)
     if not flag:
         res.update(code=-1, data=mes, msg=param_format_error)
         return jsonify(res.data)
     interface_id = data.get('interface_id')
     env_id = data.get('env_id')
     case_name = data.get('case_name')
     case_desc = data.get('case_desc')
     case_type = data.get('case_type')
     method = data.get('method')
     path = data.get('path')
     params = data.get('params')
     header = data.get('header')
     has_sign = data.get('has_sign')
     ak = data.get('ak')
     sk = data.get('sk')
     res_assert = data.get('res_assert')
     has_rely = data.get('has_rely')
     rely_info = data.get('rely_info')
     has_output = data.get('has_output')
     output_para = data.get('output_para')
     has_input = data.get('has_input')
     input_para = data.get('input_para')
     input_header = data.get('input_header')
     save_result = data.get('save_result')
     use_db = data.get('use_db')
     sql = data.get('sql')
     field_value = data.get('field_value')
     exist_interface = Interface.query.filter_by(id=interface_id, status=True).first()
     if not exist_interface:
         res.update(code=-1, data='', msg=interface_not_exist_error)
         return jsonify(res.data)
     exist_env = Environment.query.filter_by(id=env_id, status=True).first()
     if not exist_env:
         res.update(code=-1, data='', msg=env_not_exist_error)
         return jsonify(res.data)
     if not is_json(params):
         res.update(code=-1, data=params, msg=param_not_json_error)
         return jsonify(res.data)
     if not is_json(header):
         res.update(code=-1, data=header, msg=param_not_json_error)
         return jsonify(res.data)
     if not is_json(res_assert):
         res.update(code=-1, data=res_assert, msg=param_not_json_error)
         return jsonify(res.data)
     rely_case_list = list()
     rely_params = list()
     if has_rely:
         if not rely_info:
             res.update(code=-1, data='', msg=param_empty_error)
             return jsonify(res.data)
         if not is_json(rely_info):
             res.update(code=-1, data=rely_info, msg=param_not_json_error)
             return jsonify(res.data)
         rely_info = json.loads(rely_info)
         for rc in rely_info:
             rely_case_id = rc['rely_case_id']
             rely_case = TestCase.query.filter_by(id=rely_case_id, status=True).first()
             if not rely_case:
                 res.update(code=-1, data='', msg=rely_case_not_exist_error)
                 return jsonify(res.data)
             if rely_case.rely_case.all():
                 res.update(code=-1, data='', msg=rely_case_has_rely_error)
                 return jsonify(res.data)
             if rely_case in rely_case_list:
                 res.update(code=-1, data='', msg=rely_case_same_error)
                 return jsonify(res.data)
             rely_case_list.append(rely_case)
             rely_params.append(rc['rely_param'])    # 每个依赖用例只能输出一个依赖参数
     if has_output == 1:
         if not output_para:
             res.update(code=-1, data='', msg=output_param_empty_error)
             return jsonify(res.data)
     else:
         output_para = ''
     if has_input == 1:
         if not input_para and not input_header:
             res.update(code=-1, data='', msg=input_param_empty_error)
             return jsonify(res.data)
     else:
         input_para = ''
         input_header = ''
     # save_result = True if save_result == 1 else False
     # 必须保存用例执行结果
     save_result = True
     use_db = True if use_db == 1 else False
     if use_db:
         if sql and field_value:
             pass
         else:
             res.update(code=-1, data='', msg=db_info_empty_error)
             return jsonify(res.data)
     else:
         sql = field_value = ''
     new_case = TestCase(
         case_name=case_name,
         case_desc=case_desc,
         case_type=case_type,
         method=method,
         path=path,
         params=params,
         header=header,
         has_sign=has_sign,
         ak=ak,
         sk=sk,
         res_assert=res_assert,
         has_output=has_output,
         output_para=output_para,
         has_input=has_input,
         input_para=input_para,
         input_header=input_header,
         save_result=save_result,
         use_db=use_db,
         sql=sql,
         field_value=field_value,
         project_id=exist_interface.project_id,
         model_id=exist_interface.model_id,
         interface_id=interface_id,
         env_id=env_id,
         c_uid=current_user.id
     )
     db.session.add(new_case)
     db.session.flush()
     if has_rely:
         for rely_case in rely_case_list:
             new_case.rely_case.append(rely_case)
         new_case.rely_params = json.dumps(rely_params, ensure_ascii=False)
     try:
         db.session.commit()
         case_info = {
             'case_id': new_case.id,
             'case_name': case_name,
         }
         res.update(code=1, data=case_info, msg=request_success)
         return jsonify(res.data)
     except Exception as e:
         db.session.rollback()
         res.update(code=-1, data=str(e), msg=request_fail)
         return jsonify(res.data)
Beispiel #4
0
 def post(self):
     res = ResMsg()
     data = request.get_json()
     flag, mes = format_checker(add_mock_schema, data)
     if not flag:
         res.update(code=-1, data=mes, msg=param_format_error)
         return jsonify(res.data)
     mock_name = data.get('mock_name')
     mock_desc = data.get('mock_desc')
     method = data.get('method')
     path = data.get('path')
     params = data.get('params')
     header = data.get('header')
     response = data.get('response')
     res_type = data.get('res_type')
     check_params = data.get('check_params')
     check_header = data.get('check_header')
     if check_params == 1:
         if not params:
             res.update(code=-1, data='', msg=mock_params_empty_error)
             return jsonify(res.data)
         if not is_json(params):
             res.update(code=-1, data=params, msg=param_not_json_error)
             return jsonify(res.data)
     if check_header == 1:
         if not header:
             res.update(code=-1, data='', msg=mock_params_empty_error)
             return jsonify(res.data)
         if not is_json(header):
             res.update(code=-1, data=header, msg=param_not_json_error)
             return jsonify(res.data)
     if not is_json(response):
         res.update(code=-1, data=response, msg=param_not_json_error)
         return jsonify(res.data)
     if res_type != 'json':
         res.update(code=-1, data=res_type, msg=mock_resp_type_error)
         return jsonify(res.data)
     exist_mock = Mock.query.filter_by(path=path, status=True).first()
     if exist_mock:
         res.update(code=-1, data=path, msg=path_exist_error)
         return jsonify(res.data)
     new_mock = Mock(mock_name=mock_name,
                     mock_desc=mock_desc if mock_desc else '',
                     method=method,
                     path=path,
                     params=params if params else '',
                     header=header if header else '',
                     response=response,
                     res_type=res_type,
                     update_time=datetime.datetime.now(),
                     check_params=check_params,
                     check_header=check_header,
                     c_uid=current_user.id)
     db.session.add(new_mock)
     try:
         db.session.commit()
         mock_info = {
             'mock_id': new_mock.id,
             'mock_name': mock_name,
         }
         res.update(code=1, data=mock_info, msg=request_success)
         return jsonify(res.data)
     except Exception as e:
         db.session.rollback()
         res.update(code=-1, data=str(e), msg=request_fail)
         return jsonify(res.data)
Beispiel #5
0
 def post(self):
     res = ResMsg()
     data = request.get_json()
     flag, mes = format_checker(edit_mock_schema, data)
     if not flag:
         res.update(code=-1, data=mes, msg=param_format_error)
         return jsonify(res.data)
     mock_id = data.get('mock_id')
     mock_name = data.get('mock_name')
     mock_desc = data.get('mock_desc')
     method = data.get('method')
     path = data.get('path')
     params = data.get('params')
     header = data.get('header')
     response = data.get('response')
     res_type = data.get('res_type')
     check_params = data.get('check_params')
     check_header = data.get('check_header')
     exist_mock = Mock.query.filter_by(id=mock_id, status=True).first()
     if not exist_mock:
         res.update(code=-1, data='', msg=mock_not_exist_error)
         return jsonify(res.data)
     other_mock = Mock.query.filter_by(path=path, status=True).first()
     if other_mock and other_mock.id != mock_id:
         res.update(code=-1, data='', msg=path_exist_error)
         return jsonify(res.data)
     if check_params == 1:
         if not params:
             res.update(code=-1, data='', msg=mock_params_empty_error)
             return jsonify(res.data)
         if not is_json(params):
             res.update(code=-1, data=params, msg=param_not_json_error)
             return jsonify(res.data)
     if check_header == 1:
         if not header:
             res.update(code=-1, data='', msg=mock_params_empty_error)
             return jsonify(res.data)
         if not is_json(header):
             res.update(code=-1, data=header, msg=param_not_json_error)
             return jsonify(res.data)
     if not is_json(response):
         res.update(code=-1, data=response, msg=param_not_json_error)
         return jsonify(res.data)
     exist_mock.mock_name = mock_name
     exist_mock.mock_desc = mock_desc if mock_desc else ''
     exist_mock.method = method
     exist_mock.path = path
     exist_mock.params = params if params else ''
     exist_mock.header = header if header else ''
     exist_mock.response = response
     exist_mock.res_type = res_type
     exist_mock.update_time = datetime.datetime.now()
     exist_mock.check_params = check_params
     exist_mock.check_header = check_header
     try:
         db.session.commit()
         res.update(code=1, data='', msg=request_success)
         return jsonify(res.data)
     except Exception as e:
         db.session.rollback()
         res.update(code=-1, data=str(e), msg=request_fail)
         return jsonify(res.data)