Browse Source

test: add test for redoc parameters

pull/12955/head
Robert Stein 5 months ago
parent
commit
24bb427d6c
No known key found for this signature in database GPG Key ID: 5FF6BC0BCE162A99
  1. 2
      fastapi/openapi/docs.py
  2. 11
      tests/test_local_docs.py

2
fastapi/openapi/docs.py

@ -229,7 +229,7 @@ def get_redoc_html(
config_string = "" config_string = ""
if redoc_ui_parameters: if redoc_ui_parameters:
for key, value in redoc_ui_parameters.items(): for key, value in redoc_ui_parameters.items():
config_string += f" {key}={value}" config_string += f" {key}=\"{value}\""
html = f""" html = f"""
<!DOCTYPE html> <!DOCTYPE html>

11
tests/test_local_docs.py

@ -65,3 +65,14 @@ def test_google_fonts_in_generated_redoc():
openapi_url="/docs", title="title", with_google_fonts=False openapi_url="/docs", title="title", with_google_fonts=False
).body.decode() ).body.decode()
assert "fonts.googleapis.com" not in body_without_google_fonts assert "fonts.googleapis.com" not in body_without_google_fonts
def test_generated_redoc_with_parameters():
body_with_parameters = get_redoc_html(
openapi_url="/docs", title="title", with_google_fonts=False, redoc_ui_parameters={"disable-search": "true"}
).body.decode()
assert "disable-search=\"true\"" in body_with_parameters
body_without_parameters = get_redoc_html(
openapi_url="/docs", title="title", with_google_fonts=False
).body.decode()
assert "disable-search=\"true\"" not in body_without_parameters

Loading…
Cancel
Save