def build(self, contentstore): """ A contextmanager that returns an isolated mongo modulestore, and then deletes all of its data at the end of the context. Args: contentstore: The contentstore that this modulestore should use to store all of its assets. """ doc_store_config = dict( db='modulestore{}'.format(random.randint(0, 10000)), collection='xmodule', **COMMON_DOCSTORE_CONFIG ) # Set up a temp directory for storing filesystem content created during import fs_root = mkdtemp() modulestore = DraftModuleStore( contentstore, doc_store_config, fs_root, render_template=repr, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred, metadata_inheritance_cache_subsystem=MemoryCache(), ) try: yield modulestore finally: # Delete the created database modulestore._drop_database() # Delete the created directory on the filesystem rmtree(fs_root)
def build(self, contentstore): """ A contextmanager that returns an isolated mongo modulestore, and then deletes all of its data at the end of the context. Args: contentstore: The contentstore that this modulestore should use to store all of its assets. """ doc_store_config = dict(db='modulestore{}'.format( random.randint(0, 10000)), collection='xmodule', **COMMON_DOCSTORE_CONFIG) # Set up a temp directory for storing filesystem content created during import fs_root = mkdtemp() modulestore = DraftModuleStore( contentstore, doc_store_config, fs_root, render_template=repr, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred, metadata_inheritance_cache_subsystem=MemoryCache(), ) try: yield modulestore finally: # Delete the created database modulestore._drop_database() # Delete the created directory on the filesystem rmtree(fs_root, ignore_errors=True)
class MongoModulestoreBuilder(object): """ A builder class for a DraftModuleStore. """ @contextmanager def build(self, contentstore): """ A contextmanager that returns an isolated mongo modulestore, and then deletes all of its data at the end of the context. Args: contentstore: The contentstore that this modulestore should use to store all of its assets. """ doc_store_config = dict( db='modulestore{}'.format(random.randint(0, 10000)), collection='xmodule', asset_collection='asset_metadata', **COMMON_DOCSTORE_CONFIG ) # Set up a temp directory for storing filesystem content created during import fs_root = mkdtemp() # pylint: disable=attribute-defined-outside-init self.modulestore = DraftModuleStore( contentstore, doc_store_config, fs_root, render_template=repr, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred, metadata_inheritance_cache_subsystem=MemoryCache(), xblock_mixins=XBLOCK_MIXINS, ) self.modulestore.ensure_indexes() try: yield self.modulestore finally: # Delete the created database self.modulestore._drop_database() # pylint: disable=protected-access # Delete the created directory on the filesystem rmtree(fs_root, ignore_errors=True) def __repr__(self): return 'MongoModulestoreBuilder()' def asset_collection(self): """ Returns the collection storing the asset metadata. """ return self.modulestore.asset_collection
def setUp(self): super(TestMigration, self).setUp() self.loc_mapper = LocMapperStore(**self.db_config) self.old_mongo = MongoModuleStore(**self.modulestore_options) self.draft_mongo = DraftModuleStore(**self.modulestore_options) self.split_mongo = SplitMongoModuleStore( loc_mapper=self.loc_mapper, **self.modulestore_options ) self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper) self.course_location = None self.create_source_course()
def build_with_contentstore(self, contentstore, **kwargs): """ A contextmanager that returns an isolated mongo modulestore, and then deletes all of its data at the end of the context. Args: contentstore: The contentstore that this modulestore should use to store all of its assets. """ doc_store_config = dict( db='modulestore{}'.format(THIS_UUID), collection='xmodule', asset_collection='asset_metadata', **COMMON_DOCSTORE_CONFIG ) # Set up a temp directory for storing filesystem content created during import fs_root = mkdtemp() modulestore = DraftModuleStore( contentstore, doc_store_config, fs_root, render_template=repr, branch_setting_func=lambda: ModuleStoreEnum.Branch.draft_preferred, metadata_inheritance_cache_subsystem=MemoryCache(), xblock_mixins=XBLOCK_MIXINS, ) modulestore.ensure_indexes() try: yield modulestore finally: # Delete the created database modulestore._drop_database() # pylint: disable=protected-access # Delete the created directory on the filesystem rmtree(fs_root, ignore_errors=True)
def setUp(self): super(TestMigration, self).setUp() # pylint: disable=W0142 self.loc_mapper = LocMapperStore(test_location_mapper.TrivialCache(), **self.db_config) self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options) self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options) self.split_mongo = SplitMongoModuleStore( doc_store_config=self.db_config, loc_mapper=self.loc_mapper, **self.modulestore_options) self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper) self.course_location = None self.create_source_course()
def setUp(self): super(TestMigration, self).setUp() noop_cache = mock.Mock(spec=['get', 'set_many']) noop_cache.configure_mock(**{'get.return_value': None}) # pylint: disable=W0142 self.loc_mapper = LocMapperStore(noop_cache, **self.db_config) self.old_mongo = MongoModuleStore(self.db_config, **self.modulestore_options) self.draft_mongo = DraftModuleStore(self.db_config, **self.modulestore_options) self.split_mongo = SplitMongoModuleStore( doc_store_config=self.db_config, loc_mapper=self.loc_mapper, **self.modulestore_options) self.migrator = SplitMigrator(self.split_mongo, self.old_mongo, self.draft_mongo, self.loc_mapper) self.course_location = None self.create_source_course()