-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93f69ef
commit b2a762a
Showing
1 changed file
with
46 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from asphalt.core import Context | ||
from fastapi import APIRouter | ||
from httpx import AsyncClient | ||
from jupyverse_api import Router | ||
from jupyverse_api.app import App | ||
from jupyverse_api.main import JupyverseComponent | ||
|
||
from utils import configure | ||
|
||
|
||
@pytest.mark.asyncio | ||
@pytest.mark.parametrize( | ||
"mount_path", | ||
( | ||
None, | ||
"/foo", | ||
), | ||
) | ||
async def test_mount_path(mount_path, unused_tcp_port): | ||
components = configure({"app": {"type": "app"}}, {"app": {"mount_path": mount_path}}) | ||
|
||
async with Context() as ctx, AsyncClient() as http: | ||
await JupyverseComponent( | ||
components=components, | ||
port=unused_tcp_port, | ||
).start(ctx) | ||
|
||
app = await ctx.request_resource(App) | ||
router = APIRouter() | ||
|
||
@router.get("/") | ||
async def get(): | ||
pass | ||
|
||
Router(app).include_router(router) | ||
|
||
response = await http.get(f"http://127.0.0.1:{unused_tcp_port}") | ||
expected = 200 if mount_path is None else 404 | ||
assert response.status_code == expected | ||
|
||
response = await http.get(f"http://127.0.0.1:{unused_tcp_port}/bar") | ||
assert response.status_code == 404 | ||
|
||
response = await http.get(f"http://127.0.0.1:{unused_tcp_port}/foo") | ||
expected = 404 if mount_path is None else 200 |