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. 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
import sys
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 .loging_tool import login_required
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
@app.get("/items/")
@login_required
def get_item(id: int) -> Item:
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

9
tests/test_future/test_future_9095.py

@ -1,22 +1,21 @@
from __future__ import annotations
import sys
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
from ..utils import needs_py310
app = FastAPI()
client = TestClient(app)
class Test:
def __call__(self, request: Request):
return "test"
@app.get("/test/")
def call(test: str = Depends(Test())):
return {"test": test}

Loading…
Cancel
Save