Debian Codegraph @

tests/test_tutorial/test_background_tasks/test_tutorial001.py

raw
1 import os
2 from pathlib import Path
3
4 from fastapi.testclient import TestClient
5
6 from docs_src.background_tasks.tutorial001_py310 import app
7 from tests.utils import workdir_lock
8
9 client = TestClient(app)
10
11
12 @workdir_lock
13 def test():
14 log = Path("log.txt")
15 if log.is_file():
16 os.remove(log) # pragma: no cover
17 response = client.post("/send-notification/[email protected]")
18 assert response.status_code == 200, response.text
19 assert response.json() == {"message": "Notification sent in the background"}
20 with open("./log.txt") as f:
21 assert "notification for [email protected]: some notification" in f.read()