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