Browse Source

refactor unit test to avoid Python check twice

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

19
tests/test_future/test_future_9095.py

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

Loading…
Cancel
Save