| 1 |
import importlib |
| 2 |
import os |
| 3 |
from pathlib import Path |
| 4 |
|
| 5 |
import pytest |
| 6 |
from fastapi.testclient import TestClient |
| 7 |
|
| 8 |
from tests.utils import needs_py310, workdir_lock |
| 9 |
|
| 10 |
|
| 11 |
@pytest.fixture( |
| 12 |
name="client", |
| 13 |
params=[ |
| 14 |
pytest.param("tutorial002_py310", marks=needs_py310), |
| 15 |
pytest.param("tutorial002_an_py310", marks=needs_py310), |
| 16 |
], |
| 17 |
) |
| 18 |
def get_client(request: pytest.FixtureRequest): |
| 19 |
mod = importlib.import_module(f"docs_src.background_tasks.{request.param}") |
| 20 |
|
| 21 |
client = TestClient(mod.app) |
| 22 |
return client |
| 23 |
|
| 24 |
|
| 25 |
@workdir_lock |
| 26 |
def test(client: TestClient): |
| 27 |
log = Path("log.txt") |
| 28 |
if log.is_file(): |
| 29 |
os.remove(log) # pragma: no cover |
| 30 |
response = client.post("/send-notification/[email protected]?q=some-query") |
| 31 |
assert response.status_code == 200, response.text |
| 32 |
assert response.json() == {"message": "Message sent"} |
| 33 |
with open("./log.txt") as f: |
| 34 |
assert "found query: some-query\nmessage to [email protected]" in f.read() |