Ejemplo n.º 1
0
async def test_raise_tip(
    model: UserModel = Body.i(),
    other_model: UserOtherModel = Body.i(),
    content_type: str = Header.i(description="content-type"),
) -> response.HTTPResponse:
    """Test Method: error tip"""
    return_dict = model.dict()
    return_dict.update(other_model.dict())
    return_dict.update({"content_type": content_type})
    return response.json({"code": 0, "msg": "", "data": return_dict})
Ejemplo n.º 2
0
async def test_post(
    model: UserModel = Body.i(),
    other_model: UserOtherModel = Body.i(),
    sex: SexEnum = Body.i(description="sex"),
    content_type: str = Header.i(alias="Content-Type", description="content-type"),
) -> JSONResponse:
    """Test Method:Post Pydantic Model"""
    return_dict = model.dict()
    return_dict["sex"] = sex.value
    return_dict.update(other_model.dict())
    return_dict.update({"content_type": content_type})
    return JSONResponse({"code": 0, "msg": "", "data": return_dict})
Ejemplo n.º 3
0
def test_raise_tip(
        model: UserModel = Body.i(),
        other_model: UserOtherModel = Body.i(),
        content__type: str = Header.i(
            description="Content-Type"
        ),  # in flask, Content-Type's key is content_type
) -> dict:
    """Test Method: error tip"""
    return_dict = model.dict()
    return_dict.update(other_model.dict())
    return_dict.update({"content_type": content__type})
    return {"code": 0, "msg": "", "data": return_dict}
Ejemplo n.º 4
0
class TestCbv(HTTPMethodView):
    user_agent: str = Header.i(alias="user-agent",
                               description="ua")  # remove key will raise error

    @pait(
        author=("so1n", ),
        group="user",
        status=PaitStatus.release,
        tag=("user", "get"),
        response_model_list=[UserSuccessRespModel2, FailRespModel],
    )
    async def get(
            self,
            uid: int = Query.i(description="user id", gt=10, lt=1000),
            user_name: str = Query.i(description="user name",
                                     min_length=2,
                                     max_length=4),
            email: str = Query.i(default="*****@*****.**",
                                 description="user email"),
            model: UserOtherModel = Query.i(),
    ) -> response.HTTPResponse:
        """Text Pydantic Model and Field"""
        return_dict = {
            "uid": uid,
            "user_name": user_name,
            "email": email,
            "age": model.age
        }
        return response.json({"code": 0, "msg": "", "data": return_dict})

    @pait(
        author=("so1n", ),
        desc="test cbv post method",
        group="user",
        tag=("user", "post"),
        status=PaitStatus.release,
        response_model_list=[UserSuccessRespModel, FailRespModel],
    )
    async def post(
            self,
            model: UserModel = Body.i(),
            other_model: UserOtherModel = Body.i(),
    ) -> response.HTTPResponse:
        return_dict = model.dict()
        return_dict.update(other_model.dict())
        return_dict.update({"user_agent": self.user_agent})
        return response.json({"code": 0, "msg": "", "data": return_dict})
Ejemplo n.º 5
0
def demo_sub_depend(
    user_agent: str = Header.i(alias="user-agent", description="user agent"),
    age: int = Body.i(description="age", gt=1, lt=100),
) -> Tuple[str, int]:
    return user_agent, age
Ejemplo n.º 6
0
class TestPaitModel(PaitBaseModel):
    uid: int = Query.i(description="user id", gt=10, lt=1000)
    user_name: str = Query.i(description="user name", min_length=2, max_length=4)
    user_agent: str = Header.i(alias="user-agent", description="user agent")
    age: int = Body.i(description="age", gt=1, lt=100)