Commit 9ee8c8fd by David Ormsbee

Reduce publish signals during tests.

parent 44e4569d
......@@ -68,3 +68,37 @@ class TestCreateCourse(ModuleStoreTestCase):
)
# pylint: disable=protected-access
self.assertEqual(store, modulestore()._get_modulestore_for_courselike(new_key).get_modulestore_type())
# import cProfile, pstats, StringIO
# from xmodule.modulestore import ModuleStoreEnum
# from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
#
# class TestCreateSingleCourse(ModuleStoreTestCase):
# """
# Unit tests for creating a course in either old mongo or split mongo via command line
#
# These are just here for profiling tests and will be removed later.
# """
#
# @classmethod
# def setUpClass(cls):
# cls.pr = cProfile.Profile()
# cls.pr.enable()
#
# @classmethod
# def tearDownClass(cls):
# cls.pr.disable()
# cls.pr.dump_stats("steelix/ms_tc2.stats")
#
# def setUp(self):
# super(TestCreateSingleCourse, self).setUp()
#
# def test_old_mongo(self):
# course = CourseFactory.create(
# default_store=ModuleStoreEnum.Type.mongo, emit_signals=False
# )
#
# def test_split(self):
# course = CourseFactory.create(
# default_store=ModuleStoreEnum.Type.split, emit_signals=False
# )
......@@ -1234,7 +1234,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
)
return modules
def create_course(self, org, course, run, user_id, fields=None, **kwargs):
def create_course(self, org, course, run, user_id, fields=None, emit_signals=True, **kwargs):
"""
Creates and returns the course.
......@@ -1264,7 +1264,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
if courses.count() > 0:
raise DuplicateCourseError(course_id, courses[0]['_id'])
with self.bulk_operations(course_id):
with self.bulk_operations(course_id, emit_signals=emit_signals):
xblock = self.create_item(user_id, course_id, 'course', course_id.run, fields=fields, **kwargs)
# create any other necessary things as a side effect
......
......@@ -1808,7 +1808,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
def create_course(
self, org, course, run, user_id, master_branch=None, fields=None,
versions_dict=None, search_targets=None, root_category='course',
root_block_id=None, **kwargs
root_block_id=None, emit_signals=True, **kwargs
):
"""
Create a new entry in the active courses index which points to an existing or new structure. Returns
......@@ -1858,13 +1858,14 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
locator = CourseLocator(org=org, course=course, run=run, branch=master_branch)
return self._create_courselike(
locator, user_id, master_branch, fields, versions_dict,
search_targets, root_category, root_block_id, **kwargs
search_targets, root_category, root_block_id, emit_signals=emit_signals,
**kwargs
)
def _create_courselike(
self, locator, user_id, master_branch, fields=None,
versions_dict=None, search_targets=None, root_category='course',
root_block_id=None, **kwargs
root_block_id=None, emit_signals=True, **kwargs
):
"""
Internal code for creating a course or library
......@@ -1928,7 +1929,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
draft_structure = self._lookup_course(draft_version).structure
locator = locator.replace(version_guid=new_id)
with self.bulk_operations(locator):
with self.bulk_operations(locator, emit_signals=emit_signals):
self.update_structure(locator, draft_structure)
index_entry = {
'_id': ObjectId(),
......
......@@ -19,7 +19,7 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
A subclass of Split that supports a dual-branch fall-back versioning framework
with a Draft branch that falls back to a Published branch.
"""
def create_course(self, org, course, run, user_id, skip_auto_publish=False, **kwargs):
def create_course(self, org, course, run, user_id, skip_auto_publish=False, emit_signals=True, **kwargs):
"""
Creates and returns the course.
......@@ -33,7 +33,8 @@ class DraftVersioningModuleStore(SplitMongoModuleStore, ModuleStoreDraftAndPubli
Returns: a CourseDescriptor
"""
master_branch = kwargs.pop('master_branch', ModuleStoreEnum.BranchName.draft)
with self.bulk_operations(CourseLocator(org, course, run)):
with self.bulk_operations(CourseLocator(org, course, run), emit_signals=emit_signals):
item = super(DraftVersioningModuleStore, self).create_course(
org, course, run, user_id, master_branch=master_branch, **kwargs
)
......
......@@ -129,9 +129,13 @@ class CourseFactory(XModuleFactory):
with store.bulk_operations(course_key, emit_signals=emit_signals):
if default_store_override is not None:
with store.default_store(default_store_override):
new_course = store.create_course(org, number, run, user_id, fields=kwargs)
new_course = store.create_course(
org, number, run, user_id, emit_signals=emit_signals, fields=kwargs
)
else:
new_course = store.create_course(org, number, run, user_id, fields=kwargs)
new_course = store.create_course(
org, number, run, user_id, emit_signals=emit_signals, fields=kwargs
)
last_course.loc = new_course.location
return new_course
......
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