File: test_regular_handler_under_asgi_mount_path.py

package info (click to toggle)
litestar 2.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,568 kB
  • sloc: python: 70,588; makefile: 254; javascript: 104; sh: 60
file content (53 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations

from typing import TYPE_CHECKING

from litestar import Litestar, asgi, get
from litestar.enums import ScopeType
from litestar.testing import TestClient

if TYPE_CHECKING:
    from litestar.types.asgi_types import Receive, Scope, Send


async def asgi_app(scope: Scope, receive: Receive, send: Send) -> None:
    assert scope["type"] == ScopeType.HTTP
    await send(
        {
            "type": "http.response.start",
            "status": 200,
            "headers": [
                (b"content-type", b"text/plain"),
                (b"content-length", b"%d" % len(scope["raw_path"])),
            ],
        }
    )
    await send(
        {
            "type": "http.response.body",
            "body": scope["raw_path"],
            "more_body": False,
        }
    )


asgi_handler = asgi("/", is_mount=True)(asgi_app)


@get("/path")
async def get_handler() -> str:
    return "Hello, world!"


app = Litestar(
    route_handlers=[asgi_handler, get_handler],
    openapi_config=None,
    debug=True,
)


def test_regular_handler_under_mounted_asgi_app() -> None:
    # https://github.com/litestar-org/litestar/issues/3429
    with TestClient(app) as client:
        resp = client.get("/some/path")
        assert resp.content == b"/some/path"