Browse Source

necessary bump on some fakers

Rafał Pitoń 8 years ago
parent
commit
763f397799

+ 25 - 20
misago/faker/management/commands/createfakecategories.py

@@ -12,41 +12,46 @@ from misago.core.management.progressbar import show_progress
 
 
 class Command(BaseCommand):
-    help = 'Creates random fakey categories for testing purposes'
+    help = "Creates fake categories for dev and testing purposes."
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            'categories',
+            help="number of categories to create",
+            nargs='?',
+            type=int,
+            default=5
+        )
+
+        parser.add_argument(
+            'minlevel',
+            help="min. level of created categories",
+            nargs='?',
+            type=int,
+            default=0
+        )
 
     def handle(self, *args, **options):
-        try:
-            fake_cats_to_create = int(args[0])
-        except IndexError:
-            fake_cats_to_create = 5
-        except ValueError:
-            self.stderr.write("\nOptional argument should be integer.")
-            sys.exit(1)
+        items_to_create = options['categories']
+        min_level = options['minlevel']
 
         categories = Category.objects.all_categories(True)
 
-        try:
-            min_level = int(args[1])
-        except (IndexError):
-            min_level = 0
-        except ValueError:
-            self.stderr.write("\nSecond optional argument should be integer.")
-            sys.exit(1)
-
         copy_acl_from = list(Category.objects.all_categories())[0]
 
         categories = categories.filter(level__gte=min_level)
         fake = Factory.create()
 
         message = 'Creating %s fake categories...\n'
-        self.stdout.write(message % fake_cats_to_create)
+        self.stdout.write(message % items_to_create)
 
         message = '\n\nSuccessfully created %s fake categories in %s'
 
         created_count = 0
         start_time = time.time()
-        show_progress(self, created_count, fake_cats_to_create)
-        for i in range(fake_cats_to_create):
+        show_progress(self, created_count, items_to_create)
+
+        while created_count < items_to_create:
             parent = random.choice(categories)
 
             new_category = Category()
@@ -79,7 +84,7 @@ class Command(BaseCommand):
 
             created_count += 1
             show_progress(
-                self, created_count, fake_cats_to_create, start_time)
+                self, created_count, items_to_create, start_time)
 
         acl_version.invalidate()
 

+ 15 - 11
misago/faker/management/commands/createfakethreads.py

@@ -16,16 +16,19 @@ from misago.threads.models import Post, Thread
 
 
 class Command(BaseCommand):
-    help = 'Adds random threads and posts for testing purposes'
+    help = 'Creates random threads and posts for dev and testing purposes.'
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            'threads',
+            help="number of threads to create",
+            nargs='?',
+            type=int,
+            default=5
+        )
 
     def handle(self, *args, **options):
-        try:
-            fake_threads_to_create = int(args[0])
-        except IndexError:
-            fake_threads_to_create = 5
-        except ValueError:
-            self.stderr.write("\nOptional argument should be integer.")
-            sys.exit(1)
+        items_to_create = options['threads']
 
         categories = list(Category.objects.all_categories())
 
@@ -40,8 +43,9 @@ class Command(BaseCommand):
 
         created_threads = 0
         start_time = time.time()
-        show_progress(self, created_threads, fake_threads_to_create)
-        for i in range(fake_threads_to_create):
+        show_progress(self, created_threads, items_to_create)
+
+        while created_threads < items_to_create:
             with atomic():
                 datetime = timezone.now()
                 category = random.choice(categories)
@@ -133,7 +137,7 @@ class Command(BaseCommand):
 
                 created_threads += 1
                 show_progress(
-                    self, created_threads, fake_threads_to_create, start_time)
+                    self, created_threads, items_to_create, start_time)
 
         pinned_threads = random.randint(0, int(created_threads * 0.025)) or 1
         self.stdout.write('\nPinning %s threads...' % pinned_threads)

+ 16 - 12
misago/faker/management/commands/createfakeusers.py

@@ -15,16 +15,19 @@ from misago.users.models import Rank
 
 
 class Command(BaseCommand):
-    help = 'Creates random fakey users for testing purposes'
+    help = "Creates fake users for dev and testing purposes."
+
+    def add_arguments(self, parser):
+        parser.add_argument(
+            'users',
+            help="number of users to create",
+            nargs='?',
+            type=int,
+            default=5
+        )
 
     def handle(self, *args, **options):
-        try:
-            fake_users_to_create = int(args[0])
-        except IndexError:
-            fake_users_to_create = 5
-        except ValueError:
-            self.stderr.write("\nOptional argument should be integer.")
-            sys.exit(1)
+        items_to_create = options['users']
 
         fake = Factory.create()
         User = get_user_model()
@@ -32,14 +35,15 @@ class Command(BaseCommand):
         ranks = [r for r in Rank.objects.all()]
 
         message = 'Creating %s fake user accounts...\n'
-        self.stdout.write(message % fake_users_to_create)
+        self.stdout.write(message % items_to_create)
 
         message = '\n\nSuccessfully created %s fake user accounts in %s'
 
         created_count = 0
         start_time = time.time()
-        show_progress(self, created_count, fake_users_to_create)
-        for i in range(fake_users_to_create):
+        show_progress(self, created_count, items_to_create)
+
+        while created_count < items_to_create:
             try:
                 kwargs = {
                     'rank': random.choice(ranks),
@@ -61,7 +65,7 @@ class Command(BaseCommand):
             else:
                 created_count += 1
                 show_progress(
-                    self, created_count, fake_users_to_create, start_time)
+                    self, created_count, items_to_create, start_time)
 
         total_time = time.time() - start_time
         total_humanized = time.strftime('%H:%M:%S', time.gmtime(total_time))