From b2a762aac956fc789eee24996ed9ff9c0262f547 Mon Sep 17 00:00:00 2001 From: David Brochart Date: Thu, 27 Jul 2023 12:40:38 +0200 Subject: [PATCH] Add test --- tests/test_app.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/test_app.py diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 00000000..d2516a5a --- /dev/null +++ b/tests/test_app.py @@ -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