diff --git a/scripts/test.sh b/scripts/test.sh index fede2c3..82daf07 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,6 +4,7 @@ set -e set -x [ -f ../pyproject.toml ] && cd .. +WORK_DIR="$PWD" python tests/prepare_media.py directories=`python -c 'from pathlib import Path;ds=[p.name for p in Path("tests").glob("*") if p.is_dir()];print(" ".join(ds))'` @@ -14,8 +15,10 @@ do cd ../$folder && coverage run -m pytest -s test_*.py done -cd ../../examples +EG_DIR='examples/normal' +cd $WORK_DIR/$EG_DIR coverage run -m pytest -s test_*.py -cd .. -coverage combine tests/*/.coverage examples/.coverage + +cd $WORK_DIR +coverage combine $EG_DIR/.coverage tests/*/.coverage coverage report -m diff --git a/tests/prepare_media.py b/tests/prepare_media.py index 64fcf92..b0e4160 100755 --- a/tests/prepare_media.py +++ b/tests/prepare_media.py @@ -23,6 +23,7 @@ def main(): swagger_ui_files = list(src.glob("swagger-ui*")) redoc_file = src / "redoc.standalone.js" favicon_file = src / "favicon.ico" + copy_file(root / "static_auto" / "static", *swagger_ui_files) copy_file(root / "static_favicon_without_swagger_ui/static", favicon_file) pri_cdn = root / "private_cdn/cdn" @@ -31,9 +32,8 @@ def main(): pri_cdn2 = root / "cdn_with_default_asset_path/cdn" copy_file(pri_cdn2 / "swagger-ui-dist@5.9.0", *swagger_ui_files) copy_file(pri_cdn2 / "redoc@next/bundles", redoc_file) - copy_file( - root / "simple_asset_path/cdn", redoc_file, favicon_file, *swagger_ui_files - ) + simple_path = root / "simple_asset_path/cdn" + copy_file(simple_path, redoc_file, favicon_file, *swagger_ui_files) if __name__ == "__main__": diff --git a/tests/static_mounted/main.py b/tests/static_mounted/main.py index 36a31f2..04b6bf7 100644 --- a/tests/static_mounted/main.py +++ b/tests/static_mounted/main.py @@ -4,12 +4,17 @@ from fastapi.responses import RedirectResponse from fastapi.staticfiles import StaticFiles -from fastapi_cdn_host import monkey_patch_for_docs_ui +import fastapi_cdn_host app = FastAPI(title="FastAPI CDN host test") STATIC_ROOT = Path(__file__).parent.parent / "static_auto" / "static" -app.mount("/static", StaticFiles(directory=STATIC_ROOT), name="static") -app.mount("/media", StaticFiles(directory=STATIC_ROOT), name="media") +app.mount( + "/static", StaticFiles(directory=STATIC_ROOT, follow_symlink=True), name="static" +) +app.mount( + "/media", StaticFiles(directory=STATIC_ROOT, follow_symlink=True), name="media" +) +fastapi_cdn_host.patch_docs(app) # Note: Can't put it before static/media mount @app.get("/", include_in_schema=False) @@ -20,6 +25,3 @@ async def to_docs(): @app.get("/app") async def get_app(request: Request) -> dict: return {"routes": str(request.app.routes)} - - -monkey_patch_for_docs_ui(app)