File: test_htmx_plugin.py

package info (click to toggle)
litestar-htmx 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 664 kB
  • sloc: python: 1,358; makefile: 162; sh: 17
file content (30 lines) | stat: -rw-r--r-- 897 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
import pytest
from litestar.config.app import AppConfig

from litestar_htmx import HTMXConfig, HTMXPlugin, HTMXRequest

pytestmark = pytest.mark.anyio


@pytest.mark.parametrize(
    "set_request_class_globally",
    (True, False),
)
def test_request_class(set_request_class_globally: bool) -> None:
    config = HTMXConfig(set_request_class_globally=set_request_class_globally)
    plugin = HTMXPlugin(config=config)
    app_config = plugin.on_app_init(AppConfig())
    if set_request_class_globally:
        assert app_config.request_class == HTMXRequest
    else:
        assert app_config.request_class is None


class CustomHTMXRequest(HTMXRequest):
    """Extra functionality."""


def test_request_class_no_override() -> None:
    plugin = HTMXPlugin()
    app_config = plugin.on_app_init(AppConfig(request_class=CustomHTMXRequest))
    assert app_config.request_class == CustomHTMXRequest