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