@@ -349,6 +349,84 @@ def test_run_env_vars_and_args() -> None:
349349 assert "Documentation at http://0.0.0.0:8080/docs" in result .output
350350
351351
352+ def test_no_openapi () -> None :
353+ with changing_dir (assets_path ):
354+ with patch .object (uvicorn , "run" ) as mock_run :
355+ result = runner .invoke (
356+ app , ["dev" , "single_file_docs.py" , "--app" , "no_openapi" ]
357+ )
358+ assert result .exit_code == 0 , result .output
359+ assert mock_run .called
360+
361+ assert "http://127.0.0.1:8000/docs" not in result .output
362+ assert "http://127.0.0.1:8000/redoc" not in result .output
363+
364+
365+ def test_none_docs () -> None :
366+ with changing_dir (assets_path ):
367+ with patch .object (uvicorn , "run" ) as mock_run :
368+ result = runner .invoke (
369+ app , ["dev" , "single_file_docs.py" , "--app" , "none_docs" ]
370+ )
371+ assert result .exit_code == 0 , result .output
372+ assert mock_run .called
373+
374+ assert "http://127.0.0.1:8000/docs" not in result .output
375+ assert "http://127.0.0.1:8000/redoc" not in result .output
376+
377+
378+ def test_no_docs () -> None :
379+ with changing_dir (assets_path ):
380+ with patch .object (uvicorn , "run" ) as mock_run :
381+ result = runner .invoke (
382+ app , ["dev" , "single_file_docs.py" , "--app" , "no_docs" ]
383+ )
384+ assert result .exit_code == 0 , result .output
385+ assert mock_run .called
386+
387+ assert "http://127.0.0.1:8000/redoc" in result .output
388+ assert "http://127.0.0.1:8000/docs" not in result .output
389+
390+
391+ def test_no_redoc () -> None :
392+ with changing_dir (assets_path ):
393+ with patch .object (uvicorn , "run" ) as mock_run :
394+ result = runner .invoke (
395+ app , ["dev" , "single_file_docs.py" , "--app" , "no_redoc" ]
396+ )
397+ assert result .exit_code == 0 , result .output
398+ assert mock_run .called
399+
400+ assert "http://127.0.0.1:8000/docs" in result .output
401+ assert "http://127.0.0.1:8000/redocs" not in result .output
402+
403+
404+ def test_full_docs () -> None :
405+ with changing_dir (assets_path ):
406+ with patch .object (uvicorn , "run" ) as mock_run :
407+ result = runner .invoke (
408+ app , ["dev" , "single_file_docs.py" , "--app" , "full_docs" ]
409+ )
410+ assert result .exit_code == 0 , result .output
411+ assert mock_run .called
412+
413+ assert "http://127.0.0.1:8000/docs" in result .output
414+ assert "http://127.0.0.1:8000/redoc" in result .output
415+
416+
417+ def test_custom_docs () -> None :
418+ with changing_dir (assets_path ):
419+ with patch .object (uvicorn , "run" ) as mock_run :
420+ result = runner .invoke (
421+ app , ["dev" , "single_file_docs.py" , "--app" , "custom_docs" ]
422+ )
423+ assert result .exit_code == 0 , result .output
424+ assert mock_run .called
425+
426+ assert "http://127.0.0.1:8000/custom-docs-url" in result .output
427+ assert "http://127.0.0.1:8000/custom-redoc-url" in result .output
428+
429+
352430def test_run_error () -> None :
353431 with changing_dir (assets_path ):
354432 result = runner .invoke (app , ["run" , "non_existing_file.py" ])
0 commit comments