mirror of
https://github.com/fergalmoran/ferglie.git
synced 2025-12-22 01:07:55 +00:00
40 lines
1.4 KiB
Python
Executable File
40 lines
1.4 KiB
Python
Executable File
from django.test import TestCase
|
|
|
|
# Create your tests here.
|
|
from shorts.models import Url
|
|
|
|
|
|
# Print iterations progress
|
|
def print_progress_bar(iteration, total, prefix='', suffix='', decimals=1, length=100, fill='█'):
|
|
"""
|
|
Call in a loop to create terminal progress bar
|
|
@params:
|
|
iteration - Required : current iteration (Int)
|
|
total - Required : total iterations (Int)
|
|
prefix - Optional : prefix string (Str)
|
|
suffix - Optional : suffix string (Str)
|
|
decimals - Optional : positive number of decimals in percent complete (Int)
|
|
length - Optional : character length of bar (Int)
|
|
fill - Optional : bar fill character (Str)
|
|
"""
|
|
percent = ("{0:." + str(decimals) + "f}").format(100 * (iteration / float(total)))
|
|
filledLength = int(length * iteration // total)
|
|
bar = fill * filledLength + '-' * (length - filledLength)
|
|
print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end='\r')
|
|
# Print New Line on Complete
|
|
if iteration == total:
|
|
print()
|
|
|
|
|
|
class UrlTestCase(TestCase):
|
|
def setUp(self):
|
|
self._num_cases = 10000
|
|
pass
|
|
|
|
def test_slug_is_unique(self):
|
|
for i in range(0, self._num_cases):
|
|
if i % (self._num_cases / 1000) == 0:
|
|
print_progress_bar(i, self._num_cases)
|
|
|
|
Url.objects.create(url='https://www.youtube.com/watch?v=XEADdDHzGoc')
|