Browse Source

refactor unit test to avoid Python check twice

pull/11355/head
svlandeg 10 months ago
parent
commit
9b1cbc5b28
  1. 0
      tests/test_future/login_tool.py
  2. 30
      tests/test_future/test_future_6465.py
  3. 19
      tests/test_future/test_future_9095.py

0
tests/test_future/loging_tool.py → tests/test_future/login_tool.py

30
tests/test_future/test_future_6465.py

@ -1,34 +1,32 @@
from __future__ import annotations
import sys
from typing import Optional
from ..utils import needs_py310
if sys.version_info > (3, 10):
from typing import Optional
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
from fastapi import FastAPI
from fastapi.testclient import TestClient
from pydantic import BaseModel
from ..utils import needs_py310
from .login_tool import login_required
from .loging_tool import login_required
app = FastAPI()
client = TestClient(app)
app = FastAPI()
client = TestClient(app)
class Item(BaseModel):
class Item(BaseModel):
name: str
description: Optional[str] = None
price: float
tax: Optional[float] = None
@app.get("/items/")
@login_required
def get_item(id: int) -> Item:
@app.get("/items/")
@login_required
def get_item(item_id: int) -> Item:
return Item(name="name", price=42.42)
@needs_py310
def test_future_6465():
res = client.get("/items?id=3")
res = client.get("/items?item_id=3")
assert res.status_code == 200

19
tests/test_future/test_future_9095.py

@ -1,24 +1,23 @@
from __future__ import annotations
import sys
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from starlette.requests import Request
from ..utils import needs_py310
if sys.version_info > (3, 10):
from fastapi import Depends, FastAPI
from fastapi.testclient import TestClient
from starlette.requests import Request
app = FastAPI()
app = FastAPI()
client = TestClient(app)
client = TestClient(app)
class Test:
class Test:
def __call__(self, request: Request):
return "test"
@app.get("/test/")
def call(test: str = Depends(Test())):
@app.get("/test/")
def call(test: str = Depends(Test())):
return {"test": test}

Loading…
Cancel
Save