Debian Codegraph @

tests/test_tutorial/test_events/test_tutorial002.py

raw
1 import pytest
2 from fastapi import FastAPI
3 from fastapi.testclient import TestClient
4 from inline_snapshot import snapshot
5
6 from tests.utils import workdir_lock
7
8
9 @pytest.fixture(name="app", scope="module")
10 def get_app():
11 with pytest.warns(DeprecationWarning):
12 from docs_src.events.tutorial002_py310 import app
13 yield app
14
15
16 @workdir_lock
17 def test_events(app: FastAPI):
18 with TestClient(app) as client:
19 response = client.get("/items/")
20 assert response.status_code == 200, response.text
21 assert response.json() == [{"name": "Foo"}]
22 with open("log.txt") as log:
23 assert "Application shutdown" in log.read()
24
25
26 @workdir_lock
27 def test_openapi_schema(app: FastAPI):
28 with TestClient(app) as client:
29 response = client.get("/openapi.json")
30 assert response.status_code == 200, response.text
31 assert response.json() == snapshot(
32 {
33 "openapi": "3.1.0",
34 "info": {"title": "FastAPI", "version": "0.1.0"},
35 "paths": {
36 "/items/": {
37 "get": {
38 "responses": {
39 "200": {
40 "description": "Successful Response",
41 "content": {"application/json": {"schema": {}}},
42 }
43 },
44 "summary": "Read Items",
45 "operationId": "read_items_items__get",
46 }
47 }
48 },
49 }
50 )