| 1 |
import os |
| 2 |
from pathlib import Path |
| 3 |
|
| 4 |
import pytest |
| 5 |
from fastapi.testclient import TestClient |
| 6 |
|
| 7 |
from tests.utils import workdir_lock |
| 8 |
|
| 9 |
|
| 10 |
@pytest.fixture(scope="module") |
| 11 |
def client(): |
| 12 |
static_dir: Path = Path(os.getcwd()) / "static" |
| 13 |
print(static_dir) |
| 14 |
static_dir.mkdir(exist_ok=True) |
| 15 |
from docs_src.custom_docs_ui.tutorial001_py310 import app |
| 16 |
|
| 17 |
with TestClient(app) as client: |
| 18 |
yield client |
| 19 |
static_dir.rmdir() |
| 20 |
|
| 21 |
|
| 22 |
@workdir_lock |
| 23 |
def test_swagger_ui_html(client: TestClient): |
| 24 |
response = client.get("/docs") |
| 25 |
assert response.status_code == 200, response.text |
| 26 |
assert "https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js" in response.text |
| 27 |
assert "https://unpkg.com/swagger-ui-dist@5/swagger-ui.css" in response.text |
| 28 |
|
| 29 |
|
| 30 |
@workdir_lock |
| 31 |
def test_swagger_ui_oauth2_redirect_html(client: TestClient): |
| 32 |
response = client.get("/docs/oauth2-redirect") |
| 33 |
assert response.status_code == 200, response.text |
| 34 |
assert "window.opener.swaggerUIRedirectOauth2" in response.text |
| 35 |
|
| 36 |
|
| 37 |
@workdir_lock |
| 38 |
def test_redoc_html(client: TestClient): |
| 39 |
response = client.get("/redoc") |
| 40 |
assert response.status_code == 200, response.text |
| 41 |
assert "https://unpkg.com/redoc@2/bundles/redoc.standalone.js" in response.text |
| 42 |
|
| 43 |
|
| 44 |
@workdir_lock |
| 45 |
def test_api(client: TestClient): |
| 46 |
response = client.get("/users/john") |
| 47 |
assert response.status_code == 200, response.text |
| 48 |
assert response.json()["message"] == "Hello john" |