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

15 statements  

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

1import os 1eabcd

2from pathlib import Path 1eabcd

3 

4from fastapi.testclient import TestClient 1eabcd

5 

6from ...utils import needs_py39 1eabcd

7 

8 

9@needs_py39 1eabcd

10def test(): 1eabcd

11 from docs_src.background_tasks.tutorial002_an_py39 import app 1abcd

12 

13 client = TestClient(app) 1abcd

14 log = Path("log.txt") 1abcd

15 if log.is_file(): 1abcd

16 os.remove(log) # pragma: no cover 1abcd

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

18 assert response.status_code == 200, response.text 1abcd

19 assert response.json() == {"message": "Message sent"} 1abcd

20 with open("./log.txt") as f: 1abcd

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