Files
edx-platform/common/djangoapps/student/management/commands/create_test_users.py
Kyle McCormick 151bd13666 Use full names for common.djangoapps imports; warn when using old style (#25477)
* Generate common/djangoapps import shims for LMS
* Generate common/djangoapps import shims for Studio
* Stop appending project root to sys.path
* Stop appending common/djangoapps to sys.path
* Import from common.djangoapps.course_action_state instead of course_action_state
* Import from common.djangoapps.course_modes instead of course_modes
* Import from common.djangoapps.database_fixups instead of database_fixups
* Import from common.djangoapps.edxmako instead of edxmako
* Import from common.djangoapps.entitlements instead of entitlements
* Import from common.djangoapps.pipline_mako instead of pipeline_mako
* Import from common.djangoapps.static_replace instead of static_replace
* Import from common.djangoapps.student instead of student
* Import from common.djangoapps.terrain instead of terrain
* Import from common.djangoapps.third_party_auth instead of third_party_auth
* Import from common.djangoapps.track instead of track
* Import from common.djangoapps.util instead of util
* Import from common.djangoapps.xblock_django instead of xblock_django
* Add empty common/djangoapps/__init__.py to fix pytest collection
* Fix pylint formatting violations
* Exclude import_shims/ directory tree from linting
2020-11-10 07:02:01 -05:00

83 lines
2.9 KiB
Python

""" Management command to create test users """
from django.core.management.base import BaseCommand
from opaque_keys.edx.keys import CourseKey
from common.djangoapps.course_modes.models import CourseMode
from common.djangoapps.student.management.commands._create_users import create_users
def user_info_generator(usernames, password, domain):
for username in usernames:
yield {
'username': username,
'email': '{username}@{domain}'.format(username=username, domain=domain),
'password': password,
'name': username,
}
class Command(BaseCommand):
"""
Create test users with the given usernames and modes and enrolls them in the given course.
Usage: create_test_users.py username1 ... usernameN [--course] [--mode] [--password] [--domain] [--course_staff]
Examples:
create_test_users.py
create_test_users.py user1 --course MITx/6.002x/2012_Fall --domain testuniversity.edu
create_test_users.py testmasters1 testmasters2 --course HarvardX/CS50x/2012 --mode masters
create_test_users.py testcoursestaff1 testcoursestaff2 --course DemoX/MS12/1 --course_staff --password testpassword
"""
def add_arguments(self, parser):
parser.add_argument(
'usernames',
help='Usernames to use for created users.',
nargs='+'
)
parser.add_argument(
'--course',
help='Add newly created users to this course',
type=CourseKey.from_string
)
parser.add_argument(
'--mode',
help='The enrollment mode for the test users. If --course is not provided, this is ignored',
default='audit',
choices=CourseMode.ALL_MODES
)
parser.add_argument(
'--password',
help='Password to use for all created users.',
default='12345'
)
parser.add_argument(
'--domain',
help='Domain for email addresses for created accounts',
default='example.com'
)
parser.add_argument(
'--course_staff',
help=(
'If present, users are created as course staff. --mode, if specified, is ignored. '
'If --course is not provided, this is ignored'
),
action='store_true'
)
def handle(self, *args, **options):
course_key = options['course']
course_staff = options['course_staff'] if course_key else None
enrollment_mode = options['mode'] if course_key and not course_staff else None
create_users(
course_key,
user_info_generator(
options['usernames'],
options['password'],
options['domain']
),
enrollment_mode=enrollment_mode,
course_staff=course_staff,
activate=True
)