Coverage for tests/test_tutorial/test_extra_models/test_tutorial004.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-05-05 00:03 +0000
1import importlib 1abcdef
3import pytest 1abcdef
4from fastapi.testclient import TestClient 1abcdef
6from ...utils import needs_py39 1abcdef
9@pytest.fixture( 1abcdef
10 name="client",
11 params=[
12 "tutorial004",
13 pytest.param("tutorial004_py39", marks=needs_py39),
14 ],
15)
16def get_client(request: pytest.FixtureRequest): 1abcdef
17 mod = importlib.import_module(f"docs_src.extra_models.{request.param}") 1abcdef
19 client = TestClient(mod.app) 1abcdef
20 return client 1abcdef
23def test_get_items(client: TestClient): 1abcdef
24 response = client.get("/items/") 1ghijkl
25 assert response.status_code == 200, response.text 1ghijkl
26 assert response.json() == [ 1ghijkl
27 {"name": "Foo", "description": "There comes my hero"},
28 {"name": "Red", "description": "It's my aeroplane"},
29 ]
32def test_openapi_schema(client: TestClient): 1abcdef
33 response = client.get("/openapi.json") 1mnopqr
34 assert response.status_code == 200, response.text 1mnopqr
35 assert response.json() == { 1mnopqr
36 "openapi": "3.1.0",
37 "info": {"title": "FastAPI", "version": "0.1.0"},
38 "paths": {
39 "/items/": {
40 "get": {
41 "responses": {
42 "200": {
43 "description": "Successful Response",
44 "content": {
45 "application/json": {
46 "schema": {
47 "title": "Response Read Items Items Get",
48 "type": "array",
49 "items": {"$ref": "#/components/schemas/Item"},
50 }
51 }
52 },
53 }
54 },
55 "summary": "Read Items",
56 "operationId": "read_items_items__get",
57 }
58 }
59 },
60 "components": {
61 "schemas": {
62 "Item": {
63 "title": "Item",
64 "required": ["name", "description"],
65 "type": "object",
66 "properties": {
67 "name": {"title": "Name", "type": "string"},
68 "description": {"title": "Description", "type": "string"},
69 },
70 }
71 }
72 },
73 }