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. 2
      tests/test_offline_docs/static/redoc.js
  2. 2
      tests/test_offline_docs/static/swagger.css
  3. 2
      tests/test_offline_docs/static/swagger.js
  4. 54
      tests/test_offline_docs/test_root_path_with_static_mount.py

2
tests/test_offline_docs/static/redoc.js

@ -1,3 +1,3 @@
function bar() { function bar() {
return "bar" return "bar"
} }

2
tests/test_offline_docs/static/swagger.css

@ -1 +1 @@
.swagger-ui{color:#3b4151;} .swagger-ui{color:#3b4151;}

2
tests/test_offline_docs/static/swagger.js

@ -1,3 +1,3 @@
function foo() { function foo() {
return "foo" return "foo"
} }

54
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,27 +21,25 @@ 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",
docs_url=None, docs_url=None,
redoc_url=None, redoc_url=None,
**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,27 +90,25 @@ 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",
docs_url=None, docs_url=None,
redoc_url=None, redoc_url=None,
**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.
""" """
@ -141,4 +135,4 @@ def test_redoc_docs_with_static_assets(
response = client.get(f"{root_path}/static/redoc.js") response = client.get(f"{root_path}/static/redoc.js")
assert response.status_code == 200 assert response.status_code == 200
assert f"{root_path}/static/redoc.js" in redoc_html assert f"{root_path}/static/redoc.js" in redoc_html

Loading…
Cancel
Save