mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-24 08:16:11 -04:00
✨ Add support for BackgroundTasks parameters (#103)
* ✨ Add support for BackgroundTasks parameters * 🐛 Fix type declaration in dependencies * 🐛 Fix coverage of util in tests
This commit is contained in:
committed by
GitHub
parent
6d77e2ac5f
commit
9b04593260
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from background_tasks.tutorial001 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test():
|
||||
log = Path("log.txt")
|
||||
if log.is_file():
|
||||
os.remove(log) # pragma: no cover
|
||||
response = client.post("/send-notification/foo@example.com")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Notification sent in the background"}
|
||||
with open("./log.txt") as f:
|
||||
assert "notification for foo@example.com: some notification" in f.read()
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from starlette.testclient import TestClient
|
||||
|
||||
from background_tasks.tutorial002 import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
|
||||
def test():
|
||||
log = Path("log.txt")
|
||||
if log.is_file():
|
||||
os.remove(log) # pragma: no cover
|
||||
response = client.post("/send-notification/foo@example.com?q=some-query")
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"message": "Message sent"}
|
||||
with open("./log.txt") as f:
|
||||
assert "found query: some-query\nmessage to foo@example.com" in f.read()
|
||||
Reference in New Issue
Block a user