Skip to content

Commit 5617ed4

Browse files
committed
feat: remove unused var DEFAULT_DOCS_URL
1 parent fb3ee8e commit 5617ed4

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

src/fastapi_cli/cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import importlib
22
from logging import getLogger
33
from pathlib import Path
4-
from typing import Any, Final, Union
4+
from typing import Any, Union
55

66
import typer
77
import uvicorn
@@ -16,8 +16,6 @@
1616
from . import __version__
1717
from .logging import setup_logging
1818

19-
DEFAULT_DOCS_URL: Final[str] = "/docs"
20-
2119
app = typer.Typer(rich_markup_mode="rich")
2220

2321
setup_logging()

tests/test_cli.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from unittest.mock import patch
55

66
import uvicorn
7-
from fastapi_cli.cli import DEFAULT_DOCS_URL, app
7+
from fastapi_cli.cli import app
88
from typer.testing import CliRunner
99

1010
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
274274
"╭────────── FastAPI CLI - Development mode ───────────╮" in result.output
275275
)
276276
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
278278
assert "│ Running in development mode, for production use:" in result.output
279279
assert "│ fastapi run" in result.output
280280

@@ -330,6 +330,64 @@ def test_run_and_fastapi_app_without_docs_url_set_should_show_default_url_in_std
330330
"╭─────────── FastAPI CLI - Production mode ───────────╮" in result.output
331331
)
332332
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
334361
assert "│ Running in production mode, for development use:" in result.output
335362
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

Comments
 (0)