Added function filter to template system, closes #429

This commit is contained in:
Rhet Turnbull
2021-04-18 17:52:14 -07:00
parent 9371db094e
commit dd6d519135
4 changed files with 85 additions and 11 deletions

View File

@@ -982,3 +982,31 @@ def test_function_bad(photosdb):
"{function:tests/template_function.py::foobar}"
)
def test_function_filter(photosdb):
""" Test {field|function} filter"""
photo = photosdb.get_photo(UUID_MULTI_KEYWORDS)
rendered, _ = photo.render_template(
"{photo.original_filename|function:tests/template_filter.py::myfilter}"
)
assert rendered == [f"foo-{photo.original_filename}"]
rendered, _ = photo.render_template(
"{photo.original_filename|lower|function:tests/template_filter.py::myfilter}"
)
assert rendered == [f"foo-{photo.original_filename.lower()}"]
rendered, _ = photo.render_template(
"{photo.original_filename|function:tests/template_filter.py::myfilter|lower}"
)
assert rendered == [f"foo-{photo.original_filename.lower()}"]
def test_function_filter_bad(photosdb):
""" Test invalid {field|function} filter"""
photo = photosdb.get_photo(UUID_MULTI_KEYWORDS)
with pytest.raises(ValueError):
rendered, _ = photo.render_template(
"{photo.original_filename|function:tests/template_filter.py::foobar}"
)