Exemplo n.º 1
0
def test_hash_id():
    """Test that hash_id returns a 12-byte hexadecimal string
       and that it returns the expected hash value
    """
    value = hash_id("aHashId")
    assert PATTERN_12_BYTE_HASH.match(value)
    assert value == "1351b4add8fae29a10ec26ba"
 def hash(self, value):
     """Returns a 12-byte hash of a given string lowercased, unless it is already a
     12-byte hexadecimal string (e.g. as returned by the unique_id function).
     Returns zero bytes if the value is None or falsey
     Override where desired behavior differs"""
     if isinstance(value, str):
         value = value.lower()
     return hash_id(value)
Exemplo n.º 3
0
def test_hash_no_rehash():
    """Test that the hash function won't rehash a 12-byte hex string
    """
    assert hash_id("3a392b49adf4b306976fb0d0") == "3a392b49adf4b306976fb0d0"
    value = unique_id()
    assert hash_id(value) == value
Exemplo n.º 4
0
def test_hash_zero():
    """Test that no value returns 12-byte of zeros hexadecimal string
    """
    assert hash_id(None) == "000000000000000000000000"
    assert hash_id("") == "000000000000000000000000"
Exemplo n.º 5
0
def test_hash_id_case_insensitive():
    """Test that hash_id returns a 12-byte hexadecimal string
       and that it returns the expected hash value
    """
    assert hash_id("aHashId") == hash_id("ahashid")
 def hash(self, value):
     """Returns a 12-byte hash of a given string, unless it is already a
     12-byte hexadecimal string (e.g. as returned by the unique_id function).
     Returns zero bytes if the value is None or falsey"""
     return hash_id(value)