Modify lms acceptance test to use auto_auth.
This commit is contained in:
@@ -34,33 +34,13 @@ def create_user(uname, password):
|
||||
|
||||
|
||||
@world.absorb
|
||||
def log_in(username, password):
|
||||
def log_in(username='robot', password='test', email='robot@edx.org', name='Robot'):
|
||||
"""
|
||||
Log the user in programatically.
|
||||
This will delete any existing cookies to ensure that the user
|
||||
logs in to the correct session.
|
||||
Use the auto_auth feature to programmatically log the user in
|
||||
"""
|
||||
|
||||
# Authenticate the user
|
||||
world.scenario_dict['USER'] = authenticate(username=username, password=password)
|
||||
assert(world.scenario_dict['USER'] is not None and world.scenario_dict['USER'].is_active)
|
||||
|
||||
# Send a fake HttpRequest to log the user in
|
||||
# We need to process the request using
|
||||
# Session middleware and Authentication middleware
|
||||
# to ensure that session state can be stored
|
||||
request = HttpRequest()
|
||||
SessionMiddleware().process_request(request)
|
||||
AuthenticationMiddleware().process_request(request)
|
||||
login(request, world.scenario_dict['USER'])
|
||||
|
||||
# Save the session
|
||||
request.session.save()
|
||||
|
||||
# Retrieve the sessionid and add it to the browser's cookies
|
||||
cookie_dict = {settings.SESSION_COOKIE_NAME: request.session.session_key}
|
||||
world.browser.cookies.delete()
|
||||
world.browser.cookies.add(cookie_dict)
|
||||
url = '/auto_auth?username=%s&password=%s&name=%s&email=%s' % (username,
|
||||
password, name, email)
|
||||
world.visit(url)
|
||||
|
||||
|
||||
@world.absorb
|
||||
|
||||
@@ -83,6 +83,9 @@ MITX_FEATURES['STUB_VIDEO_FOR_TESTING'] = True
|
||||
# per-test control for acceptance tests
|
||||
MITX_FEATURES['ENABLE_DISCUSSION_SERVICE'] = True
|
||||
|
||||
# Use the auto_auth workflow for creating users and logging them in
|
||||
MITX_FEATURES['AUTOMATIC_AUTH_FOR_TESTING'] = True
|
||||
|
||||
# Include the lettuce app for acceptance testing, including the 'harvest' django-admin command
|
||||
INSTALLED_APPS += ('lettuce.django',)
|
||||
LETTUCE_APPS = ('courseware',)
|
||||
|
||||
Reference in New Issue
Block a user