Browse Source

Add test for `docs_src.first_steps.tutorial002.py` and `docs_src.first_steps.tutorial003.py`

pull/14569/head
Yurii Motov 7 months ago
parent
commit
ec9da27cb0
  1. 21
      tests/test_tutorial/test_first_steps/test_tutorial001_tutorial002_tutorial003.py

21
tests/test_tutorial/test_first_steps/test_tutorial001.py → tests/test_tutorial/test_first_steps/test_tutorial001_tutorial002_tutorial003.py

@ -1,9 +1,22 @@
import importlib
import pytest import pytest
from fastapi.testclient import TestClient 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( @pytest.mark.parametrize(
@ -13,13 +26,13 @@ client = TestClient(app)
("/nonexistent", 404, {"detail": "Not Found"}), ("/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) response = client.get(path)
assert response.status_code == expected_status assert response.status_code == expected_status
assert response.json() == expected_response assert response.json() == expected_response
def test_openapi_schema(): def test_openapi_schema(client: TestClient):
response = client.get("/openapi.json") response = client.get("/openapi.json")
assert response.status_code == 200 assert response.status_code == 200
assert response.json() == { assert response.json() == {
Loading…
Cancel
Save