Esempio n. 1
0
def deleteCondition(id):
    condition = Condition.query.filter_by(id=id).first()
    if condition and condition.user_id == current_user.id:
        condition.status = -1
        db.session.add(condition)
        db.session.commit()
        cache.clear()
        return response()
    elif condition:
        return response(False, "只能删除自己创建的mock-api-condition")
    else:
        return response(False, "未配置的mock-api-condition")
Esempio n. 2
0
def deleteMock(id):
    api = Api.query.filter_by(id=id).first()
    if api and api.user_id == current_user.id:
        conditions = Condition.query.filter_by(
            user_id=current_user.id).filter_by(api_id=id).all()
        api.status = -1
        db.session.add(api)
        for c in conditions:
            c.status = -1
            db.session.add(c)
        db.session.commit()
        cache.clear()
        return response()
    elif api:
        return response(False, "只能删除自己创建的mock-api")
    else:
        return response(False, "未配置的mock-api")
Esempio n. 3
0
def edit_mock_service(id, request):
    api = Api.query.filter_by(id=id).first()
    force = request.form.get("force")
    if api:
        if force or api.user_id == current_user.id:
            resp_default = request.form.get("body")
            httpcode = request.form.get("httpcode")
            if resp_default:
                api.resp_default = resp_default
            if httpcode:
                api.httpcode = httpcode
            db.session.add(api)
            db.session.commit()
            cache.clear()
        else:
            raise Exception("只能编辑自己创建的mock-api")
    else:
        raise Exception("未配置的mock-api")
Esempio n. 4
0
def add_mock_service(request):
    data = request.json or request.form
    remote = data.get("remote")
    method = data.get("method")
    urlpath = data.get("urlpath")
    condition = data.get("condition")
    operation = data.get("operation")
    value = data.get("value")
    httpcode = data.get("httpcode")
    resp_type = data.get("resp_type")
    resp_body = data.get("resp_body")
    resp_default = data.get("resp_default")
    api = Api.query.filter_by(path=urlpath).filter_by(method=method).filter_by(status=0).first()
    if not api:
        api = Api(
            path=urlpath,
            method=method,
            resp_type=resp_type,
            httpcode=httpcode,
            resp_default=resp_default or resp_body,
            user_id=current_user.id if not remote else 1
        )
    if resp_default:
        api.resp_default = resp_default

    db.session.add(api)
    db.session.commit()

    if value:
        condition = Condition(
            api_id=api.id,
            condition=condition,
            operation=operation,
            value=value,
            httpcode=httpcode,
            resp_body=resp_body,
            user_id=current_user.id
        )
        db.session.add(condition)
    db.session.commit()
    cache.clear()
Esempio n. 5
0
def edit_condition_resp(id, request):
    condition = Condition.query.filter_by(id=id).first()
    force = request.form.get("force")
    if condition:
        if force or condition.user_id == current_user.id:
            resp_body = request.form.get("body")
            httpcode = request.form.get("httpcode")
            value = request.form.get("value")
            if resp_body:
                condition.resp_body = resp_body
            if httpcode:
                condition.httpcode = httpcode
            if value:
                condition.value = value
            db.session.add(condition)
            db.session.commit()
            cache.clear()
        else:
            raise Exception("只能编辑自己创建的mock-api-condition")
    else:
        raise Exception("未配置的mock-api-condition")