Coverage for tests/test_tutorial/test_events/test_tutorial002.py: 100%
20 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 pytest 1abcdef
2from fastapi import FastAPI 1abcdef
3from fastapi.testclient import TestClient 1abcdef
6@pytest.fixture(name="app", scope="module") 1abcdef
7def get_app(): 1abcdef
8 with pytest.warns(DeprecationWarning): 1abcdef
9 from docs_src.events.tutorial002 import app 1abcdef
10 yield app 1abcdef
13def test_events(app: FastAPI): 1abcdef
14 with TestClient(app) as client: 1ghijkl
15 response = client.get("/items/") 1ghijkl
16 assert response.status_code == 200, response.text 1ghijkl
17 assert response.json() == [{"name": "Foo"}] 1ghijkl
18 with open("log.txt") as log: 1ghijkl
19 assert "Application shutdown" in log.read() 1ghijkl
22def test_openapi_schema(app: FastAPI): 1abcdef
23 with TestClient(app) as client: 1mnopqr
24 response = client.get("/openapi.json") 1mnopqr
25 assert response.status_code == 200, response.text 1mnopqr
26 assert response.json() == { 1mnopqr
27 "openapi": "3.1.0",
28 "info": {"title": "FastAPI", "version": "0.1.0"},
29 "paths": {
30 "/items/": {
31 "get": {
32 "responses": {
33 "200": {
34 "description": "Successful Response",
35 "content": {"application/json": {"schema": {}}},
36 }
37 },
38 "summary": "Read Items",
39 "operationId": "read_items_items__get",
40 }
41 }
42 },
43 }