Coverage for tests / test_local_docs.py: 100%

41 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-12 18:15 +0000

1import inspect 1ghij

2 

3from fastapi.openapi.docs import get_redoc_html, get_swagger_ui_html 1ghij

4 

5 

6def test_strings_in_generated_swagger(): 1ghij

7 sig = inspect.signature(get_swagger_ui_html) 1abc

8 swagger_js_url = sig.parameters.get("swagger_js_url").default # type: ignore 1abc

9 swagger_css_url = sig.parameters.get("swagger_css_url").default # type: ignore 1abc

10 swagger_favicon_url = sig.parameters.get("swagger_favicon_url").default # type: ignore 1abc

11 html = get_swagger_ui_html(openapi_url="/docs", title="title") 1abc

12 body_content = html.body.decode() 1abc

13 assert swagger_js_url in body_content 1abc

14 assert swagger_css_url in body_content 1abc

15 assert swagger_favicon_url in body_content 1abc

16 

17 

18def test_strings_in_custom_swagger(): 1ghij

19 swagger_js_url = "swagger_fake_file.js" 1def

20 swagger_css_url = "swagger_fake_file.css" 1def

21 swagger_favicon_url = "swagger_fake_file.png" 1def

22 html = get_swagger_ui_html( 1def

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() 1def

30 assert swagger_js_url in body_content 1def

31 assert swagger_css_url in body_content 1def

32 assert swagger_favicon_url in body_content 1def

33 

34 

35def test_strings_in_generated_redoc(): 1ghij

36 sig = inspect.signature(get_redoc_html) 1klm

37 redoc_js_url = sig.parameters.get("redoc_js_url").default # type: ignore 1klm

38 redoc_favicon_url = sig.parameters.get("redoc_favicon_url").default # type: ignore 1klm

39 html = get_redoc_html(openapi_url="/docs", title="title") 1klm

40 body_content = html.body.decode() 1klm

41 assert redoc_js_url in body_content 1klm

42 assert redoc_favicon_url in body_content 1klm

43 

44 

45def test_strings_in_custom_redoc(): 1ghij

46 redoc_js_url = "fake_redoc_file.js" 1nop

47 redoc_favicon_url = "fake_redoc_file.png" 1nop

48 html = get_redoc_html( 1nop

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() 1nop

55 assert redoc_js_url in body_content 1nop

56 assert redoc_favicon_url in body_content 1nop

57 

58 

59def test_google_fonts_in_generated_redoc(): 1ghij

60 body_with_google_fonts = get_redoc_html( 1qrs

61 openapi_url="/docs", title="title" 

62 ).body.decode() 

63 assert "fonts.googleapis.com" in body_with_google_fonts 1qrs

64 body_without_google_fonts = get_redoc_html( 1qrs

65 openapi_url="/docs", title="title", with_google_fonts=False 

66 ).body.decode() 

67 assert "fonts.googleapis.com" not in body_without_google_fonts 1qrs