From 0782e72d07732b44ce2ffe9efe485a59f0687f98 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Sun, 22 Dec 2013 21:53:56 -0500 Subject: [PATCH] Added fabric command to install edxapp pages with new directory structure Added Jenkins script to configure and run tests for edxapp --- fabfile.py | 45 ++++++++++++++++++++++++++++++- jenkins/test_edxapp.sh | 55 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 5 +--- test_lms/base.py | 4 +-- test_lms/test_lms.py | 22 +++++++-------- test_lms/test_ora.py | 6 ++--- test_studio/test_studio.py | 6 ++--- 7 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 jenkins/test_edxapp.sh diff --git a/fabfile.py b/fabfile.py index e5100470..69c13398 100644 --- a/fabfile.py +++ b/fabfile.py @@ -3,8 +3,9 @@ """ import os +import shutil from ConfigParser import SafeConfigParser -from fabric.api import task, local +from fabric.api import task, local, lcd from textwrap import dedent from path import path import requests @@ -21,6 +22,13 @@ # Process timeout for test results PROCESS_TIMEOUT = 600 +# edx-platform git repo +# Used to install the page objects for edxapp +EDX_PLATFORM_REPO_NAME = "edx-platform" +EDX_PLATFORM_REPO_URL = "https://github.com/edx/edx-platform.git" +EDXAPP_PAGES_DIR = "common/test/bok_choy" +EDX_PLATFORM_VERSION = "659e590fc9386e17f36ffa0e59ac10fd08cb7635" + @task def config_lms(**kwargs): @@ -49,6 +57,41 @@ def config_mktg(**kwargs): _set_config('mktg', kwargs) +@task +def install_pages(repo_dirname="/tmp"): + """ + Install page objects from external repos. + + `repo_dirname` is the directory in which to clone the repos. + If a copy of the repo does not yet exist under this directory + then it will first be cloned there. + + WARNING: This operation is NOT safe to run concurrently. + """ + try: + + # Clone the repo and check out the commit + repo_path = os.path.join(repo_dirname, EDX_PLATFORM_REPO_NAME) + if not os.path.isdir(repo_path): + local(_cmd("git", "clone", EDX_PLATFORM_REPO_URL, repo_path)) + + with lcd(repo_path): + local(_cmd("git", "fetch")) + local(_cmd("git", "checkout", EDX_PLATFORM_VERSION)) + + # Install the page objects in the current virtualenv + with lcd(os.path.join(repo_path, EDXAPP_PAGES_DIR)): + local(_cmd("python", "setup.py", "install")) + + # Fabric will fail-fast and exit if any of these commands fail + # This could leave the git repository in an unusable state + # Therefore, if we exit with a fatal error, assume that the git repository + # can no longer be trusted and delete it. + except SystemExit: + if os.path.isdir(repo_path): + shutil.rmtree(repo_path) + + @task def test(): """ diff --git a/jenkins/test_edxapp.sh b/jenkins/test_edxapp.sh new file mode 100644 index 00000000..3a390501 --- /dev/null +++ b/jenkins/test_edxapp.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +# Run end-to-end tests for edxapp and other services in Jenkins +# Assumes that the following environment variables are set: +# +# TEST_ENV_HOST: hostname to run the tests on (e.g. test.domain.org) +# Assumes that Studio is served from studio.$TEST_ENV_HOST +# +# BASIC_AUTH_USER and BASIC_AUTH_PASSWORD: basic auth credentials; can be blank +# +# REGISTRATION_EMAIL: email used to register for new courses (e.g. test@example.com) +# +# SSH_USER and SSH_KEYFILE: user and private key to ssh into the test server +# +# Optional: Saucelabs plugin may set additional environment variables, +# which are printed to make debugging easier + +set -e + +# Create the virtualenv and install requirements +mkdir -p venv +virtualenv venv +. venv/bin/activate +pip install -r requirements.txt + +# Install edxapp page objects +# This operation is not safe to run concurrently, +# so ensure the jobs use unique directories +mkdir -p /mnt/tmp/${JOB_NAME} +fab install_pages:/mnt/tmp/${JOB_NAME} + +# Debug information +echo "SELENIUM_BROWSER=$SELENIUM_BROWSER" +echo "SELENIUM_VERSION=$SELENIUM_VERSION" +echo "SELENIUM_PLATFORM=$SELENIUM_PLATFORM" + +# Configure the test +fab config_lms:protocol=http +fab config_lms:test_host=$TEST_ENV_HOST +fab config_lms:basic_auth_user=$BASIC_AUTH_USER +fab config_lms:basic_auth_password=$BASIC_AUTH_PASSWORD +fab config_lms:registration_email=$REGISTRATION_EMAIL +fab config_lms:ssh_user=$SSH_USER +fab config_lms:ssh_keyfile=$SSH_KEYFILE + +fab config_studio:protocol=http +fab config_studio:test_host=studio.$TEST_ENV_HOST +fab config_studio:basic_auth_user=$BASIC_AUTH_USER +fab config_studio:basic_auth_password=$BASIC_AUTH_PASSWORD +fab config_studio:ssh_user=$SSH_USER +fab config_studio:ssh_keyfile=$SSH_KEYFILE + +# Run the tests +fab test_lms +fab test_studio diff --git a/requirements.txt b/requirements.txt index 5ec1ed1a..c91f85ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,4 @@ requests==2.0.1 nose # bok-choy framework --e git+https://github.com/edx/bok-choy.git@69eb162b0bd1e8bf4c4c2d88bd1ea01930b32f3d#egg=bok_choy - -# edx-platform page objects --e git+https://github.com/edx/edx-platform.git@04e66be70589612b0e5ffb6c55465932ca930e8d#egg=edxapp_selenium_pages +-e git+https://github.com/edx/bok-choy.git@d276a2b508820651ae6e20266dc8e584f128bd3a#egg=bok_choy diff --git a/test_lms/base.py b/test_lms/base.py index 3332bb75..e5cd80eb 100644 --- a/test_lms/base.py +++ b/test_lms/base.py @@ -4,8 +4,8 @@ from bok_choy.web_app_test import WebAppTest from .fixtures import UserFixture -from edxapp_selenium_pages.lms.login import LoginPage -from edxapp_selenium_pages.lms.dashboard import DashboardPage +from edxapp_pages.lms.login import LoginPage +from edxapp_pages.lms.dashboard import DashboardPage class LoggedInTest(WebAppTest): diff --git a/test_lms/test_lms.py b/test_lms/test_lms.py index a11c9032..2715aa3d 100644 --- a/test_lms/test_lms.py +++ b/test_lms/test_lms.py @@ -8,17 +8,17 @@ from credentials import TestCredentials from fixtures import UserFixture -from edxapp_selenium_pages.lms.login import LoginPage -from edxapp_selenium_pages.lms.find_courses import FindCoursesPage -from edxapp_selenium_pages.lms.info import InfoPage -from edxapp_selenium_pages.lms.course_about import CourseAboutPage -from edxapp_selenium_pages.lms.register import RegisterPage -from edxapp_selenium_pages.lms.dashboard import DashboardPage -from edxapp_selenium_pages.lms.course_info import CourseInfoPage -from edxapp_selenium_pages.lms.tab_nav import TabNavPage -from edxapp_selenium_pages.lms.course_nav import CourseNavPage -from edxapp_selenium_pages.lms.progress import ProgressPage -from edxapp_selenium_pages.lms.video import VideoPage +from edxapp_pages.lms.login import LoginPage +from edxapp_pages.lms.find_courses import FindCoursesPage +from edxapp_pages.lms.info import InfoPage +from edxapp_pages.lms.course_about import CourseAboutPage +from edxapp_pages.lms.register import RegisterPage +from edxapp_pages.lms.dashboard import DashboardPage +from edxapp_pages.lms.course_info import CourseInfoPage +from edxapp_pages.lms.tab_nav import TabNavPage +from edxapp_pages.lms.course_nav import CourseNavPage +from edxapp_pages.lms.progress import ProgressPage +from edxapp_pages.lms.video import VideoPage from .base import LoggedInTest diff --git a/test_lms/test_ora.py b/test_lms/test_ora.py index 9c2b1831..225cd920 100644 --- a/test_lms/test_ora.py +++ b/test_lms/test_ora.py @@ -3,9 +3,9 @@ """ from .base import LoggedInTest -from edxapp_selenium_pages.lms.tab_nav import TabNavPage -from edxapp_selenium_pages.lms.course_nav import CourseNavPage -from edxapp_selenium_pages.lms.open_response import OpenResponsePage +from edxapp_pages.lms.tab_nav import TabNavPage +from edxapp_pages.lms.course_nav import CourseNavPage +from edxapp_pages.lms.open_response import OpenResponsePage class OpenResponseTest(LoggedInTest): diff --git a/test_studio/test_studio.py b/test_studio/test_studio.py index 97346a01..50ed5e46 100644 --- a/test_studio/test_studio.py +++ b/test_studio/test_studio.py @@ -3,9 +3,9 @@ """ from bok_choy.web_app_test import WebAppTest -from edxapp_selenium_pages.studio.login import LoginPage -from edxapp_selenium_pages.studio.howitworks import HowitworksPage -from edxapp_selenium_pages.studio.signup import SignupPage +from edxapp_pages.studio.login import LoginPage +from edxapp_pages.studio.howitworks import HowitworksPage +from edxapp_pages.studio.signup import SignupPage class LoggedOutTest(WebAppTest):