Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add function to create random users to populatedb command
Marcin Gębalaaa237f2ea46b
diff --git a/saleor/product/management/commands/populatedb.py b/saleor/product/management/commands/populatedb.pyindex 36957bcf9d..73be4d5554 100644--- a/saleor/product/management/commands/populatedb.py+++ b/saleor/product/management/commands/populatedb.py@@ -3,7 +3,7 @@ from os.path import exists, joinfrom django.core.management.base import BaseCommand, CommandErrorfrom django.core.management import call_command-from utils.create_random_data import create_items+from utils.create_random_data import create_items, create_usersclass Command(BaseCommand):@@ -18,3 +18,5 @@ class Command(BaseCommand):raise CommandError(msg)for msg in create_items(self.BASE_DIR, 10):self.stdout.write(msg)+ for msg in create_users(10):+ self.stdout.write(msg)diff --git a/utils/create_random_data.py b/utils/create_random_data.pyindex 013d879139..1be7cd9df5 100644--- a/utils/create_random_data.py+++ b/utils/create_random_data.py@@ -1,6 +1,7 @@from __future__ import unicode_literalsimport randomimport os+import unicodedatafrom faker import Factoryfrom django.core.files import File@@ -8,6 +9,7 @@ from django.core.files import Filefrom saleor.product.models import (Shirt, ShirtVariant,Bag, BagVariant, ProductImage)from saleor.product.models import Category, Color+from saleor.userprofile.models import User, Address, AddressBookfake = Factory.create()@@ -129,3 +131,39 @@ def create_items(placeholder_dir, how_many=10):yield "Shirt - %s %s Variants" % (shirt, shirt.variants.count())yield "Bag - %s %s Variants" % (bag, bag.variants.count())+++def create_fake_user():+ first_name = fake.first_name()+ last_name = fake.last_name()++ _first = unicodedata.normalize('NFD', first_name).encode('ascii', 'ignore')+ _last = unicodedata.normalize('NFD', last_name).encode('ascii', 'ignore')++ email = u'%s.%[email protected]' % (_first.lower(), _last.lower())++ user = User.objects.create_user(email=email, password='password')++ address = Address.objects.create(+ first_name=first_name,+ last_name=last_name,+ street_address_1=fake.street_address(),+ city=fake.city(),+ postal_code=fake.postcode(),+ country=fake.country_code())++ addr_book = AddressBook.objects.create(+ user=user,+ address=address)++ user.address_book.add(addr_book)+ user.default_billing_address = addr_book+ user.is_active = True+ user.save()+ return user+++def create_users(how_many=10):+ for i in range(how_many):+ user = create_fake_user()+ yield "User - %s" % user.emaildiff --git a/utils/create_random_users.py b/utils/create_random_users.pydeleted file mode 100644index 82a0020514..0000000000--- a/utils/create_random_users.py+++ /dev/null@@ -1,53 +0,0 @@-import os-os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'saleor.settings')--import sys-import faker-import unicodedata-from django.contrib.auth.hashers import make_password-from saleor.userprofile.models import User, Address, AddressBook--factory = faker.Factory.create('pl_PL')---def create_fake_user():- first_name = factory.first_name()- last_name = factory.last_name()-- _first = unicodedata.normalize('NFD', first_name).encode('ascii', 'ignore')- _last = unicodedata.normalize('NFD', last_name).encode('ascii', 'ignore')-- email = u'%s.%[email protected]' % (_first.lower(), _last.lower())-- user = User.objects.create(- email=email,- password=make_password('password'))- user.save()- print email-- address = Address.objects.create(- first_name=first_name,- last_name=last_name,- street_address_1=factory.street_address(),- city=factory.city(),- postal_code=factory.postcode(),- country='PL')-- addr_book = AddressBook.objects.create(- user=user,- address=address)- addr_book.save()-- user.address_book.add(addr_book)- user.default_billing_address = addr_book- user.is_active = True- user.save()---if __name__ == '__main__':- try:- count = int(sys.argv[1])- except:- count = 10- for _ in range(count):- create_fake_user()