-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show percent progress for
fastcdn offline
and add unittest for it
- Loading branch information
1 parent
70872c8
commit 0980f3b
Showing
4 changed files
with
125 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
import shutil | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
def ensure_not_exist(path: Path) -> None: | ||
if path.exists(): | ||
shutil.rmtree(path) | ||
print(f"{path} removed.") | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def prepare(): | ||
static_root = Path(__file__).parent / "static" | ||
ensure_not_exist(static_root) | ||
rc = os.system("fastcdn offline") | ||
assert rc == 0 | ||
assert static_root.exists() | ||
yield | ||
ensure_not_exist(static_root) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
|
||
from fastapi import FastAPI, Request | ||
from fastapi.responses import RedirectResponse | ||
|
||
import fastapi_cdn_host | ||
|
||
app = FastAPI(title="FastAPI CDN host test") | ||
|
||
|
||
@app.get("/", include_in_schema=False) | ||
async def to_docs(): | ||
return RedirectResponse("/docs") | ||
|
||
|
||
@app.get("/app") | ||
async def get_app(request: Request) -> dict: | ||
return {"routes": str(request.app.routes)} | ||
|
||
|
||
fastapi_cdn_host.patch_docs(app) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# mypy: no-disallow-untyped-decorators | ||
import pytest | ||
from httpx import AsyncClient | ||
|
||
from fastapi_cdn_host.client import CdnHostBuilder | ||
from fastapi_cdn_host.utils import TestClient | ||
|
||
default_favicon_url = "https://fastapi.tiangolo.com/img/favicon.png" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
async def client(): | ||
from main import app | ||
|
||
async with TestClient(app) as c: | ||
yield c | ||
|
||
|
||
@pytest.mark.anyio | ||
async def test_docs(client: AsyncClient): # nosec | ||
swagger_ui = CdnHostBuilder.swagger_files | ||
js_url = "/static/" + swagger_ui["js"] | ||
css_url = "/static/" + swagger_ui["css"] | ||
response = await client.get(css_url) | ||
assert response.status_code == 200, f"{response.url=};{response.text=}" | ||
response = await client.get(js_url) | ||
assert response.status_code == 200, response.text | ||
response = await client.get("/docs") | ||
text = response.text | ||
assert response.status_code == 200, text | ||
assert default_favicon_url in text | ||
assert js_url in text | ||
assert css_url in text | ||
response = await client.get("/redoc") | ||
text = response.text | ||
assert response.status_code == 200, text | ||
assert "/static/redoc" in text | ||
response = await client.get("/app") | ||
assert response.status_code == 200 |