Commit b14553d8 by Jonah Stanley

Merge pull request #220 from edx/jonahstanley/make-units-parallel

Jonahstanley/make units parallel
parents 397583e1 8a9125f1
...@@ -23,7 +23,7 @@ from xmodule.modulestore import Location ...@@ -23,7 +23,7 @@ from xmodule.modulestore import Location
from xmodule.modulestore.store_utilities import clone_course from xmodule.modulestore.store_utilities import clone_course
from xmodule.modulestore.store_utilities import delete_course from xmodule.modulestore.store_utilities import delete_course
from xmodule.modulestore.django import modulestore from xmodule.modulestore.django import modulestore
from xmodule.contentstore.django import contentstore from xmodule.contentstore.django import contentstore, _CONTENTSTORE
from xmodule.templates import update_templates from xmodule.templates import update_templates
from xmodule.modulestore.xml_exporter import export_to_xml from xmodule.modulestore.xml_exporter import export_to_xml
from xmodule.modulestore.xml_importer import import_from_xml, perform_xlint from xmodule.modulestore.xml_importer import import_from_xml, perform_xlint
...@@ -43,10 +43,12 @@ from django_comment_common.utils import are_permissions_roles_seeded ...@@ -43,10 +43,12 @@ from django_comment_common.utils import are_permissions_roles_seeded
from xmodule.exceptions import InvalidVersionError from xmodule.exceptions import InvalidVersionError
import datetime import datetime
from pytz import UTC from pytz import UTC
from uuid import uuid4
from pymongo import MongoClient
TEST_DATA_MODULESTORE = copy.deepcopy(settings.MODULESTORE)
TEST_DATA_MODULESTORE['default']['OPTIONS']['fs_root'] = path('common/test/data') TEST_DATA_CONTENTSTORE = copy.deepcopy(settings.CONTENTSTORE)
TEST_DATA_MODULESTORE['direct']['OPTIONS']['fs_root'] = path('common/test/data') TEST_DATA_CONTENTSTORE['OPTIONS']['db'] = 'test_xcontent_%s' % uuid4().hex
class MongoCollectionFindWrapper(object): class MongoCollectionFindWrapper(object):
...@@ -59,13 +61,16 @@ class MongoCollectionFindWrapper(object): ...@@ -59,13 +61,16 @@ class MongoCollectionFindWrapper(object):
return self.original(query, *args, **kwargs) return self.original(query, *args, **kwargs)
@override_settings(MODULESTORE=TEST_DATA_MODULESTORE) @override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ContentStoreToyCourseTest(ModuleStoreTestCase): class ContentStoreToyCourseTest(ModuleStoreTestCase):
""" """
Tests that rely on the toy courses. Tests that rely on the toy courses.
TODO: refactor using CourseFactory so they do not. TODO: refactor using CourseFactory so they do not.
""" """
def setUp(self): def setUp(self):
settings.MODULESTORE['default']['OPTIONS']['fs_root'] = path('common/test/data')
settings.MODULESTORE['direct']['OPTIONS']['fs_root'] = path('common/test/data')
uname = 'testuser' uname = 'testuser'
email = 'test+courses@edx.org' email = 'test+courses@edx.org'
password = 'foo' password = 'foo'
...@@ -83,6 +88,11 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -83,6 +88,11 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.client = Client() self.client = Client()
self.client.login(username=uname, password=password) self.client.login(username=uname, password=password)
def tearDown(self):
mongo = MongoClient()
mongo.drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()
def check_components_on_page(self, component_types, expected_types): def check_components_on_page(self, component_types, expected_types):
""" """
Ensure that the right types end up on the page. Ensure that the right types end up on the page.
...@@ -403,7 +413,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -403,7 +413,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertGreater(len(all_assets), 0) self.assertGreater(len(all_assets), 0)
# make sure we have some thumbnails in our contentstore # make sure we have some thumbnails in our contentstore
all_thumbnails = content_store.get_all_content_thumbnails_for_course(course_location) content_store.get_all_content_thumbnails_for_course(course_location)
# #
# cdodge: temporarily comment out assertion on thumbnails because many environments # cdodge: temporarily comment out assertion on thumbnails because many environments
...@@ -442,7 +452,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -442,7 +452,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
content_store = contentstore() content_store = contentstore()
trash_store = contentstore('trashcan') trash_store = contentstore('trashcan')
module_store = modulestore('direct') module_store = modulestore('direct')
import_from_xml(module_store, 'common/test/data/', ['full'], static_content_store=content_store) import_from_xml(module_store, 'common/test/data/', ['full'], static_content_store=content_store)
# look up original (and thumbnail) in content store, should be there after import # look up original (and thumbnail) in content store, should be there after import
...@@ -533,7 +542,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -533,7 +542,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
all_assets = trash_store.get_all_content_for_course(course_location) all_assets = trash_store.get_all_content_for_course(course_location)
self.assertEqual(len(all_assets), 0) self.assertEqual(len(all_assets), 0)
all_thumbnails = trash_store.get_all_content_thumbnails_for_course(course_location) all_thumbnails = trash_store.get_all_content_thumbnails_for_course(course_location)
self.assertEqual(len(all_thumbnails), 0) self.assertEqual(len(all_thumbnails), 0)
...@@ -598,7 +606,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -598,7 +606,6 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
self.assertRaises(InvalidVersionError, draft_store.unpublish, location) self.assertRaises(InvalidVersionError, draft_store.unpublish, location)
def test_bad_contentstore_request(self): def test_bad_contentstore_request(self):
resp = self.client.get('http://localhost:8001/c4x/CDX/123123/asset/&images_circuits_Lab7Solution2.png') resp = self.client.get('http://localhost:8001/c4x/CDX/123123/asset/&images_circuits_Lab7Solution2.png')
self.assertEqual(resp.status_code, 400) self.assertEqual(resp.status_code, 400)
...@@ -809,6 +816,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase): ...@@ -809,6 +816,7 @@ class ContentStoreToyCourseTest(ModuleStoreTestCase):
export_to_xml(module_store, content_store, location, root_dir, 'test_export') export_to_xml(module_store, content_store, location, root_dir, 'test_export')
@override_settings(CONTENTSTORE=TEST_DATA_CONTENTSTORE)
class ContentStoreTest(ModuleStoreTestCase): class ContentStoreTest(ModuleStoreTestCase):
""" """
Tests for the CMS ContentStore application. Tests for the CMS ContentStore application.
...@@ -845,6 +853,11 @@ class ContentStoreTest(ModuleStoreTestCase): ...@@ -845,6 +853,11 @@ class ContentStoreTest(ModuleStoreTestCase):
'display_name': 'Robot Super Course', 'display_name': 'Robot Super Course',
} }
def tearDown(self):
mongo = MongoClient()
mongo.drop_database(TEST_DATA_CONTENTSTORE['OPTIONS']['db'])
_CONTENTSTORE.clear()
def test_create_course(self): def test_create_course(self):
"""Test new course creation - happy path""" """Test new course creation - happy path"""
resp = self.client.post(reverse('create_new_course'), self.course_data) resp = self.client.post(reverse('create_new_course'), self.course_data)
......
...@@ -70,7 +70,7 @@ CONTENTSTORE = { ...@@ -70,7 +70,7 @@ CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore', 'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'OPTIONS': { 'OPTIONS': {
'host': 'localhost', 'host': 'localhost',
'db': 'test_xmodule', 'db': 'test_xcontent',
}, },
# allow for additional options that can be keyed on a name, e.g. 'trashcan' # allow for additional options that can be keyed on a name, e.g. 'trashcan'
'ADDITIONAL_OPTIONS': { 'ADDITIONAL_OPTIONS': {
......
...@@ -27,6 +27,7 @@ class ModuleStoreTestCase(TestCase): ...@@ -27,6 +27,7 @@ class ModuleStoreTestCase(TestCase):
# Remove everything except templates # Remove everything except templates
modulestore.collection.remove(query) modulestore.collection.remove(query)
modulestore.collection.drop()
@staticmethod @staticmethod
def load_templates_if_necessary(): def load_templates_if_necessary():
......
...@@ -13,11 +13,12 @@ from xmodule.templates import update_templates ...@@ -13,11 +13,12 @@ from xmodule.templates import update_templates
from .test_modulestore import check_path_to_location from .test_modulestore import check_path_to_location
from . import DATA_DIR from . import DATA_DIR
from uuid import uuid4
HOST = 'localhost' HOST = 'localhost'
PORT = 27017 PORT = 27017
DB = 'test' DB = 'test_mongo_%s' % uuid4().hex
COLLECTION = 'modulestore' COLLECTION = 'modulestore'
FS_ROOT = DATA_DIR # TODO (vshnayder): will need a real fs_root for testing load_item FS_ROOT = DATA_DIR # TODO (vshnayder): will need a real fs_root for testing load_item
DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor' DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor'
...@@ -39,7 +40,8 @@ class TestMongoModuleStore(object): ...@@ -39,7 +40,8 @@ class TestMongoModuleStore(object):
@classmethod @classmethod
def teardownClass(cls): def teardownClass(cls):
pass cls.connection = pymongo.connection.Connection(HOST, PORT)
cls.connection.drop_database(DB)
@staticmethod @staticmethod
def initdb(): def initdb():
......
...@@ -60,9 +60,6 @@ fi ...@@ -60,9 +60,6 @@ fi
export PIP_DOWNLOAD_CACHE=/mnt/pip-cache export PIP_DOWNLOAD_CACHE=/mnt/pip-cache
# Allow django liveserver tests to use a range of ports
export DJANGO_LIVE_TEST_SERVER_ADDRESS=${DJANGO_LIVE_TEST_SERVER_ADDRESS-localhost:8000-9000}
source /mnt/virtualenvs/"$JOB_NAME"/bin/activate source /mnt/virtualenvs/"$JOB_NAME"/bin/activate
bundle install bundle install
......
...@@ -16,7 +16,7 @@ def run_tests(system, report_dir, test_id=nil, stop_on_failure=true) ...@@ -16,7 +16,7 @@ def run_tests(system, report_dir, test_id=nil, stop_on_failure=true)
ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml") ENV['NOSE_XUNIT_FILE'] = File.join(report_dir, "nosetests.xml")
dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"] dirs = Dir["common/djangoapps/*"] + Dir["#{system}/djangoapps/*"]
test_id = dirs.join(' ') if test_id.nil? or test_id == '' test_id = dirs.join(' ') if test_id.nil? or test_id == ''
cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', test_id) cmd = django_admin(system, :test, 'test', '--logging-clear-handlers', '--liveserver=localhost:8000-9000', test_id)
test_sh(run_under_coverage(cmd, system)) test_sh(run_under_coverage(cmd, system))
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment