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

13 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-08-08 03:53 +0000

1import os 1abcde

2from pathlib import Path 1abcde

3 

4from fastapi.testclient import TestClient 1abcde

5 

6from docs_src.background_tasks.tutorial002 import app 1abcde

7 

8client = TestClient(app) 1abcde

9 

10 

11def test(): 1abcde

12 log = Path("log.txt") 1abcde

13 if log.is_file(): 1abcde

14 os.remove(log) # pragma: no cover 1abcde

15 response = client.post("/send-notification/foo@example.com?q=some-query") 1abcde

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

17 assert response.json() == {"message": "Message sent"} 1abcde

18 with open("./log.txt") as f: 1abcde

19 assert "found query: some-query\nmessage to foo@example.com" in f.read() 1abcde