Example #1
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
Example #2
0
 def bench():
     h = HashidsCFFI(min_length=min_length)
     h.encode(1)
Example #3
0
 def test_alphabet_with_two_standard_separators(self, numbers, hashid):
     h = Hashids(
         alphabet='abdegjklmnopqrvwxyzABDEGJKLMNOPQRVWXYZ1234567890uC')
     assert h.encode(*numbers) == hashid
Example #4
0
 def test_all_parameters(self, numbers, hashid):
     h = Hashids('arbitrary salt', 16, 'abcdefghijklmnopqrstuvwxyz')
     assert h.encode(*numbers) == hashid
Example #5
0
 def test_min_length(self, numbers, hashid):
     h = Hashids(min_length=25)
     assert h.encode(*numbers) == hashid
Example #6
0
 def test_alphabet(self, numbers, hashid):
     h = Hashids(
         alphabet=
         '!"#%&\',-/0123456789:;<=>ABCDEFGHIJKLMNOPQRSTUVWXYZ_`abcdefghijklmnopqrstuvwxyz~'
     )
     assert h.encode(*numbers) == hashid
Example #7
0
 def test_salt(self, numbers, hashid):
     h = Hashids(salt='Arbitrary string')
     assert h.encode(*numbers) == hashid
Example #8
0
 def test_multiple_numbers(self, numbers, hashid):
     h = Hashids()
     assert h.encode(*numbers) == hashid
Example #9
0
 def test_single_number(self, number, hashid):
     h = Hashids()
     assert h.encode(number) == hashid
Example #10
0
 def test_only_one_valid(self):
     h = Hashids(min_length=6)
     assert h.decode(h.encode(1)[:-1] + '0') == ()