Coverage for tests / test_tutorial / test_response_directly / test_tutorial002.py: 100%
19 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-04-06 01:24 +0000
1import importlib 1abcd
3import pytest 1abcd
4from fastapi.testclient import TestClient 1abcd
5from inline_snapshot import snapshot 1abcd
8@pytest.fixture( 1abcd
9 name="client",
10 params=[
11 pytest.param("tutorial002_py310"),
12 ],
13)
14def get_client(request: pytest.FixtureRequest): 1abcd
15 mod = importlib.import_module(f"docs_src.response_directly.{request.param}") 1ijklmnop
17 client = TestClient(mod.app) 1ijklmnop
18 return client 1ijklmnop
21def test_path_operation(client: TestClient): 1abcd
22 expected_content = """<?xml version="1.0"?> 1efgh
23 <shampoo>
24 <Header>
25 Apply shampoo here.
26 </Header>
27 <Body>
28 You'll have to use soap here.
29 </Body>
30 </shampoo>
31 """
33 response = client.get("/legacy/") 1efgh
34 assert response.status_code == 200, response.text 1efgh
35 assert response.headers["content-type"] == "application/xml" 1efgh
36 assert response.text == expected_content 1efgh
39def test_openapi_schema(client: TestClient): 1abcd
40 response = client.get("/openapi.json") 1qrst
41 assert response.status_code == 200, response.text 1qrst
42 assert response.json() == snapshot( 1qrst
43 {
44 "info": {
45 "title": "FastAPI",
46 "version": "0.1.0",
47 },
48 "openapi": "3.1.0",
49 "paths": {
50 "/legacy/": {
51 "get": {
52 "operationId": "get_legacy_data_legacy__get",
53 "responses": {
54 "200": {
55 "content": {
56 "application/json": {
57 "schema": {},
58 },
59 },
60 "description": "Successful Response",
61 },
62 },
63 "summary": "Get Legacy Data",
64 },
65 },
66 },
67 }
68 )