diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 00000000..343a1629 --- /dev/null +++ b/tests/test_app.py @@ -0,0 +1,43 @@ +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(follow_redirects=True)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