Coverage for tests/test_tutorial/test_events/test_tutorial003.py: 100%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1from fastapi.testclient import TestClient 1abcde
3from docs_src.events.tutorial003 import ( 1abcde
4 app,
5 fake_answer_to_everything_ml_model,
6 ml_models,
7)
10def test_events(): 1abcde
11 assert not ml_models, "ml_models should be empty" 1abcde
12 with TestClient(app) as client: 1abcde
13 assert ml_models["answer_to_everything"] == fake_answer_to_everything_ml_model 1abcde
14 response = client.get("/predict", params={"x": 2}) 1abcde
15 assert response.status_code == 200, response.text 1abcde
16 assert response.json() == {"result": 84.0} 1abcde
17 assert not ml_models, "ml_models should be empty" 1abcde
20def test_openapi_schema(): 1abcde
21 with TestClient(app) as client: 1abcde
22 response = client.get("/openapi.json") 1abcde
23 assert response.status_code == 200, response.text 1abcde
24 assert response.json() == { 1abcde
25 "openapi": "3.1.0",
26 "info": {"title": "FastAPI", "version": "0.1.0"},
27 "paths": {
28 "/predict": {
29 "get": {
30 "summary": "Predict",
31 "operationId": "predict_predict_get",
32 "parameters": [
33 {
34 "required": True,
35 "schema": {"title": "X", "type": "number"},
36 "name": "x",
37 "in": "query",
38 }
39 ],
40 "responses": {
41 "200": {
42 "description": "Successful Response",
43 "content": {"application/json": {"schema": {}}},
44 },
45 "422": {
46 "description": "Validation Error",
47 "content": {
48 "application/json": {
49 "schema": {
50 "$ref": "#/components/schemas/HTTPValidationError"
51 }
52 }
53 },
54 },
55 },
56 }
57 }
58 },
59 "components": {
60 "schemas": {
61 "HTTPValidationError": {
62 "title": "HTTPValidationError",
63 "type": "object",
64 "properties": {
65 "detail": {
66 "title": "Detail",
67 "type": "array",
68 "items": {
69 "$ref": "#/components/schemas/ValidationError"
70 },
71 }
72 },
73 },
74 "ValidationError": {
75 "title": "ValidationError",
76 "required": ["loc", "msg", "type"],
77 "type": "object",
78 "properties": {
79 "loc": {
80 "title": "Location",
81 "type": "array",
82 "items": {
83 "anyOf": [{"type": "string"}, {"type": "integer"}]
84 },
85 },
86 "msg": {"title": "Message", "type": "string"},
87 "type": {"title": "Error Type", "type": "string"},
88 },
89 },
90 }
91 },
92 }