def test_shorten_and_unshorten_without_prefix(self): uuid = uuid4() shortener = UuidShortener() short_uuid = shortener.shorten(uuid) self.assertEqual(uuid, shortener.unshorten(short_uuid))
def test_shorten_and_unshorten_with_prefix(self): uuid = uuid4() shortener = UuidShortener('dev') short_uuid = shortener.shorten(uuid) self.assertEqual(0, short_uuid.index('dev-')) self.assertEqual(uuid, shortener.unshorten(short_uuid))
from uuid_shortener import UuidShortener from uuid import uuid4 if __name__ == "__main__": print('******** Without prefix') shortener = UuidShortener() uuid_4 = uuid4() short_uuid = shortener.shorten(uuid_4) unshortened_uuid = shortener.unshorten(short_uuid) print(f'Uuid to shorten: {uuid_4}') print(f'shortened uuid: {short_uuid}') print(f'unshortened uuid(original uuid): {shortener.unshorten(short_uuid)}') print("\n\n") print('******** With prefix: meow') shortener = UuidShortener('meow') uuid_4 = uuid4() short_uuid = shortener.shorten(uuid_4) unshortened_uuid = shortener.unshorten(short_uuid) print(f'Uuid to shorten: {uuid_4}') print(f'shortened uuid: {short_uuid}') print(f'unshortened uuid (original uuid): {shortener.unshorten(short_uuid)}')