diff --git a/cms/envs/acceptance.py b/cms/envs/acceptance.py index 8b208123cc..708583719e 100644 --- a/cms/envs/acceptance.py +++ b/cms/envs/acceptance.py @@ -8,7 +8,7 @@ so that we can run the lettuce acceptance tests. # pylint: disable=W0401, W0614 from .test import * -from selenium.webdriver.common.desired_capabilities import DesiredCapabilities +from lms.envs.sauce import * # You need to start the server in debug mode, # otherwise the browser will not render the pages correctly @@ -19,22 +19,7 @@ import logging logging.disable(logging.ERROR) import os from random import choice -PORTS = [2000, 2001, 2020, 2109, 2222, 2310, 3000, 3001, - 3030, 3210, 3333, 4000, 4001, 4040, 4321, 4502, 4503, 5000, 5001, - 5050, 5555, 5432, 6000, 6001, 6060, 6666, 6543, 7000, 7070, 7774, - 7777, 8003, 8031, 8080, 8081, 8765, 8888, 9000, 9001, - 9080, 9090, 9876, 9999, 49221, 55001] -DESIRED_CAPABILITIES = { - 'chrome': DesiredCapabilities.CHROME, - 'internet explorer': DesiredCapabilities.INTERNETEXPLORER, - 'firefox': DesiredCapabilities.FIREFOX, - 'opera': DesiredCapabilities.OPERA, - 'iphone': DesiredCapabilities.IPHONE, - 'ipad': DesiredCapabilities.IPAD, - 'safari': DesiredCapabilities.SAFARI, - 'android': DesiredCapabilities.ANDROID -} def seed(): return os.getppid() @@ -96,19 +81,6 @@ MITX_FEATURES['AUTOMATIC_AUTH_FOR_TESTING'] = True # We do not yet understand why this occurs. Setting this to true is a stopgap measure USE_I18N = True -# Information needed to utilize Sauce Labs. -SAUCE = { - 'SAUCE_ENABLED' : os.environ.get('SAUCE_ENABLED'), - 'USERNAME' : os.environ.get('SAUCE_USER_NAME'), - 'ACCESS_ID' : os.environ.get('SAUCE_API_KEY'), - 'BROWSER' : DESIRED_CAPABILITIES.get(os.environ.get('SAUCE_BROWSER', 'chrome').lower(), DesiredCapabilities.CHROME), - 'PLATFORM' : os.environ.get('SAUCE_PLATFORM', 'Linux'), - 'VERSION' : os.environ.get('SAUCE_VERSION', ''), - 'DEVICE' : os.environ.get('SAUCE_DEVICE', ''), - 'SESSION' : 'Jenkins Acceptance Tests', - 'BUILD' : os.environ.get('JOB_NAME', 'CMS TESTS'), -} - # Include the lettuce app for acceptance testing, including the 'harvest' django-admin command INSTALLED_APPS += ('lettuce.django',) LETTUCE_APPS = ('contentstore',) diff --git a/common/djangoapps/terrain/browser.py b/common/djangoapps/terrain/browser.py index 0068e587b0..80c47433b7 100644 --- a/common/djangoapps/terrain/browser.py +++ b/common/djangoapps/terrain/browser.py @@ -55,11 +55,12 @@ def set_job_status(jobid, passed=True): body_content = json.dumps({"passed": passed}) config = get_username_and_key() base64string = base64.encodestring('{}:{}'.format(config['username'], config['access-key']))[:-1] - result=requests.put('http://saucelabs.com/rest/v1/{}/jobs/{}'.format(config['username'], world.jobid), + result = requests.put('http://saucelabs.com/rest/v1/{}/jobs/{}'.format(config['username'], world.jobid), data=body_content, headers={"Authorization": "Basic {}".format(base64string)}) return result.status_code == 200 + def make_desired_capabilities(): desired_capabilities = settings.SAUCE.get('BROWSER', DesiredCapabilities.CHROME) desired_capabilities['platform'] = settings.SAUCE.get('PLATFORM') @@ -75,8 +76,9 @@ def make_desired_capabilities(): desired_capabilities['public'] = 'public restricted' return desired_capabilities + def get_username_and_key(): - return {"username": settings.SAUCE.get('USERNAME'),"access-key": settings.SAUCE.get('ACCESS_ID')} + return {"username": settings.SAUCE.get('USERNAME'), "access-key": settings.SAUCE.get('ACCESS_ID')} @before.harvest @@ -99,7 +101,7 @@ def initial_setup(server): config = get_username_and_key() world.browser = Browser( 'remote', - url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config['username'],config['access-key']), + url="http://{}:{}@ondemand.saucelabs.com:80/wd/hub".format(config['username'], config['access-key']), **make_desired_capabilities() ) world.absorb(world.browser.driver.session_id, 'jobid') @@ -147,7 +149,6 @@ def clear_data(scenario): world.spew('scenario_dict') - @after.each_scenario def reset_databases(scenario): ''' @@ -179,5 +180,5 @@ def teardown_browser(total): Quit the browser after executing the tests. """ if world.SAUCE_ENABLED: - set_job_status(world.jobid, total.scenarios_ran == total.scenarios_passed) + set_job_status(world.jobid, total.scenarios_ran == total.scenarios_passed) world.browser.quit() diff --git a/lms/envs/acceptance.py b/lms/envs/acceptance.py index 80e8fd980e..969f461640 100644 --- a/lms/envs/acceptance.py +++ b/lms/envs/acceptance.py @@ -8,8 +8,7 @@ so that we can run the lettuce acceptance tests. # pylint: disable=W0401, W0614 from .test import * - -from selenium.webdriver.common.desired_capabilities import DesiredCapabilities +from .sauce import * # You need to start the server in debug mode, # otherwise the browser will not render the pages correctly @@ -20,22 +19,7 @@ import logging logging.disable(logging.ERROR) import os from random import choice -PORTS = [2000, 2001, 2020, 2109, 2222, 2310, 3000, 3001, - 3030, 3210, 3333, 4000, 4001, 4040, 4321, 4502, 4503, 5000, 5001, - 5050, 5555, 5432, 6000, 6001, 6060, 6666, 6543, 7000, 7070, 7774, - 7777, 8003, 8031, 8080, 8081, 8765, 8888, 9000, 9001, - 9080, 9090, 9876, 9999, 49221, 55001] -DESIRED_CAPABILITIES = { - 'chrome': DesiredCapabilities.CHROME, - 'internet explorer': DesiredCapabilities.INTERNETEXPLORER, - 'firefox': DesiredCapabilities.FIREFOX, - 'opera': DesiredCapabilities.OPERA, - 'iphone': DesiredCapabilities.IPHONE, - 'ipad': DesiredCapabilities.IPAD, - 'safari': DesiredCapabilities.SAFARI, - 'android': DesiredCapabilities.ANDROID -} def seed(): return os.getppid() @@ -104,20 +88,6 @@ MITX_FEATURES['AUTOMATIC_AUTH_FOR_TESTING'] = True # We do not yet understand why this occurs. Setting this to true is a stopgap measure USE_I18N = True -# Information needed to utilize Sauce Labs. -SAUCE = { - 'SAUCE_ENABLED' : os.environ.get('SAUCE_ENABLED'), - 'USERNAME' : os.environ.get('SAUCE_USER_NAME'), - 'ACCESS_ID' : os.environ.get('SAUCE_API_KEY'), - 'BROWSER' : DESIRED_CAPABILITIES.get(os.environ.get('SAUCE_BROWSER', 'chrome').lower(), DesiredCapabilities.CHROME), - 'PLATFORM' : os.environ.get('SAUCE_PLATFORM', 'Linux'), - 'VERSION' : os.environ.get('SAUCE_VERSION', ''), - 'DEVICE' : os.environ.get('SAUCE_DEVICE', ''), - 'SESSION' : 'Jenkins Acceptance Tests', - 'BUILD' : os.environ.get('JOB_NAME', 'LMS TESTS'), -} - - # Include the lettuce app for acceptance testing, including the 'harvest' django-admin command INSTALLED_APPS += ('lettuce.django',) LETTUCE_APPS = ('courseware',) diff --git a/lms/envs/sauce.py b/lms/envs/sauce.py new file mode 100644 index 0000000000..2692037082 --- /dev/null +++ b/lms/envs/sauce.py @@ -0,0 +1,46 @@ +""" +This config file extends the test environment configuration +so that we can run the lettuce acceptance tests on SauceLabs. +""" + +# We intentionally define lots of variables that aren't used, and +# want to import all variables from base settings files +# pylint: disable=W0401, W0614 + +from selenium.webdriver.common.desired_capabilities import DesiredCapabilities +import os +import json + +PORTS = [2000, 2001, 2020, 2109, 2222, 2310, 3000, 3001, + 3030, 3210, 3333, 4000, 4001, 4040, 4321, 4502, 4503, 5000, 5001, + 5050, 5555, 5432, 6000, 6001, 6060, 6666, 6543, 7000, 7070, 7774, + 7777, 8003, 8031, 8080, 8081, 8765, 8888, 9000, 9001, + 9080, 9090, 9876, 9999, 49221, 55001] + +DESIRED_CAPABILITIES = { + 'chrome': DesiredCapabilities.CHROME, + 'internet explorer': DesiredCapabilities.INTERNETEXPLORER, + 'firefox': DesiredCapabilities.FIREFOX, + 'opera': DesiredCapabilities.OPERA, + 'iphone': DesiredCapabilities.IPHONE, + 'ipad': DesiredCapabilities.IPAD, + 'safari': DesiredCapabilities.SAFARI, + 'android': DesiredCapabilities.ANDROID +} + +DEFAULT_CONFIG='{"PLATFORM":"Linux", "BROWSER":"chrome", "VERISON":"", "DEVICE":""}' + +SAUCE_INFO = json.loads(os.environ.get('SAUCE_INFO', DEFAULT_CONFIG)) + +# Information needed to utilize Sauce Labs. +SAUCE = { + 'SAUCE_ENABLED': os.environ.get('SAUCE_ENABLED'), + 'USERNAME': os.environ.get('SAUCE_USER_NAME'), + 'ACCESS_ID': os.environ.get('SAUCE_API_KEY'), + 'BROWSER': DESIRED_CAPABILITIES.get(SAUCE_INFO.get('BROWSER', 'chrome').lower(), DesiredCapabilities.CHROME), + 'PLATFORM': SAUCE_INFO.get('PLATFORM', 'Linux'), + 'VERSION': SAUCE_INFO.get('VERSION', ''), + 'DEVICE': SAUCE_INFO.get('DEVICE', ''), + 'SESSION': 'Jenkins Acceptance Tests', + 'BUILD': os.environ.get('JOB_NAME', 'LETTUCE TESTS'), +}