def test_save_without_custom(self): url = "www.a.com" Shortener.shorten(url=url) result = OriginalUrl.objects.get(original=url) result_custom = ShortUrl.objects.get(url_associated=result.id) self.assertEqual(result.original, url) self.assertEqual(result_custom.shortened, Shortener.encode(result_custom.hash_id))
def test_save_with_custom(self): url = "www.b.com" custom = "nope" Shortener.shorten(url=url, custom=custom) result_url = OriginalUrl.objects.get(original=url) result_custom = ShortUrl.objects.get(shortened=custom) self.assertEqual(result_url.original, url) self.assertEqual(result_custom.shortened, Shortener.encode(result_custom.hash_id)) self.assertEqual(result_custom.url_associated_id, result_url.id)
def test_encode(self): self.assertEqual(Shortener.AVAILABLE_CHARS[0], Shortener.encode(0)) self.assertEqual(Shortener.AVAILABLE_CHARS[26], Shortener.encode(26)) self.assertEqual('eyay', Shortener.encode(217752)) self.assertEqual('ooo', Shortener.encode(18662)) self.assertEqual('upiz', Shortener.encode(952873))
def test_next_encoded(self): value, encoded = Shortener.get_next_encoded() self.assertEqual(value, Shortener.decode(encoded)) self.assertEqual(encoded, Shortener.encode(value))