File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,15 @@ class _BaseHash(BaseTag):
1212 description: Hashes the given data using the {name} algorithm. If the data is not binary, it is converted to UTF-8 bytes.
1313 """
1414
15+ value_types = (
16+ str ,
17+ object ,
18+ )
19+
1520 hasher : Any = None # TODO: what's the proper type for a hasher factory?
1621
1722 def enrich (self , context : Context ) -> str :
18- data = self .data
23+ data = context . enrich ( self .data )
1924 if not isinstance (data , bytes ):
2025 if not isinstance (data , str ):
2126 data = str (data )
Original file line number Diff line number Diff line change 11import pytest
22
3- from emrichen import Template
3+ from emrichen import Context , Template
44
55HASHES = {
66 'MD5' : '8b1a9953c4611296a827abf8c47804d7' ,
77 'SHA1' : 'f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0' ,
88 'SHA256' : '185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969' ,
99}
1010
11+ @pytest .mark .parametrize ('h' , sorted (HASHES .items ()), ids = sorted (HASHES ))
12+ def test_hash_variable (h ):
13+ algo , expected = h
14+
15+ VARIABLES = """
16+ helloVar: Hello
17+ """
18+
19+ assert Template .parse (f'!{ algo } ,Var helloVar' ).enrich (Context (VARIABLES )) == [expected ]
1120
1221@pytest .mark .parametrize ('h' , sorted (HASHES .items ()), ids = sorted (HASHES ))
1322def test_hash (h ):
You can’t perform that action at this time.
0 commit comments