From cc6b09e91d75125f045270dcf4b9d09c6bd92858 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20M=C3=A9rigot?= <nicolas.merigot@gmail.com>
Date: Tue, 8 Jan 2019 14:41:04 +0100
Subject: [PATCH] feature: add user factory and command

---
 djangoldp/factories.py                     | 14 ++++++++++++++
 djangoldp/management/commands/__init__.py  |  0
 djangoldp/management/commands/mock_user.py | 13 +++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 djangoldp/factories.py
 create mode 100644 djangoldp/management/commands/__init__.py
 create mode 100644 djangoldp/management/commands/mock_user.py

diff --git a/djangoldp/factories.py b/djangoldp/factories.py
new file mode 100644
index 00000000..172e289b
--- /dev/null
+++ b/djangoldp/factories.py
@@ -0,0 +1,14 @@
+import factory
+from django.contrib.auth.models import User
+from django.db.models.signals import post_save
+
+@factory.django.mute_signals(post_save)
+class UserFactory(factory.django.DjangoModelFactory):
+    class Meta:
+        model = User
+
+    username = factory.Faker('user_name')
+    first_name = factory.Faker('first_name')
+    last_name = factory.Faker('last_name')
+    email = factory.Faker('email')
+    password = factory.PostGenerationMethodCall('set_password', 'totototo')
diff --git a/djangoldp/management/commands/__init__.py b/djangoldp/management/commands/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/djangoldp/management/commands/mock_user.py b/djangoldp/management/commands/mock_user.py
new file mode 100644
index 00000000..30b4373e
--- /dev/null
+++ b/djangoldp/management/commands/mock_user.py
@@ -0,0 +1,13 @@
+from django.core.management.base import BaseCommand, CommandError
+from djangoldp.factories import UserFactory
+
+class Command(BaseCommand):
+    help = 'Mock data'
+
+    def add_arguments(self, parser):
+        parser.add_argument('--size', type=int, default=0, help='Number of user to create')
+
+    def handle(self, *args, **options):
+        UserFactory.create_batch(size=options['size']);
+
+        self.stdout.write(self.style.SUCCESS('Successful data mock install'))
-- 
GitLab