mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Added new filters for templates (#18125)
* added additional filters Added base64_encode, base64_decode and ordinal filters. * added test cases added test cases for base64_encode, base64_decode and ordinal filters. * forgot to add filters :)
This commit is contained in:
committed by
Pascal Vizeli
parent
1ae58ce48b
commit
c23792d1fb
@@ -274,6 +274,37 @@ class TestHelpersTemplate(unittest.TestCase):
|
||||
template.Template('{{ [1, 2, 3] | max }}',
|
||||
self.hass).render()
|
||||
|
||||
def test_base64_encode(self):
|
||||
"""Test the base64_encode filter."""
|
||||
self.assertEqual(
|
||||
'aG9tZWFzc2lzdGFudA==',
|
||||
template.Template('{{ "homeassistant" | base64_encode }}',
|
||||
self.hass).render())
|
||||
|
||||
def test_base64_decode(self):
|
||||
"""Test the base64_decode filter."""
|
||||
self.assertEqual(
|
||||
'homeassistant',
|
||||
template.Template('{{ "aG9tZWFzc2lzdGFudA==" | base64_decode }}',
|
||||
self.hass).render())
|
||||
|
||||
def test_ordinal(self):
|
||||
"""Test the ordinal filter."""
|
||||
tests = [
|
||||
(1, '1st'),
|
||||
(2, '2nd'),
|
||||
(3, '3rd'),
|
||||
(4, '4th'),
|
||||
(5, '5th'),
|
||||
]
|
||||
|
||||
for value, expected in tests:
|
||||
self.assertEqual(
|
||||
expected,
|
||||
template.Template(
|
||||
'{{ %s | ordinal }}' % value,
|
||||
self.hass).render())
|
||||
|
||||
def test_timestamp_utc(self):
|
||||
"""Test the timestamps to local filter."""
|
||||
now = dt_util.utcnow()
|
||||
|
||||
Reference in New Issue
Block a user