Coverage for tests/test_tutorial/test_events/test_tutorial001.py: 100%
18 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
1import pytest 1abcde
2from fastapi import FastAPI 1abcde
3from fastapi.testclient import TestClient 1abcde
6@pytest.fixture(name="app", scope="module") 1abcde
7def get_app(): 1abcde
8 with pytest.warns(DeprecationWarning): 1abcde
9 from docs_src.events.tutorial001 import app 1abcde
10 yield app 1abcde
13def test_events(app: FastAPI): 1abcde
14 with TestClient(app) as client: 1abcde
15 response = client.get("/items/foo") 1abcde
16 assert response.status_code == 200, response.text 1abcde
17 assert response.json() == {"name": "Fighters"} 1abcde
20def test_openapi_schema(app: FastAPI): 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 "/items/{item_id}": {
29 "get": {
30 "responses": {
31 "200": {
32 "description": "Successful Response",
33 "content": {"application/json": {"schema": {}}},
34 },
35 "422": {
36 "description": "Validation Error",
37 "content": {
38 "application/json": {
39 "schema": {
40 "$ref": "#/components/schemas/HTTPValidationError"
41 }
42 }
43 },
44 },
45 },
46 "summary": "Read Items",
47 "operationId": "read_items_items__item_id__get",
48 "parameters": [
49 {
50 "required": True,
51 "schema": {"title": "Item Id", "type": "string"},
52 "name": "item_id",
53 "in": "path",
54 }
55 ],
56 }
57 }
58 },
59 "components": {
60 "schemas": {
61 "ValidationError": {
62 "title": "ValidationError",
63 "required": ["loc", "msg", "type"],
64 "type": "object",
65 "properties": {
66 "loc": {
67 "title": "Location",
68 "type": "array",
69 "items": {
70 "anyOf": [{"type": "string"}, {"type": "integer"}]
71 },
72 },
73 "msg": {"title": "Message", "type": "string"},
74 "type": {"title": "Error Type", "type": "string"},
75 },
76 },
77 "HTTPValidationError": {
78 "title": "HTTPValidationError",
79 "type": "object",
80 "properties": {
81 "detail": {
82 "title": "Detail",
83 "type": "array",
84 "items": {
85 "$ref": "#/components/schemas/ValidationError"
86 },
87 }
88 },
89 },
90 }
91 },
92 }