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

15 statements  

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

1import os 1deabc

2from pathlib import Path 1deabc

3 

4from fastapi.testclient import TestClient 1deabc

5 

6from ...utils import needs_py310 1deabc

7 

8 

9@needs_py310 1deabc

10def test(): 1deabc

11 from docs_src.background_tasks.tutorial002_an_py310 import app 1abc

12 

13 client = TestClient(app) 1abc

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

15 if log.is_file(): 1abc

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

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

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

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

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

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