Browse Source

🎨 [pre-commit.ci] Auto format from pre-commit.com hooks

pull/13825/head
pre-commit-ci[bot] 4 weeks ago
parent
commit
0de2e7c3e9
  1. 44
      tests/test_offline_docs/test_root_path_with_static_mount.py

44
tests/test_offline_docs/test_root_path_with_static_mount.py

@ -1,8 +1,7 @@
import pytest import pytest
from fastapi import FastAPI, Request from fastapi import FastAPI, Request
from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from fastapi.openapi.docs import get_swagger_ui_html, get_redoc_html
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
@ -13,7 +12,7 @@ from fastapi.testclient import TestClient
("/api", False), ("/api", False),
("", True), ("", True),
("", False), ("", False),
] ],
) )
def test_swagger_docs_with_static_assets( def test_swagger_docs_with_static_assets(
root_path: str, root_path: str,
@ -22,13 +21,9 @@ def test_swagger_docs_with_static_assets(
app_kwargs = {} app_kwargs = {}
client_kwargs = {} client_kwargs = {}
if not using_test_client: if not using_test_client:
app_kwargs = { app_kwargs = {"root_path": root_path}
"root_path": root_path
}
if using_test_client: if using_test_client:
client_kwargs = { client_kwargs = {"root_path": root_path}
"root_path": root_path
}
app = FastAPI( app = FastAPI(
title="FastAPI", title="FastAPI",
@ -37,12 +32,14 @@ def test_swagger_docs_with_static_assets(
**app_kwargs, **app_kwargs,
) )
app.mount("/static", StaticFiles(directory="tests/test_offline_docs/static"), name="static") app.mount(
"/static",
StaticFiles(directory="tests/test_offline_docs/static"),
name="static",
)
@app.get("/") @app.get("/")
async def custom_swagger_ui_html( async def custom_swagger_ui_html(req: Request):
req: Request
):
""" """
Sets up a localized version of the Swagger (OpenAPI) docs that can be run without assets from the Internet. Sets up a localized version of the Swagger (OpenAPI) docs that can be run without assets from the Internet.
""" """
@ -54,7 +51,6 @@ def test_swagger_docs_with_static_assets(
swagger_css_url=f"{root_path}/static/swagger.css", swagger_css_url=f"{root_path}/static/swagger.css",
) )
client = TestClient(app, **client_kwargs) client = TestClient(app, **client_kwargs)
response = client.get("/") response = client.get("/")
@ -85,7 +81,7 @@ def test_swagger_docs_with_static_assets(
("/api", False), ("/api", False),
("", True), ("", True),
("", False), ("", False),
] ],
) )
def test_redoc_docs_with_static_assets( def test_redoc_docs_with_static_assets(
root_path: str, root_path: str,
@ -94,13 +90,9 @@ def test_redoc_docs_with_static_assets(
app_kwargs = {} app_kwargs = {}
client_kwargs = {} client_kwargs = {}
if not using_test_client: if not using_test_client:
app_kwargs = { app_kwargs = {"root_path": root_path}
"root_path": root_path
}
if using_test_client: if using_test_client:
client_kwargs = { client_kwargs = {"root_path": root_path}
"root_path": root_path
}
app = FastAPI( app = FastAPI(
title="FastAPI", title="FastAPI",
@ -109,12 +101,14 @@ def test_redoc_docs_with_static_assets(
**app_kwargs, **app_kwargs,
) )
app.mount("/static", StaticFiles(directory="tests/test_offline_docs/static"), name="static") app.mount(
"/static",
StaticFiles(directory="tests/test_offline_docs/static"),
name="static",
)
@app.get("/") @app.get("/")
async def custom_redoc_html( async def custom_redoc_html(req: Request):
req: Request
):
""" """
Sets up a localized version of the Swagger (OpenAPI) docs that can be run without assets from the Internet. Sets up a localized version of the Swagger (OpenAPI) docs that can be run without assets from the Internet.
""" """

Loading…
Cancel
Save