Coverage for tests/test_local_docs.py: 100%
41 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-08-08 03:53 +0000
1import inspect 1abcde
3from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html 1abcde
6def test_strings_in_generated_swagger(): 1abcde
7 sig = inspect.signature(get_swagger_ui_html) 1abcde
8 swagger_js_url = sig.parameters.get("swagger_js_url").default # type: ignore 1abcde
9 swagger_css_url = sig.parameters.get("swagger_css_url").default # type: ignore 1abcde
10 swagger_favicon_url = sig.parameters.get("swagger_favicon_url").default # type: ignore 1abcde
11 html = get_swagger_ui_html(openapi_url="/docs", title="title") 1abcde
12 body_content = html.body.decode() 1abcde
13 assert swagger_js_url in body_content 1abcde
14 assert swagger_css_url in body_content 1abcde
15 assert swagger_favicon_url in body_content 1abcde
18def test_strings_in_custom_swagger(): 1abcde
19 swagger_js_url = "swagger_fake_file.js" 1abcde
20 swagger_css_url = "swagger_fake_file.css" 1abcde
21 swagger_favicon_url = "swagger_fake_file.png" 1abcde
22 html = get_swagger_ui_html( 1abcde
23 openapi_url="/docs",
24 title="title",
25 swagger_js_url=swagger_js_url,
26 swagger_css_url=swagger_css_url,
27 swagger_favicon_url=swagger_favicon_url,
28 )
29 body_content = html.body.decode() 1abcde
30 assert swagger_js_url in body_content 1abcde
31 assert swagger_css_url in body_content 1abcde
32 assert swagger_favicon_url in body_content 1abcde
35def test_strings_in_generated_redoc(): 1abcde
36 sig = inspect.signature(get_redoc_html) 1abcde
37 redoc_js_url = sig.parameters.get("redoc_js_url").default # type: ignore 1abcde
38 redoc_favicon_url = sig.parameters.get("redoc_favicon_url").default # type: ignore 1abcde
39 html = get_redoc_html(openapi_url="/docs", title="title") 1abcde
40 body_content = html.body.decode() 1abcde
41 assert redoc_js_url in body_content 1abcde
42 assert redoc_favicon_url in body_content 1abcde
45def test_strings_in_custom_redoc(): 1abcde
46 redoc_js_url = "fake_redoc_file.js" 1abcde
47 redoc_favicon_url = "fake_redoc_file.png" 1abcde
48 html = get_redoc_html( 1abcde
49 openapi_url="/docs",
50 title="title",
51 redoc_js_url=redoc_js_url,
52 redoc_favicon_url=redoc_favicon_url,
53 )
54 body_content = html.body.decode() 1abcde
55 assert redoc_js_url in body_content 1abcde
56 assert redoc_favicon_url in body_content 1abcde
59def test_google_fonts_in_generated_redoc(): 1abcde
60 body_with_google_fonts = get_redoc_html( 1abcde
61 openapi_url="/docs", title="title"
62 ).body.decode()
63 assert "fonts.googleapis.com" in body_with_google_fonts 1abcde
64 body_without_google_fonts = get_redoc_html( 1abcde
65 openapi_url="/docs", title="title", with_google_fonts=False
66 ).body.decode()
67 assert "fonts.googleapis.com" not in body_without_google_fonts 1abcde