async def on_post(self, request: ASGIRequest): files: FileStorage = request.files["file"] if not isinstance(files, list): files = [files] for f in files: with open(f.filename, "wb") as fp: f.save(fp) return JSONResponse({"success": 1})
def on_post( self, path: str, query: dict = Query(LimitOffsetSchema), body: dict = Body(ArticleSchema()), ): """ Test json body """ return JSONResponse({"path": path, "query": query, "body": body})
def on_get( self, path: str, log: Logger = Plugin("logging"), foo: int = Settings("foo"), kebab_size: str = Depends(get_kebab_size), ): log.info("can you see me?") return JSONResponse({ "path": path, "foo": foo, "kebab_size": kebab_size })
def on_post(self, request: Request): """ Test multipart/form-data """ files: FileStorage = request.files["file"] if not isinstance(files, list): files = [files] for f in files: with open(f.filename, "wb") as fp: f.save(fp) return JSONResponse({"success": 1})
async def on_get(self): await asyncio.sleep(5) return JSONResponse({ "users": [ { "email": "*****@*****.**", "password": "******" }, { "email": "*****@*****.**", "password": "******" }, { "email": "*****@*****.**", "password": "******" }, ] })
def on_get(): """ Get a secret user list """ return JSONResponse({ "users": [ { "email": "*****@*****.**", "password": "******" }, { "email": "*****@*****.**", "password": "******" }, { "email": "*****@*****.**", "password": "******" }, ] })
def on_get(self): return JSONResponse({"status": 1})
def on_get(self, config: dict = Settings()): return JSONResponse(config)
async def settings(part_config: dict = Settings("part_config")): return JSONResponse(part_config)
def on_get(self, token: str): return JSONResponse({"token": token})
def on_get(self, foo: int = Settings("foo")): return JSONResponse({"foo": foo})
async def on_post_form(self, form: dict = Form(ArticleSchema)): """ Test form data with suffixes """ return JSONResponse(form)
async def on_post(self, body: dict = Body(ArticleSchema)): return JSONResponse(body)
def on_get(self, kebab_size: str = Depends(get_kebab_size)): return JSONResponse({"kebab_size": kebab_size})
import asyncio import pytest from falca.responses import JSONResponse data = [{"name": "kwoakwoakow", "email": "*****@*****.**"}] default = JSONResponse(data) class Users: def on_get(self): return default class AsyncUsers: async def on_get(self): await asyncio.sleep(5) return default def test_resources_wsgi(wsgi_app, wsgi_client): wsgi_app.add_route("/users/class", Users()) @wsgi_app.get("/users/function") def users_function(): return default resp = wsgi_client.get("/users/class") assert resp.json == data
def on_get(self, query: dict = Query()): return JSONResponse(query)
def on_post(self, body: dict = Body(ArticleSchema())): """ Test json body """ return JSONResponse(body)
def on_get(self, query: dict = Query(LimitOffsetSchema)): """ Test query parameters """ return JSONResponse(query)
def private(): return JSONResponse({"status": 1})
async def on_get(self, query: dict = Query(LimitOffsetSchema)): return JSONResponse(query)