Browse Source

refactor unit test to avoid Python check twice

pull/11355/head
svlandeg 1 year ago
parent
commit
9b1cbc5b28
  1. 0
      tests/test_future/login_tool.py
  2. 14
      tests/test_future/test_future_6465.py
  3. 9
      tests/test_future/test_future_9095.py

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

14
tests/test_future/test_future_6465.py

@ -1,34 +1,32 @@
from __future__ import annotations from __future__ import annotations
import sys
from ..utils import needs_py310
if sys.version_info > (3, 10):
from typing import Optional from typing import Optional
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from pydantic import BaseModel from pydantic import BaseModel
from .loging_tool import login_required from ..utils import needs_py310
from .login_tool import login_required
app = FastAPI() app = FastAPI()
client = TestClient(app) 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/") @app.get("/items/")
@login_required @login_required
def get_item(id: int) -> Item: 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

9
tests/test_future/test_future_9095.py

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

Loading…
Cancel
Save