File: test_using_application_state.py

package info (click to toggle)
litestar 2.19.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 12,500 kB
  • sloc: python: 70,169; makefile: 254; javascript: 105; sh: 60
file content (24 lines) | stat: -rw-r--r-- 825 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
from logging import INFO
from typing import Any

import pytest
from docs.examples.application_state.using_application_state import app

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


@pytest.mark.usefixtures("reset_httpx_logging")
def test_using_application_state(caplog: Any) -> None:
    with caplog.at_level(INFO, "docs.examples.application_state.using_application_state"), TestClient(
        app=app
    ) as client:
        response = client.get("/")
        assert response.status_code == HTTP_200_OK

    assert {record.getMessage() for record in caplog.records} == {
        "state value in middleware: abc123",
        "state value in dependency: abc123",
        "state value in handler from `State`: abc123",
        "state value in handler from `Request`: abc123",
    }