Skip to content

Commit

Permalink
fixing ci error
Browse files Browse the repository at this point in the history
  • Loading branch information
waketzheng committed Apr 9, 2024
1 parent 572c39c commit aa1d640
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
6 changes: 5 additions & 1 deletion tests/extend_choices/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ async def get_app(request: Request) -> dict:
monkey_patch_for_docs_ui(
app,
docs_cdn_host=CdnHostEnum.extend(
("https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M", NORMAL_ASSET_PATH) # 字节
(
"https://raw.githubusercontent.com/swagger-api/swagger-ui",
("/v{version}/dist/", ""),
),
("https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M", NORMAL_ASSET_PATH),
),
)
29 changes: 18 additions & 11 deletions tests/extend_choices/test_extend.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import AsyncClient
from main import app

from fastapi_cdn_host.client import CdnHostBuilder, CdnHostEnum
from fastapi_cdn_host.client import NORMAL_ASSET_PATH, CdnHostBuilder, CdnHostEnum


@pytest.fixture(scope="module")
Expand All @@ -17,24 +17,31 @@ async def client():
yield c


@pytest.mark.anyio
async def test_docs(client: AsyncClient): # nosec
urls = await CdnHostBuilder.sniff_the_fastest(
async def _get_cdn_host():
return await CdnHostBuilder.sniff_the_fastest(
choices=CdnHostEnum.extend(
("https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M", NORMAL_ASSET_PATH),
(
"https://cdn.bootcdn.net/ajax/libs",
("/swagger-ui/{version}/", ""),
),
("https://cdn.staticfile.org", ("/swagger-ui/{version}/", "")),
(
"https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M",
("/swagger-ui/{version}/", ""),
"https://raw.githubusercontent.com/swagger-api/swagger-ui",
("/v{version}/dist/", ""),
),
)
)


@pytest.mark.anyio
async def test_docs(client: AsyncClient): # nosec
urls = await _get_cdn_host()
response = await client.get("/docs")
text = response.text
assert response.status_code == 200, text
if urls.js not in text:
# Sometimes there are several cdn hosts that have good response speed.
for _ in range(3):
new_urls = await _get_cdn_host()
if new_urls.js != urls.js:
urls = new_urls
break
assert urls.js in text
assert urls.css in text
response2 = await client.get("/redoc")
Expand Down

0 comments on commit aa1d640

Please sign in to comment.