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-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 "tutorial005",
13 pytest.param("tutorial005_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("/keyword-weights/") 1ghijkl
25 assert response.status_code == 200, response.text 1ghijkl
26 assert response.json() == {"foo": 2.3, "bar": 3.4} 1ghijkl
29def test_openapi_schema(client: TestClient): 1abcdef
30 response = client.get("/openapi.json") 1mnopqr
31 assert response.status_code == 200, response.text 1mnopqr
32 assert response.json() == { 1mnopqr
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 }