-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: coverage for contrib.minijinja (#2593)
This PR extends test coverage for the minijinja contrib. For: #2535
- Loading branch information
1 parent
47281b2
commit 2d63576
Showing
2 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
from minijinja import Environment # type: ignore[import-untyped] | ||
|
||
from litestar.contrib.minijinja import MiniJinjaTemplateEngine | ||
from litestar.exceptions import ImproperlyConfiguredException, TemplateNotFoundException | ||
|
||
if TYPE_CHECKING: | ||
from pathlib import Path | ||
|
||
|
||
def test_mini_jinja_template_engine_instantiation_error(tmp_path: Path) -> None: | ||
with pytest.raises(ImproperlyConfiguredException): | ||
MiniJinjaTemplateEngine(directory=tmp_path, engine_instance=Environment()) | ||
|
||
with pytest.raises(ImproperlyConfiguredException): | ||
MiniJinjaTemplateEngine() | ||
|
||
|
||
def test_mini_jinja_template_engine_instantiated_with_engine() -> None: | ||
engine = Environment() | ||
template_engine = MiniJinjaTemplateEngine(engine_instance=engine) | ||
assert template_engine.engine is engine | ||
|
||
|
||
def test_mini_jinja_template_render_raises_template_not_found(tmp_path: Path) -> None: | ||
template_engine = MiniJinjaTemplateEngine(engine_instance=Environment()) | ||
with pytest.raises(TemplateNotFoundException): | ||
tmpl = template_engine.get_template("not_found.html") | ||
tmpl.render() | ||
|
||
|
||
def test_from_environment() -> None: | ||
engine = Environment() | ||
template_engine = MiniJinjaTemplateEngine.from_environment(engine) | ||
assert template_engine.engine is engine |