Commit 9eb1cce3 by ihoover

maximum number of random users

parent 66eb47fb
...@@ -918,6 +918,21 @@ def get_random_post_override(): ...@@ -918,6 +918,21 @@ def get_random_post_override():
'honor_code': u'true', 'honor_code': u'true',
'terms_of_service': u'true', } 'terms_of_service': u'true', }
def get_planned_post_override(username, password):
"""
Return a dictionary suitable for passing to post_vars of _do_create_account or post_override
of create_account, with specified username and password.
"""
def id_generator(size=6, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):
return ''.join(random.choice(chars) for x in range(size))
return {'username': username,
'email': id_generator(size=10, chars=string.ascii_lowercase) + "_dummy_test@mitx.mit.edu",
'password': password,
'name': (id_generator(size=5, chars=string.ascii_lowercase) + " " +
id_generator(size=7, chars=string.ascii_lowercase)),
'honor_code': u'true',
'terms_of_service': u'true', }
def create_random_account(create_account_function): def create_random_account(create_account_function):
def inner_create_random_account(request): def inner_create_random_account(request):
...@@ -929,6 +944,16 @@ def create_random_account(create_account_function): ...@@ -929,6 +944,16 @@ def create_random_account(create_account_function):
if settings.GENERATE_RANDOM_USER_CREDENTIALS: if settings.GENERATE_RANDOM_USER_CREDENTIALS:
create_account = create_random_account(create_account) create_account = create_random_account(create_account)
def create_random_account_with_name_and_password(create_account_function):
def inner_create_random_account(request, username, password):
return create_account_function(request, post_override=get_planned_post_override(username, password))
return inner_create_random_account
# for load testing we want to create lots of accounts
# with controlled username and password
if settings.AUTOMATIC_AUTH_FOR_LOAD_TESTING:
create_account = create_random_account_with_name_and_password(create_account)
@ensure_csrf_cookie @ensure_csrf_cookie
def activate_account(request, key): def activate_account(request, key):
......
...@@ -58,12 +58,30 @@ def auto_auth(request): ...@@ -58,12 +58,30 @@ def auto_auth(request):
true. true.
""" """
# log the user in from django.contrib.auth.models import User
student.views.create_account(request) from django.contrib.auth import login, authenticate
from random import randint
# activate account
request.user.is_active = True # generate random user ceredentials from a small name space
request.user.save() name_base = 'USER_'
pass_base = 'PASS_'
number = randint(1, settings.MAX_AUTO_AUTH_USERS)
username = name_base + str(number)
password = pass_base + str(number)
# if they already are a user, log in
try:
user = User.objects.get(username=username)
user = authenticate(username=username, password=password)
login(request, user)
except:
# create and activate account info
student.views.create_account(request, username, password)
request.user.is_active = True
request.user.save()
# redirect to home-page # redirect to home-page
return redirect('root') return redirect('root')
...@@ -38,12 +38,13 @@ COURSEWARE_ENABLED = True ...@@ -38,12 +38,13 @@ COURSEWARE_ENABLED = True
ENABLE_JASMINE = False ENABLE_JASMINE = False
AUTOMATIC_AUTH_FOR_LOAD_TESTING = True AUTOMATIC_AUTH_FOR_LOAD_TESTING = True
MAX_AUTO_AUTH_USERS = 2
GENERATE_RANDOM_USER_CREDENTIALS = False GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False PERFSTATS = False
# automatic_auth should turn on random_cred of it needs to # # automatic_auth should turn on random_cred of it needs to
GENERATE_RANDOM_USER_CREDENTIALS = GENERATE_RANDOM_USER_CREDENTIALS or AUTOMATIC_AUTH_FOR_LOAD_TESTING # GENERATE_RANDOM_USER_CREDENTIALS = GENERATE_RANDOM_USER_CREDENTIALS or AUTOMATIC_AUTH_FOR_LOAD_TESTING
DISCUSSION_SETTINGS = { DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2, 'MAX_COMMENT_DEPTH': 2,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment