Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed Jun 18, 2023
1 parent 752973e commit 75f55ea
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions starlette/routing.py
Expand Up @@ -820,6 +820,7 @@ def mount(
self, path: str, app: ASGIApp, name: typing.Optional[str] = None
) -> None: # pragma: nocover
route = Mount(path, app=app, name=name)
self._merge_router_events(app.router)
self.routes.append(route)

def host(
Expand Down
36 changes: 36 additions & 0 deletions tests/test_applications.py
Expand Up @@ -15,6 +15,7 @@
from starlette.responses import JSONResponse, PlainTextResponse
from starlette.routing import Host, Mount, Route, Router, WebSocketRoute
from starlette.staticfiles import StaticFiles
from starlette.testclient import TestClient
from starlette.types import ASGIApp
from starlette.websockets import WebSocket

Expand Down Expand Up @@ -281,6 +282,41 @@ def test_app_mount(tmpdir, test_client_factory):
assert response.text == "Method Not Allowed"


def test_app_mount_events():
app = Starlette()
nested_app = Starlette()

with pytest.warns(DeprecationWarning):

@nested_app.on_event("startup")
async def startup():
app.state.nested_started = True

app.mount(path="/", app=nested_app)

with TestClient(app):
assert app.state.nested_started is True


def test_app_mount_lifespan():
app = Starlette()

@asynccontextmanager
async def lifespan(app: Starlette):
app.state.nested_started = True
yield {"router": True}
app.state.nested_shutdown = True

nested_app = Starlette(lifespan=lifespan)
app.mount(path="/", app=nested_app)

with TestClient(app):
assert app.state.nested_started is True

assert app.state.nested_started is True
assert app.state.nested_shutdown is True


def test_app_debug(test_client_factory):
async def homepage(request):
raise RuntimeError()
Expand Down

0 comments on commit 75f55ea

Please sign in to comment.