def test_int_roundtrip(self): "Test converting an integer to a Uuid and back" ttype = 'Account' for i in chain(xrange(1, 1000), product(xrange(1, 10), repeat=2)): u1 = uuid.int_to_uuid(i, ttype) u2, test_ttype = uuid.uuid_to_int(u1, return_tag='type', split=isinstance(i, tuple)) self.assertEquals(i, u2) self.assertEquals(test_ttype, ttype) u3 = uuid.int_to_slug(i, ttype) u4, test_ttype = uuid.slug_to_int(u3, return_tag='type', split=isinstance(i, tuple)) self.assertEquals(i, u4) self.assertEquals(test_ttype, ttype)
def test_uuid_roundtrip(self): "Test converting a hex string to a Uuid and back" suffix = 'acc1' for i in xrange(1, 1000): hex_str = '%x%s' % (i, suffix) hex_str = '0' * (32 - len(hex_str)) + hex_str u1, ttype = uuid.uuid_to_int(hex_str, return_tag='type') self.assertEquals(ttype, 'Account') u2 = uuid.int_to_uuid(u1, ttype) self.assertEquals(u2, hex_str) u3 = uuid.uuid_to_slug(hex_str) u4 = uuid.slug_to_uuid(u3) self.assertEquals(u4, hex_str)
def uuidToInteger(uuid): uu = Uuid.from_int((uuid.high, uuid.low), 'Account') return uuid_to_int(uu.to_hex())