Add slugify as a template filter (#58724)

This commit is contained in:
Brynley McDonald 2021-12-21 23:35:54 +13:00 committed by GitHub
parent e0ef066022
commit 26dc526234
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View file

@ -865,6 +865,26 @@ def test_base64_decode(hass):
)
def test_slugify(hass):
"""Test the slugify filter."""
assert (
template.Template('{{ slugify("Home Assistant") }}', hass).async_render()
== "home_assistant"
)
assert (
template.Template('{{ "Home Assistant" | slugify }}', hass).async_render()
== "home_assistant"
)
assert (
template.Template('{{ slugify("Home Assistant", "-") }}', hass).async_render()
== "home-assistant"
)
assert (
template.Template('{{ "Home Assistant" | slugify("-") }}', hass).async_render()
== "home-assistant"
)
def test_ordinal(hass):
"""Test the ordinal filter."""
tests = [