Debian Codegraph @

tests/test_tutorial/test_path_params/test_tutorial003b.py

raw
1 import asyncio
2
3 from fastapi.testclient import TestClient
4 from inline_snapshot import snapshot
5
6 from docs_src.path_params.tutorial003b_py310 import app, read_users2
7
8 client = TestClient(app)
9
10
11 def test_get_users():
12 response = client.get("/users")
13 assert response.status_code == 200, response.text
14 assert response.json() == ["Rick", "Morty"]
15
16
17 def test_read_users2(): # Just for coverage
18 assert asyncio.run(read_users2()) == ["Bean", "Elfo"]
19
20
21 def test_openapi_schema():
22 response = client.get("/openapi.json")
23 assert response.status_code == 200, response.text
24 assert response.json() == snapshot(
25 {
26 "openapi": "3.1.0",
27 "info": {"title": "FastAPI", "version": "0.1.0"},
28 "paths": {
29 "/users": {
30 "get": {
31 "operationId": "read_users2_users_get",
32 "responses": {
33 "200": {
34 "content": {
35 "application/json": {
36 "schema": {},
37 },
38 },
39 "description": "Successful Response",
40 },
41 },
42 "summary": "Read Users2",
43 },
44 },
45 },
46 }
47 )