-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtasks.py
51 lines (39 loc) · 1.58 KB
/
tasks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import random
import os
from functools import wraps
import sys
from invoke import task
from django.utils.crypto import get_random_string
sys.path.append(os.path.dirname(__file__))
# helpers
_django_setup_run = False
def django_setup(f):
@wraps(f)
def wrapper(*args, **kwargs):
global _django_setup_run
if not _django_setup_run:
_django_setup_run = True
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'dostuff.settings')
django.setup()
return f(*args, **kwargs)
return wrapper
# tasks
@task
@django_setup
def create_users(ctx, count=1):
from django.contrib.auth.models import User
adjectives = "adaptable adventurous affectionate ambitious amiable compassionate considerate courageous courteous diligent empathetic exuberant frank generous gregarious impartial intuitive inventive passionate persistent philosophical practical rational reliable resourceful sensible sincere sympathetic unassuming witty".split() # noqa
animals = "Dog Cat Horse Chicken Fish Bear Bird Shark Snake Pig Lion Turkey Wolf Spider Duck Deer Cow Monkey Lobster Ape Pony Eagle Dolphin Bison".split() # noqa
for i in range(int(count)):
# TODO: this throws IntegrityError if it happens
# to regenerate the same username
username = ("%s %s" % (
random.choice(adjectives),
random.choice(animals)
)).title()
user = User.objects.create_user(
username=username,
password=get_random_string(20)
)
print(user.auth_token.key)