alv2017
4 days ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
14 additions and
13 deletions
-
tests/test_tutorial/test_background_tasks/conftest.py
-
tests/test_tutorial/test_background_tasks/test_tutorial001.py
-
tests/test_tutorial/test_background_tasks/test_tutorial002.py
|
@ -0,0 +1,12 @@ |
|
|
|
|
|
import os |
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(name="path_to_log_file") |
|
|
|
|
|
def log_path(): |
|
|
|
|
|
log = Path("log.txt") |
|
|
|
|
|
yield log |
|
|
|
|
|
if log.is_file(): |
|
|
|
|
|
os.remove(log) # pragma: no cover |
|
@ -1,6 +1,3 @@ |
|
|
import os |
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
|
from docs_src.background_tasks.tutorial001 import app |
|
|
from docs_src.background_tasks.tutorial001 import app |
|
@ -8,10 +5,7 @@ from docs_src.background_tasks.tutorial001 import app |
|
|
client = TestClient(app) |
|
|
client = TestClient(app) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test(): |
|
|
def test(path_to_log_file): |
|
|
log = Path("log.txt") |
|
|
|
|
|
if log.is_file(): |
|
|
|
|
|
os.remove(log) # pragma: no cover |
|
|
|
|
|
response = client.post("/send-notification/foo@example.com") |
|
|
response = client.post("/send-notification/foo@example.com") |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.json() == {"message": "Notification sent in the background"} |
|
|
assert response.json() == {"message": "Notification sent in the background"} |
|
|
|
@ -1,6 +1,4 @@ |
|
|
import importlib |
|
|
import importlib |
|
|
import os |
|
|
|
|
|
from pathlib import Path |
|
|
|
|
|
|
|
|
|
|
|
import pytest |
|
|
import pytest |
|
|
from fastapi.testclient import TestClient |
|
|
from fastapi.testclient import TestClient |
|
@ -25,10 +23,7 @@ def get_client(request: pytest.FixtureRequest): |
|
|
return client |
|
|
return client |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test(client: TestClient): |
|
|
def test(client: TestClient, path_to_log_file): |
|
|
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") |
|
|
response = client.post("/send-notification/foo@example.com?q=some-query") |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.status_code == 200, response.text |
|
|
assert response.json() == {"message": "Message sent"} |
|
|
assert response.json() == {"message": "Message sent"} |
|
|