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:
Sebastián Ramírez
2019-03-24 23:33:35 +04:00
committed by GitHub
parent 6d77e2ac5f
commit 9b04593260
11 changed files with 207 additions and 8 deletions

View File

View File

@@ -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()

View File

@@ -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()