Use `snapshot` in tests

This commit is contained in:
Yurii Motov 2026-02-12 11:06:20 +01:00
parent d34f1e6bcf
commit 1a18de1153
1 changed files with 94 additions and 87 deletions

View File

@ -3,6 +3,7 @@ from typing import Annotated
from dirty_equals import IsList
from fastapi import FastAPI, Query
from fastapi.testclient import TestClient
from inline_snapshot import snapshot
from pydantic import Field
MaxSizedSet = Annotated[set[str], Field(max_length=3)]
@ -33,7 +34,8 @@ def test_endpoint_valid():
def test_endpoint_too_long():
response = client.get("/", params={"foo": ["a", "b", "c", "d"]})
assert response.status_code == 422
assert response.json() == {
assert response.json() == snapshot(
{
"detail": [
{
"type": "too_long",
@ -48,16 +50,20 @@ def test_endpoint_too_long():
}
]
}
)
def test_openapi():
assert app.openapi() == {
assert app.openapi() == snapshot(
{
"components": {
"schemas": {
"HTTPValidationError": {
"properties": {
"detail": {
"items": {"$ref": "#/components/schemas/ValidationError"},
"items": {
"$ref": "#/components/schemas/ValidationError"
},
"title": "Detail",
"type": "array",
},
@ -134,3 +140,4 @@ def test_openapi():
},
},
}
)