committed by
GitHub
5 changed files with 76 additions and 2 deletions
@ -0,0 +1,10 @@ |
|||||
|
from functools import wraps |
||||
|
|
||||
|
|
||||
|
def login_required(func): |
||||
|
@wraps(func) |
||||
|
def wrapper(*args, **kwargs): |
||||
|
# login functionality could come here |
||||
|
return func(*args, **kwargs) |
||||
|
|
||||
|
return wrapper |
@ -0,0 +1,31 @@ |
|||||
|
from __future__ import annotations |
||||
|
|
||||
|
from typing import Optional |
||||
|
|
||||
|
from fastapi import FastAPI |
||||
|
from fastapi.testclient import TestClient |
||||
|
from pydantic import BaseModel |
||||
|
|
||||
|
from ..utils import needs_py310 |
||||
|
from .login_tool import login_required |
||||
|
|
||||
|
app = FastAPI() |
||||
|
client = TestClient(app) |
||||
|
|
||||
|
|
||||
|
class Item(BaseModel): |
||||
|
name: str |
||||
|
description: Optional[str] = None |
||||
|
price: float |
||||
|
tax: Optional[float] = None |
||||
|
|
||||
|
|
||||
|
@needs_py310 |
||||
|
def test_future_6465(): |
||||
|
@app.get("/items/") |
||||
|
@login_required |
||||
|
def get_item(item_id: int) -> Item: |
||||
|
return Item(name="name", price=42.42) |
||||
|
|
||||
|
res = client.get("/items?item_id=3") |
||||
|
assert res.status_code == 200 |
@ -0,0 +1,26 @@ |
|||||
|
from __future__ import annotations |
||||
|
|
||||
|
from fastapi import Depends, FastAPI |
||||
|
from fastapi.testclient import TestClient |
||||
|
from starlette.requests import Request |
||||
|
|
||||
|
from ..utils import needs_py310 |
||||
|
|
||||
|
app = FastAPI() |
||||
|
|
||||
|
client = TestClient(app) |
||||
|
|
||||
|
|
||||
|
class Test: |
||||
|
def __call__(self, request: Request): |
||||
|
return "test" |
||||
|
|
||||
|
|
||||
|
@needs_py310 |
||||
|
def test_call(): |
||||
|
@app.get("/test/") |
||||
|
def call(test: str = Depends(Test())): |
||||
|
return {"test": test} |
||||
|
|
||||
|
response = client.get("/test") |
||||
|
assert response.status_code == 200 |
Loading…
Reference in new issue