File: test_routing.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 (32 lines) | stat: -rw-r--r-- 1,003 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
from typing import TYPE_CHECKING

import pytest
from docs.examples.routing import mount_custom_app, mounting_starlette_app

from litestar.status_codes import HTTP_200_OK
from litestar.testing import TestClient

if TYPE_CHECKING:
    from litestar import Litestar


@pytest.mark.parametrize(
    "app",
    (
        mount_custom_app.app,
        mounting_starlette_app.app,
    ),
)
def test_mounting_asgi_app_example(app: "Litestar") -> None:
    with TestClient(app) as client:
        response = client.get("/some/sub-path")
        assert response.status_code == HTTP_200_OK
        assert response.json() == {"forwarded_path": "/"}

        response = client.get("/some/sub-path/abc")
        assert response.status_code == HTTP_200_OK
        assert response.json() == {"forwarded_path": "/abc/"}

        response = client.get("/some/sub-path/123/another/sub-path")
        assert response.status_code == HTTP_200_OK
        assert response.json() == {"forwarded_path": "/123/another/sub-path/"}