Debian Codegraph @

tests/test_tutorial/test_custom_response/test_tutorial001.py

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