Debian Codegraph @

tests/test_tutorial/test_custom_response/test_tutorial001b.py

raw
1 import warnings
2
3 import pytest
4 from fastapi.exceptions import FastAPIDeprecationWarning
5 from fastapi.testclient import TestClient
6 from inline_snapshot import snapshot
7
8 with warnings.catch_warnings():
9 warnings.simplefilter("ignore", FastAPIDeprecationWarning)
10 from docs_src.custom_response.tutorial001b_py310 import app
11
12 client = TestClient(app)
13
14 pytest.importorskip("orjson")
15
16
17 @pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning")
18 def test_get_custom_response():
19 response = client.get("/items/")
20 assert response.status_code == 200, response.text
21 assert response.json() == [{"item_id": "Foo"}]
22
23
24 @pytest.mark.filterwarnings("ignore::fastapi.exceptions.FastAPIDeprecationWarning")
25 def test_openapi_schema():
26 response = client.get("/openapi.json")
27 assert response.status_code == 200, response.text
28 assert response.json() == snapshot(
29 {
30 "openapi": "3.1.0",
31 "info": {"title": "FastAPI", "version": "0.1.0"},
32 "paths": {
33 "/items/": {
34 "get": {
35 "responses": {
36 "200": {
37 "description": "Successful Response",
38 "content": {"application/json": {"schema": {}}},
39 }
40 },
41 "summary": "Read Items",
42 "operationId": "read_items_items__get",
43 }
44 }
45 },
46 }
47 )