Exemplo n.º 1
0
 def test_encode_hex(self):
     assert Hashids().encode_hex(
         '507f1f77bcf86cd799439011') == 'y42LW46J9luq3Xq9XMly'
     assert len(
         Hashids(min_length=1000).encode_hex(
             '507f1f77bcf86cd799439011')) >= 1000
     assert Hashids().encode_hex(
         'f000000000000000000000000000000000000000000000000000000000000000000000000000000000000f') == \
            'WxMLpERDrmh25Lp4L3xEfM6WovWYO3IjkRMKR2ogCMVzn4zQlqt1WK8jKq7OsEpy2qyw1Vi2p'
Exemplo n.º 2
0
def test_encode(salt, alphabet, min_length, numbers):
    alphabet = str(alphabet)
    salt = str(salt)

    hashids = Hashids(salt=salt, alphabet=alphabet, min_length=min_length)
    hashids_cffi = HashidsCFFI(salt=salt, alphabet=alphabet, min_length=min_length)

    hashids_cffi_encoded_hash = hashids_cffi.encode(*numbers)
    assert hashids.encode(*numbers) == hashids_cffi_encoded_hash

    assert len(hashids_cffi_encoded_hash) >= min_length
Exemplo n.º 3
0
def test_decode(salt, alphabet, min_length, hashid):
    alphabet = str(alphabet)
    salt = str(salt)
    hashid = str(hashid)

    hashids = Hashids(salt=salt, alphabet=alphabet, min_length=min_length)
    hashids_cffi = HashidsCFFI(salt=salt, alphabet=alphabet, min_length=min_length)

    hashid_decoded_numbers = hashids.decode(hashid)
    # TODO: Add overflow checks the to C library
    # These cases causes integer overflow
    assume(all((number <= MAX_ULONGLONG for number in hashid_decoded_numbers)) or (hashid_decoded_numbers == ()))

    assert hashid_decoded_numbers == hashids_cffi.decode(hashid)
Exemplo n.º 4
0
 def test_decode_hex(self):
     hex_str = '507f1f77bcf86cd799439011'
     assert Hashids().decode_hex('y42LW46J9luq3Xq9XMly') == hex_str
     h = Hashids(min_length=1000)
     assert h.decode_hex(h.encode_hex(hex_str)) == hex_str
     assert Hashids().decode_hex('WxMLpERDrmh25Lp4L3xEfM6WovWYO3IjkRMKR2ogCMVzn4zQlqt1WK8jKq7OsEpy2qyw1Vi2p') == \
            'f000000000000000000000000000000000000000000000000000000000000000000000000000000000000f'
Exemplo n.º 5
0
 def test_salt(self, numbers, hashid):
     h = Hashids(salt='Arbitrary string')
     assert h.encode(*numbers) == hashid
Exemplo n.º 6
0
 def test_default_salt(self):
     assert Hashids().decode('o2fXhV') == (1, 2, 3)
Exemplo n.º 7
0
 def test_multiple_numbers(self, numbers, hashid):
     h = Hashids()
     assert h.encode(*numbers) == hashid
Exemplo n.º 8
0
 def test_empty_call(self):
     assert Hashids().encode() == ''
Exemplo n.º 9
0
 def bench():
     h = HashidsCFFI(min_length=min_length)
     h.decode(hashid)
Exemplo n.º 10
0
 def test_all_parameters(self, numbers, hashid):
     h = Hashids('arbitrary salt', 16, 'abcdefghijklmnopqrstuvwxyz')
     assert h.encode(*numbers) == hashid
Exemplo n.º 11
0
 def test_negative_call(self):
     assert Hashids().encode(1, -2, 3) == ''
Exemplo n.º 12
0
 def test_min_length(self, numbers, hashid):
     h = Hashids(min_length=25)
     assert h.decode(hashid) == numbers
Exemplo n.º 13
0
 def test_invalid_hash(self):
     assert Hashids(alphabet='abcdefghijklmnop').decode('qrstuvwxyz') == ()
Exemplo n.º 14
0
 def test_default_salt(self):
     assert Hashids().encode(1, 2, 3) == 'o2fXhV'
Exemplo n.º 15
0
 def test_salt(self, numbers, hashid):
     h = Hashids(salt='Arbitrary string')
     assert h.decode(hashid) == numbers
Exemplo n.º 16
0
 def test_multiple_numbers(self, numbers, hashid):
     h = Hashids()
     assert h.decode(hashid) == numbers
Exemplo n.º 17
0
 def test_single_number(self, numbers, hashid):
     h = Hashids()
     assert h.decode(hashid) == numbers
Exemplo n.º 18
0
 def test_empty_call(self):
     assert Hashids().decode('') == ()
Exemplo n.º 19
0
 def test_alphabet(self, numbers, hashid):
     h = Hashids(
         alphabet=
         '!"#%&\',-/0123456789:;<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'
     )
     assert h.encode(*numbers) == hashid
Exemplo n.º 20
0
 def test_alphabet_without_standard_separators(self, numbers, hashid):
     h = Hashids(
         alphabet='abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890')
     assert h.decode(hashid) == numbers
Exemplo n.º 21
0
 def test_min_length(self, numbers, hashid):
     h = Hashids(min_length=25)
     assert h.encode(*numbers) == hashid
Exemplo n.º 22
0
 def test_only_one_valid(self):
     h = Hashids(min_length=6)
     assert h.decode(h.encode(1)[:-1] + '0') == ()
Exemplo n.º 23
0
 def test_alphabet_with_two_standard_separators(self, numbers, hashid):
     h = Hashids(
         alphabet='abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890uC')
     assert h.encode(*numbers) == hashid
Exemplo n.º 24
0
 def test_empty_string(self):
     assert Hashids().decode('') == ()
Exemplo n.º 25
0
 def test_float_call(self):
     assert Hashids().encode(1, 2.5, 3) == ''
Exemplo n.º 26
0
 def test_single_number(self, number, hashid):
     h = Hashids()
     assert h.encode(number) == hashid
Exemplo n.º 27
0
 def test_illegal_hex(self):
     assert Hashids().encode_hex('') == ''
     assert Hashids().encode_hex('1234SGT8') == ''
Exemplo n.º 28
0
 def test_illegal_decode_hex(self):
     assert Hashids().decode_hex('') == ''
     assert Hashids().decode_hex(
         'WxMLpERDrmh25Lp4L3xEfM6WovWYO3IjkRMKR2ogCMVlqt1WK8jKq7OsEp1Vi2p'
     ) == ''
Exemplo n.º 29
0
 def bench():
     h = HashidsCFFI(min_length=min_length)
     h.encode(1)
Exemplo n.º 30
0
 def test_non_string(self):
     assert Hashids().decode(object()) == ()