Files
core/tests/helpers/template/extensions/test_crypto.py
T
Franck NijhofGitHubcopilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>frenck
9a1fd913bf Fix line length violations in tests (non-components) (#170804)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
2026-05-17 10:30:45 -04:00

38 lines
1.4 KiB
Python

"""Test cryptographic hash functions for Home Assistant templates."""
from homeassistant.core import HomeAssistant
from tests.helpers.template.helpers import render
def test_md5(hass: HomeAssistant) -> None:
"""Test the md5 function and filter."""
ha_md5 = "3d15e5c102c3413d0337393c3287e006"
assert render(hass, "{{ md5('Home Assistant') }}") == ha_md5
assert render(hass, "{{ 'Home Assistant' | md5 }}") == ha_md5
def test_sha1(hass: HomeAssistant) -> None:
"""Test the sha1 function and filter."""
ha_sha1 = "c8fd3bb19b94312664faa619af7729bdbf6e9f8a"
assert render(hass, "{{ sha1('Home Assistant') }}") == ha_sha1
assert render(hass, "{{ 'Home Assistant' | sha1 }}") == ha_sha1
def test_sha256(hass: HomeAssistant) -> None:
"""Test the sha256 function and filter."""
ha_sha256 = "2a366abb0cd47f51f3725bf0fb7ebcb4fefa6e20f4971e25fe2bb8da8145ce2b"
assert render(hass, "{{ sha256('Home Assistant') }}") == ha_sha256
assert render(hass, "{{ 'Home Assistant' | sha256 }}") == ha_sha256
def test_sha512(hass: HomeAssistant) -> None:
"""Test the sha512 function and filter."""
ha_sha512 = (
"9e3c2cdd1fbab0037378d37e1baf8a3a4bf92c54b56ad1d459deee30"
"ccbb2acbebd7a3614552ea08992ad27dedeb7b4c5473525ba90cb73d"
"be8b9ec5f69295bb"
)
assert render(hass, "{{ sha512('Home Assistant') }}") == ha_sha512
assert render(hass, "{{ 'Home Assistant' | sha512 }}") == ha_sha512