Coverage for tests/test_tutorial/test_extra_models/test_tutorial005.py: 100%
17 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2025-12-04 08:29 +0000
1import importlib 1abcdefg
3import pytest 1abcdefg
4from fastapi.testclient import TestClient 1abcdefg
6from ...utils import needs_py39 1abcdefg
9@pytest.fixture( 1abcdefg
10 name="client",
11 params=[
12 "tutorial005",
13 pytest.param("tutorial005_py39", marks=needs_py39),
14 ],
15)
16def get_client(request: pytest.FixtureRequest): 1abcdefg
17 mod = importlib.import_module(f"docs_src.extra_models.{request.param}") 1abcdefg
19 client = TestClient(mod.app) 1abcdefg
20 return client 1abcdefg
23def test_get_items(client: TestClient): 1abcdefg
24 response = client.get("/keyword-weights/") 1hijklmn
25 assert response.status_code == 200, response.text 1hijklmn
26 assert response.json() == {"foo": 2.3, "bar": 3.4} 1hijklmn
29def test_openapi_schema(client: TestClient): 1abcdefg
30 response = client.get("/openapi.json") 1opqrstu
31 assert response.status_code == 200, response.text 1opqrstu
32 assert response.json() == { 1opqrstu
33 "openapi": "3.1.0",
34 "info": {"title": "FastAPI", "version": "0.1.0"},
35 "paths": {
36 "/keyword-weights/": {
37 "get": {
38 "responses": {
39 "200": {
40 "description": "Successful Response",
41 "content": {
42 "application/json": {
43 "schema": {
44 "title": "Response Read Keyword Weights Keyword Weights Get",
45 "type": "object",
46 "additionalProperties": {"type": "number"},
47 }
48 }
49 },
50 }
51 },
52 "summary": "Read Keyword Weights",
53 "operationId": "read_keyword_weights_keyword_weights__get",
54 }
55 }
56 },
57 }