Skip to content
Snippets Groups Projects
Commit 9eb1cce3 authored by ihoover's avatar ihoover
Browse files

maximum number of random users

parent 66eb47fb
No related branches found
No related tags found
No related merge requests found
......@@ -918,6 +918,21 @@ def get_random_post_override():
'honor_code': 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 inner_create_random_account(request):
......@@ -929,6 +944,16 @@ def create_random_account(create_account_function):
if settings.GENERATE_RANDOM_USER_CREDENTIALS:
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
def activate_account(request, key):
......
......@@ -58,12 +58,30 @@ def auto_auth(request):
true.
"""
# log the user in
student.views.create_account(request)
# activate account
request.user.is_active = True
request.user.save()
from django.contrib.auth.models import User
from django.contrib.auth import login, authenticate
from random import randint
# generate random user ceredentials from a small name space
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
return redirect('root')
......@@ -38,12 +38,13 @@ COURSEWARE_ENABLED = True
ENABLE_JASMINE = False
AUTOMATIC_AUTH_FOR_LOAD_TESTING = True
MAX_AUTO_AUTH_USERS = 2
GENERATE_RANDOM_USER_CREDENTIALS = False
PERFSTATS = False
# 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
# # 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
DISCUSSION_SETTINGS = {
'MAX_COMMENT_DEPTH': 2,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment