Coverage for tests/test_custom_swagger_ui_redirect.py: 100%
23 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
1from fastapi import FastAPI 1abcde
2from fastapi.testclient import TestClient 1abcde
4swagger_ui_oauth2_redirect_url = "/docs/redirect" 1abcde
6app = FastAPI(swagger_ui_oauth2_redirect_url=swagger_ui_oauth2_redirect_url) 1abcde
9@app.get("/items/") 1abcde
10async def read_items(): 1abcde
11 return {"id": "foo"} 1abcde
14client = TestClient(app) 1abcde
17def test_swagger_ui(): 1abcde
18 response = client.get("/docs") 1abcde
19 assert response.status_code == 200, response.text 1abcde
20 assert response.headers["content-type"] == "text/html; charset=utf-8" 1abcde
21 assert "swagger-ui-dist" in response.text 1abcde
22 print(client.base_url) 1abcde
23 assert ( 1abcde
24 f"oauth2RedirectUrl: window.location.origin + '{swagger_ui_oauth2_redirect_url}'"
25 in response.text
26 )
29def test_swagger_ui_oauth2_redirect(): 1abcde
30 response = client.get(swagger_ui_oauth2_redirect_url) 1abcde
31 assert response.status_code == 200, response.text 1abcde
32 assert response.headers["content-type"] == "text/html; charset=utf-8" 1abcde
33 assert "window.opener.swaggerUIRedirectOauth2" in response.text 1abcde
36def test_response(): 1abcde
37 response = client.get("/items/") 1abcde
38 assert response.json() == {"id": "foo"} 1abcde