Coverage for tests/test_tutorial/test_events/test_tutorial002.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2025-01-13 13:38 +0000

1import pytest 1abcde

2from fastapi import FastAPI 1abcde

3from fastapi.testclient import TestClient 1abcde

4 

5 

6@pytest.fixture(name="app", scope="module") 1abcde

7def get_app(): 1abcde

8 with pytest.warns(DeprecationWarning): 1abcde

9 from docs_src.events.tutorial002 import app 1abcde

10 yield app 1abcde

11 

12 

13def test_events(app: FastAPI): 1abcde

14 with TestClient(app) as client: 1fghij

15 response = client.get("/items/") 1fghij

16 assert response.status_code == 200, response.text 1fghij

17 assert response.json() == [{"name": "Foo"}] 1fghij

18 with open("log.txt") as log: 1fghij

19 assert "Application shutdown" in log.read() 1fghij

20 

21 

22def test_openapi_schema(app: FastAPI): 1abcde

23 with TestClient(app) as client: 1klmno

24 response = client.get("/openapi.json") 1klmno

25 assert response.status_code == 200, response.text 1klmno

26 assert response.json() == { 1klmno

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 }