@@ -192,6 +192,84 @@ def test_run_args() -> None:
192
192
)
193
193
194
194
195
+ def test_no_openapi () -> None :
196
+ with changing_dir (assets_path ):
197
+ with patch .object (uvicorn , "run" ) as mock_run :
198
+ result = runner .invoke (
199
+ app , ["dev" , "single_file_docs.py" , "--app" , "no_openapi" ]
200
+ )
201
+ assert result .exit_code == 0 , result .output
202
+ assert mock_run .called
203
+
204
+ assert "http://127.0.0.1:8000/docs" not in result .output
205
+ assert "http://127.0.0.1:8000/redoc" not in result .output
206
+
207
+
208
+ def test_none_docs () -> None :
209
+ with changing_dir (assets_path ):
210
+ with patch .object (uvicorn , "run" ) as mock_run :
211
+ result = runner .invoke (
212
+ app , ["dev" , "single_file_docs.py" , "--app" , "none_docs" ]
213
+ )
214
+ assert result .exit_code == 0 , result .output
215
+ assert mock_run .called
216
+
217
+ assert "http://127.0.0.1:8000/docs" not in result .output
218
+ assert "http://127.0.0.1:8000/redoc" not in result .output
219
+
220
+
221
+ def test_no_docs () -> None :
222
+ with changing_dir (assets_path ):
223
+ with patch .object (uvicorn , "run" ) as mock_run :
224
+ result = runner .invoke (
225
+ app , ["dev" , "single_file_docs.py" , "--app" , "no_docs" ]
226
+ )
227
+ assert result .exit_code == 0 , result .output
228
+ assert mock_run .called
229
+
230
+ assert "http://127.0.0.1:8000/redoc" in result .output
231
+ assert "http://127.0.0.1:8000/docs" not in result .output
232
+
233
+
234
+ def test_no_redoc () -> None :
235
+ with changing_dir (assets_path ):
236
+ with patch .object (uvicorn , "run" ) as mock_run :
237
+ result = runner .invoke (
238
+ app , ["dev" , "single_file_docs.py" , "--app" , "no_redoc" ]
239
+ )
240
+ assert result .exit_code == 0 , result .output
241
+ assert mock_run .called
242
+
243
+ assert "http://127.0.0.1:8000/docs" in result .output
244
+ assert "http://127.0.0.1:8000/redocs" not in result .output
245
+
246
+
247
+ def test_full_docs () -> None :
248
+ with changing_dir (assets_path ):
249
+ with patch .object (uvicorn , "run" ) as mock_run :
250
+ result = runner .invoke (
251
+ app , ["dev" , "single_file_docs.py" , "--app" , "full_docs" ]
252
+ )
253
+ assert result .exit_code == 0 , result .output
254
+ assert mock_run .called
255
+
256
+ assert "http://127.0.0.1:8000/docs" in result .output
257
+ assert "http://127.0.0.1:8000/redoc" in result .output
258
+
259
+
260
+ def test_custom_docs () -> None :
261
+ with changing_dir (assets_path ):
262
+ with patch .object (uvicorn , "run" ) as mock_run :
263
+ result = runner .invoke (
264
+ app , ["dev" , "single_file_docs.py" , "--app" , "custom_docs" ]
265
+ )
266
+ assert result .exit_code == 0 , result .output
267
+ assert mock_run .called
268
+
269
+ assert "http://127.0.0.1:8000/custom-docs-url" in result .output
270
+ assert "http://127.0.0.1:8000/custom-redoc-url" in result .output
271
+
272
+
195
273
def test_run_error () -> None :
196
274
with changing_dir (assets_path ):
197
275
result = runner .invoke (app , ["run" , "non_existing_file.py" ])
0 commit comments