Coverage for tests / test_tutorial / test_extra_models / test_tutorial005.py: 100%
17 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("tutorial005_py310"),
12 ],
13)
14def get_client(request: pytest.FixtureRequest): 1abcd
15 mod = importlib.import_module(f"docs_src.extra_models.{request.param}") 1efghijkl
17 client = TestClient(mod.app) 1efghijkl
18 return client 1efghijkl
21def test_get_items(client: TestClient): 1abcd
22 response = client.get("/keyword-weights/") 1mnop
23 assert response.status_code == 200, response.text 1mnop
24 assert response.json() == {"foo": 2.3, "bar": 3.4} 1mnop
27def test_openapi_schema(client: TestClient): 1abcd
28 response = client.get("/openapi.json") 1qrst
29 assert response.status_code == 200, response.text 1qrst
30 assert response.json() == snapshot( 1qrst
31 {
32 "openapi": "3.1.0",
33 "info": {"title": "FastAPI", "version": "0.1.0"},
34 "paths": {
35 "/keyword-weights/": {
36 "get": {
37 "responses": {
38 "200": {
39 "description": "Successful Response",
40 "content": {
41 "application/json": {
42 "schema": {
43 "title": "Response Read Keyword Weights Keyword Weights Get",
44 "type": "object",
45 "additionalProperties": {"type": "number"},
46 }
47 }
48 },
49 }
50 },
51 "summary": "Read Keyword Weights",
52 "operationId": "read_keyword_weights_keyword_weights__get",
53 }
54 }
55 },
56 }
57 )