Rafał Pitoń 11 лет назад
Родитель
Сommit
f53b1a3322

+ 1 - 0
misago/conf/defaults.py

@@ -95,6 +95,7 @@ INSTALLED_APPS = (
     'misago.core',
     'misago.conf',
     'misago.users',
+    'misago.faker',
 )
 
 MIDDLEWARE_CLASSES = (

+ 0 - 0
misago/faker/__init__.py


+ 0 - 0
misago/faker/management/__init__.py


+ 0 - 0
misago/faker/management/commands/__init__.py


+ 32 - 0
misago/faker/management/commands/createfakeusers.py

@@ -0,0 +1,32 @@
+from faker import Factory
+from django.contrib.auth import get_user_model
+from django.core.exceptions import ValidationError
+from django.core.management.base import BaseCommand
+from django.db import IntegrityError
+
+class Command(BaseCommand):
+    help = 'Creates plenty of random fakey users for testing purposes'
+
+    def handle(self, *args, **options):
+        fake_users_to_create = 100000
+        fake = Factory.create()
+        User = get_user_model()
+
+        message = 'Attempting to create %s fake user accounts!'
+        self.stdout.write(message % fake_users_to_create)
+
+        message = 'Successfully created %s fake user accounts!'
+
+        created_count = 0
+        for i in xrange(fake_users_to_create):
+            try:
+                User.objects.create_user(fake.first_name(), fake.email(),
+                                         'pass123')
+            except (ValidationError, IntegrityError):
+                pass
+            else:
+                created_count += 1
+                if created_count % 100 == 0:
+                    self.stdout.write(message % created_count)
+
+        self.stdout.write(message % User.objects.all().count())

+ 1 - 0
misago/project_template/requirements.txt

@@ -2,6 +2,7 @@ django==1.6.1
 django-debug-toolbar==1.0.1
 django-crispy-forms==1.4.0
 django-pipeline==1.3.20
+fake-factory
 south==0.8.4
 unidecode
 pytz