mirror of
https://github.com/fastapi/fastapi.git
synced 2026-04-05 23:55:06 -04:00
Fix "to to" and "that that" word duplications in security module docstrings, and "be be" in test data string. Co-authored-by: ahsan.sheraz <ahsan.sheraz@bonial.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
52 lines
1.1 KiB
Python
52 lines
1.1 KiB
Python
from __future__ import annotations
|
|
|
|
import uuid
|
|
from dataclasses import dataclass, field
|
|
|
|
from dirty_equals import IsUUID
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
from inline_snapshot import snapshot
|
|
|
|
|
|
@dataclass
|
|
class Item:
|
|
id: uuid.UUID
|
|
name: str
|
|
price: float
|
|
tags: list[str] = field(default_factory=list)
|
|
description: str | None = None
|
|
tax: float | None = None
|
|
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/item", response_model=Item)
|
|
async def read_item():
|
|
return {
|
|
"id": uuid.uuid4(),
|
|
"name": "Island In The Moon",
|
|
"price": 12.99,
|
|
"description": "A place to be playin' and havin' fun",
|
|
"tags": ["breater"],
|
|
}
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def test_annotations():
|
|
response = client.get("/item")
|
|
assert response.status_code == 200, response.text
|
|
assert response.json() == snapshot(
|
|
{
|
|
"id": IsUUID(),
|
|
"name": "Island In The Moon",
|
|
"price": 12.99,
|
|
"tags": ["breater"],
|
|
"description": "A place to be playin' and havin' fun",
|
|
"tax": None,
|
|
}
|
|
)
|