Skip to content

Commit

Permalink
Fix ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Jun 19, 2024
1 parent a17ab93 commit 8c785af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
9 changes: 6 additions & 3 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))'`
Expand All @@ -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
6 changes: 3 additions & 3 deletions tests/prepare_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -31,9 +32,8 @@ def main():
pri_cdn2 = root / "cdn_with_default_asset_path/cdn"
copy_file(pri_cdn2 / "[email protected]", *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__":
Expand Down
14 changes: 8 additions & 6 deletions tests/static_mounted/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

0 comments on commit 8c785af

Please sign in to comment.