From 8414ef022f39aab8f72016db0e5dab481038386a Mon Sep 17 00:00:00 2001 From: Jay Zoldak Date: Wed, 7 Aug 2013 17:04:50 -0400 Subject: [PATCH] Modify lms acceptance test to use auto_auth. --- common/djangoapps/terrain/course_helpers.py | 30 ++++----------------- lms/envs/acceptance.py | 3 +++ 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/common/djangoapps/terrain/course_helpers.py b/common/djangoapps/terrain/course_helpers.py index 081e2a3bc2..235305716d 100644 --- a/common/djangoapps/terrain/course_helpers.py +++ b/common/djangoapps/terrain/course_helpers.py @@ -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 diff --git a/lms/envs/acceptance.py b/lms/envs/acceptance.py index 5f8fd99c16..a58420ab1e 100644 --- a/lms/envs/acceptance.py +++ b/lms/envs/acceptance.py @@ -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',)