From 1f2f0bf348fc31108e554b50bead3bcfff61eb28 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Wed, 28 Aug 2013 21:02:42 -0400 Subject: [PATCH] Skip acceptance test DB migrations if the DB already exists and running fasttest_acceptance --- cms/envs/acceptance.py | 4 +- cms/envs/acceptance_static.py | 77 ----------------------------------- lms/envs/acceptance.py | 4 +- lms/envs/acceptance_static.py | 77 ----------------------------------- rakelib/tests.rake | 32 ++++++++++++--- 5 files changed, 30 insertions(+), 164 deletions(-) delete mode 100644 cms/envs/acceptance_static.py delete mode 100644 lms/envs/acceptance_static.py diff --git a/cms/envs/acceptance.py b/cms/envs/acceptance.py index 3b89e2e988..32bae3c34c 100644 --- a/cms/envs/acceptance.py +++ b/cms/envs/acceptance.py @@ -68,8 +68,8 @@ CONTENTSTORE = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': TEST_ROOT / "db" / "test_mitx_%s.db" % seed(), - 'TEST_NAME': TEST_ROOT / "db" / "test_mitx_%s.db" % seed(), + 'NAME': TEST_ROOT / "db" / "test_edx.db", + 'TEST_NAME': TEST_ROOT / "db" / "test_edx.db" } } diff --git a/cms/envs/acceptance_static.py b/cms/envs/acceptance_static.py deleted file mode 100644 index f7d69794fb..0000000000 --- a/cms/envs/acceptance_static.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -This config file extends the test environment configuration -so that we can run the lettuce acceptance tests. -This is used in the django-admin call as acceptance.py -contains random seeding, causing django-admin to create a random collection -""" - -# 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 .test import * - -# You need to start the server in debug mode, -# otherwise the browser will not render the pages correctly -DEBUG = True - -# Disable warnings for acceptance tests, to make the logs readable -import logging -logging.disable(logging.ERROR) -import os -import random - -MODULESTORE_OPTIONS = { - 'default_class': 'xmodule.raw_module.RawDescriptor', - 'host': 'localhost', - 'db': 'acceptance_xmodule', - 'collection': 'acceptance_modulestore', - 'fs_root': TEST_ROOT / "data", - 'render_template': 'mitxmako.shortcuts.render_to_string', -} - -MODULESTORE = { - 'default': { - 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', - 'OPTIONS': MODULESTORE_OPTIONS - }, - 'direct': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'OPTIONS': MODULESTORE_OPTIONS - }, - 'draft': { - 'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore', - 'OPTIONS': MODULESTORE_OPTIONS - } -} - -CONTENTSTORE = { - 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', - 'OPTIONS': { - 'host': 'localhost', - 'db': 'acceptance_xcontent', - }, - # allow for additional options that can be keyed on a name, e.g. 'trashcan' - 'ADDITIONAL_OPTIONS': { - 'trashcan': { - 'bucket': 'trash_fs' - } - } -} - -# Set this up so that rake lms[acceptance] and running the -# harvest command both use the same (test) database -# which they can flush without messing up your dev db -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': TEST_ROOT / "db" / "test_mitx.db", - 'TEST_NAME': TEST_ROOT / "db" / "test_mitx.db", - } -} - -# Include the lettuce app for acceptance testing, including the 'harvest' django-admin command -INSTALLED_APPS += ('lettuce.django',) -LETTUCE_APPS = ('contentstore',) -LETTUCE_SERVER_PORT = random.randint(1024, 65535) -LETTUCE_BROWSER = 'chrome' diff --git a/lms/envs/acceptance.py b/lms/envs/acceptance.py index e866a250d9..5d0e350bb6 100644 --- a/lms/envs/acceptance.py +++ b/lms/envs/acceptance.py @@ -65,8 +65,8 @@ CONTENTSTORE = { DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': TEST_ROOT / "db" / "test_mitx_%s.db" % seed(), - 'TEST_NAME': TEST_ROOT / "db" / "test_mitx_%s.db" % seed(), + 'NAME': TEST_ROOT / "db" / "test_edx.db", + 'TEST_NAME': TEST_ROOT / "db" / "test_edx.db", } } diff --git a/lms/envs/acceptance_static.py b/lms/envs/acceptance_static.py deleted file mode 100644 index 27efb6160d..0000000000 --- a/lms/envs/acceptance_static.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -This config file extends the test environment configuration -so that we can run the lettuce acceptance tests. -""" - -# 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 .test import * - -# You need to start the server in debug mode, -# otherwise the browser will not render the pages correctly -DEBUG = True - -# Disable warnings for acceptance tests, to make the logs readable -import logging -logging.disable(logging.ERROR) -import random - -# Use the mongo store for acceptance tests -modulestore_options = { - 'default_class': 'xmodule.raw_module.RawDescriptor', - 'host': 'localhost', - 'db': 'acceptance_xmodule', - 'collection': 'acceptance_modulestore', - 'fs_root': TEST_ROOT / "data", - 'render_template': 'mitxmako.shortcuts.render_to_string', -} - -MODULESTORE = { - 'default': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'OPTIONS': modulestore_options - }, - 'direct': { - 'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore', - 'OPTIONS': modulestore_options - } -} - -CONTENTSTORE = { - 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', - 'OPTIONS': { - 'host': 'localhost', - 'db': 'acceptance_xcontent', - } -} - -# Set this up so that rake lms[acceptance] and running the -# harvest command both use the same (test) database -# which they can flush without messing up your dev db -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': TEST_ROOT / "db" / "test_mitx.db", - 'TEST_NAME': TEST_ROOT / "db" / "test_mitx.db", - } -} - -# Set up XQueue information so that the lms will send -# requests to a mock XQueue server running locally -XQUEUE_PORT = random.randint(1024, 65535) -XQUEUE_INTERFACE = { - "url": "http://127.0.0.1:%d" % XQUEUE_PORT, - "django_auth": { - "username": "lms", - "password": "***REMOVED***" - }, - "basic_auth": ('anant', 'agarwal'), -} - -# Include the lettuce app for acceptance testing, including the 'harvest' django-admin command -INSTALLED_APPS += ('lettuce.django',) -LETTUCE_APPS = ('courseware',) -LETTUCE_SERVER_PORT = random.randint(1024, 65535) -LETTUCE_BROWSER = 'chrome' diff --git a/rakelib/tests.rake b/rakelib/tests.rake index 1c976b1c05..f7c0fbdc4f 100644 --- a/rakelib/tests.rake +++ b/rakelib/tests.rake @@ -4,6 +4,8 @@ CLOBBER.include(REPORT_DIR, 'test_root/*_repo', 'test_root/staticfiles') # Create the directory to hold coverage reports, if it doesn't already exist. directory REPORT_DIR +ACCEPTANCE_DB = 'test_root/db/test_edx.db' + def test_id_dir(path) return File.join(".testids", path.to_s) end @@ -30,7 +32,7 @@ def run_tests(system, report_dir, test_id=nil, stop_on_failure=true) test_sh(run_under_coverage(cmd, system)) end -def run_acceptance_tests(system, report_dir, harvest_args) +def create_acceptance_db(system) # HACK: Since now the CMS depends on the existence of some database tables # that used to be in LMS (Role/Permissions for Forums) we need to make # sure the acceptance tests create/migrate the database tables @@ -43,6 +45,22 @@ def run_acceptance_tests(system, report_dir, harvest_args) end sh(django_admin(system, 'acceptance', 'syncdb', '--noinput')) sh(django_admin(system, 'acceptance', 'migrate', '--noinput')) +end + +def setup_acceptance_db(system, fasttest=false) + # If running under fasttest mode and the database already + # exists, skip the migrations. + if File.exists?(ACCEPTANCE_DB) + if not fasttest + File.delete(ACCEPTANCE_DB) + create_acceptance_db(system) + end + else + create_acceptance_db(system) + end +end + +def run_acceptance_tests(system, report_dir, harvest_args) test_sh(django_admin(system, 'acceptance', 'harvest', '--debug-mode', '--tag -skip', harvest_args)) end @@ -58,7 +76,7 @@ end task :clean_test_files do desc "Clean fixture files used by tests" - sh("git clean -fqdx test_root") + sh("git clean -fqdx test_root/logs test_root/data test_root/staticfiles test_root/uploads") end task :clean_reports_dir => REPORT_DIR do @@ -91,13 +109,15 @@ TEST_TASK_DIRS = [] # Run acceptance tests desc "Run acceptance tests" - #gather_assets uses its own env because acceptance contains seeds to make the information unique - #acceptance_static is acceptance without the random seeding - task "test_acceptance_#{system}", [:harvest_args] => [:clean_test_files, "#{system}:gather_assets:acceptance_static", "fasttest_acceptance_#{system}"] + task "test_acceptance_#{system}", [:harvest_args] => [:clean_test_files, "#{system}:gather_assets:acceptance"] do |t, args| + setup_acceptance_db(system) + Rake::Task["fasttest_acceptance_#{system}"].invoke(*args) + end - desc "Run acceptance tests without collectstatic" + desc "Run acceptance tests without collectstatic or database migrations" task "fasttest_acceptance_#{system}", [:harvest_args] => [report_dir, :clean_reports_dir, :predjango] do |t, args| args.with_defaults(:harvest_args => '') + setup_acceptance_db(system, fasttest=true) run_acceptance_tests(system, report_dir, args.harvest_args) end