|
4 | 4 | from unittest.mock import patch |
5 | 5 |
|
6 | 6 | import uvicorn |
7 | | -from fastapi_cli.cli import DEFAULT_DOCS_URL, app |
| 7 | +from fastapi_cli.cli import app |
8 | 8 | from typer.testing import CliRunner |
9 | 9 |
|
10 | 10 | from tests.utils import changing_dir |
@@ -274,7 +274,7 @@ def test_dev_and_fastapi_app_without_docs_url_set_should_show_default_url_in_std |
274 | 274 | "╭────────── FastAPI CLI - Development mode ───────────╮" in result.output |
275 | 275 | ) |
276 | 276 | assert "│ Serving at: http://127.0.0.1:8000" in result.output |
277 | | - assert f"│ API docs: http://127.0.0.1:8000{DEFAULT_DOCS_URL}" in result.output |
| 277 | + assert "│ API docs: http://127.0.0.1:8000/docs" in result.output |
278 | 278 | assert "│ Running in development mode, for production use:" in result.output |
279 | 279 | assert "│ fastapi run" in result.output |
280 | 280 |
|
@@ -330,6 +330,64 @@ def test_run_and_fastapi_app_without_docs_url_set_should_show_default_url_in_std |
330 | 330 | "╭─────────── FastAPI CLI - Production mode ───────────╮" in result.output |
331 | 331 | ) |
332 | 332 | assert "│ Serving at: http://0.0.0.0:8000" in result.output |
333 | | - assert f"│ API docs: http://0.0.0.0:8000{DEFAULT_DOCS_URL}" in result.output |
| 333 | + assert "│ API docs: http://0.0.0.0:8000/docs" in result.output |
| 334 | + assert "│ Running in production mode, for development use:" in result.output |
| 335 | + assert "│ fastapi dev" in result.output |
| 336 | + |
| 337 | + |
| 338 | +def test_run_and_fastapi_app_docs_url_set_to_none_should_not_show_api_docs_section() -> ( |
| 339 | + None |
| 340 | +): |
| 341 | + with changing_dir(assets_path): |
| 342 | + with patch.object(uvicorn, "run") as mock_run: |
| 343 | + result = runner.invoke(app, ["run", "without_docs_url_none.py"]) |
| 344 | + assert result.exit_code == 0, result.output |
| 345 | + assert mock_run.called |
| 346 | + assert mock_run.call_args |
| 347 | + assert mock_run.call_args.kwargs == { |
| 348 | + "app": "without_docs_url_none:app", |
| 349 | + "host": "0.0.0.0", |
| 350 | + "port": 8000, |
| 351 | + "reload": False, |
| 352 | + "workers": None, |
| 353 | + "root_path": "", |
| 354 | + "proxy_headers": True, |
| 355 | + } |
| 356 | + assert "Using import string without_docs_url_none:app" in result.output |
| 357 | + assert ( |
| 358 | + "╭─────────── FastAPI CLI - Production mode ───────────╮" in result.output |
| 359 | + ) |
| 360 | + assert "│ Serving at: http://0.0.0.0:8000" in result.output |
334 | 361 | assert "│ Running in production mode, for development use:" in result.output |
335 | 362 | assert "│ fastapi dev" in result.output |
| 363 | + |
| 364 | + assert "│ API docs" not in result.output |
| 365 | + |
| 366 | + |
| 367 | +def test_dev_and_fastapi_app_docs_url_set_to_none_should_not_show_api_docs_section() -> ( |
| 368 | + None |
| 369 | +): |
| 370 | + with changing_dir(assets_path): |
| 371 | + with patch.object(uvicorn, "run") as mock_run: |
| 372 | + result = runner.invoke(app, ["dev", "without_docs_url_none.py"]) |
| 373 | + assert result.exit_code == 0, result.output |
| 374 | + assert mock_run.called |
| 375 | + assert mock_run.call_args |
| 376 | + assert mock_run.call_args.kwargs == { |
| 377 | + "app": "without_docs_url_none:app", |
| 378 | + "host": "127.0.0.1", |
| 379 | + "port": 8000, |
| 380 | + "reload": True, |
| 381 | + "workers": None, |
| 382 | + "root_path": "", |
| 383 | + "proxy_headers": True, |
| 384 | + } |
| 385 | + assert "Using import string without_docs_url_none:app" in result.output |
| 386 | + assert ( |
| 387 | + "╭────────── FastAPI CLI - Development mode ───────────" |
| 388 | + ) in result.output |
| 389 | + assert "│ Serving at: http://127.0.0.1:8000" in result.output |
| 390 | + assert "│ Running in development mode, for production use:" in result.output |
| 391 | + assert "│ fastapi run" in result.output |
| 392 | + |
| 393 | + assert "│ API docs" not in result.output |
0 commit comments