|
|
|
@ -1,9 +1,22 @@ |
|
|
|
import importlib |
|
|
|
|
|
|
|
import pytest |
|
|
|
from fastapi.testclient import TestClient |
|
|
|
|
|
|
|
from docs_src.first_steps.tutorial001 import app |
|
|
|
|
|
|
|
client = TestClient(app) |
|
|
|
@pytest.fixture( |
|
|
|
name="client", |
|
|
|
params=[ |
|
|
|
("tutorial001", "app"), |
|
|
|
("tutorial002", "my_awesome_api"), |
|
|
|
("tutorial003", "app"), |
|
|
|
], |
|
|
|
) |
|
|
|
def get_client(request: pytest.FixtureRequest): |
|
|
|
mod = importlib.import_module(f"docs_src.first_steps.{request.param[0]}") |
|
|
|
app = getattr(mod, request.param[1]) |
|
|
|
client = TestClient(app) |
|
|
|
return client |
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize( |
|
|
|
@ -13,13 +26,13 @@ client = TestClient(app) |
|
|
|
("/nonexistent", 404, {"detail": "Not Found"}), |
|
|
|
], |
|
|
|
) |
|
|
|
def test_get_path(path, expected_status, expected_response): |
|
|
|
def test_get_path(client: TestClient, path, expected_status, expected_response): |
|
|
|
response = client.get(path) |
|
|
|
assert response.status_code == expected_status |
|
|
|
assert response.json() == expected_response |
|
|
|
|
|
|
|
|
|
|
|
def test_openapi_schema(): |
|
|
|
def test_openapi_schema(client: TestClient): |
|
|
|
response = client.get("/openapi.json") |
|
|
|
assert response.status_code == 200 |
|
|
|
assert response.json() == { |