Coverage for tests / test_tutorial / test_first_steps / test_tutorial001_tutorial002_tutorial003.py: 100%
18 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-12 18:15 +0000
1import importlib 1abdc
3import pytest 1abdc
4from fastapi.testclient import TestClient 1abdc
5from inline_snapshot import snapshot 1abdc
8@pytest.fixture( 1abdc
9 name="client",
10 params=[
11 "tutorial001_py310",
12 "tutorial003_py310",
13 ],
14)
15def get_client(request: pytest.FixtureRequest): 1abdc
16 mod = importlib.import_module(f"docs_src.first_steps.{request.param}") 1abc
17 client = TestClient(mod.app) 1abc
18 return client 1abc
21@pytest.mark.parametrize( 1abdc
22 "path,expected_status,expected_response",
23 [
24 ("/", 200, {"message": "Hello World"}),
25 ("/nonexistent", 404, {"detail": "Not Found"}),
26 ],
27)
28def test_get_path(client: TestClient, path, expected_status, expected_response): 1abdc
29 response = client.get(path) 1efg
30 assert response.status_code == expected_status 1efg
31 assert response.json() == expected_response 1efg
34def test_openapi_schema(client: TestClient): 1abdc
35 response = client.get("/openapi.json") 1hij
36 assert response.status_code == 200 1hij
37 assert response.json() == snapshot( 1hij
38 {
39 "openapi": "3.1.0",
40 "info": {"title": "FastAPI", "version": "0.1.0"},
41 "paths": {
42 "/": {
43 "get": {
44 "responses": {
45 "200": {
46 "description": "Successful Response",
47 "content": {"application/json": {"schema": {}}},
48 }
49 },
50 "summary": "Root",
51 "operationId": "root__get",
52 }
53 }
54 },
55 }
56 )