def build(self, contentstore):
        """
        A contextmanager that returns an isolated versioning 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.
        """
        # pylint: disable=unreachable
        doc_store_config = dict(
            db='modulestore{}'.format(random.randint(0, 10000)),
            collection='split_module',
            **COMMON_DOCSTORE_CONFIG
        )
        # Set up a temp directory for storing filesystem content created during import
        fs_root = mkdtemp()

        modulestore = DraftVersioningModuleStore(
            contentstore,
            doc_store_config,
            fs_root,
            render_template=repr,
            xblock_mixins=XBLOCK_MIXINS,
        )
        modulestore.ensure_indexes()

        try:
            yield modulestore
        finally:
            # Delete the created database
            modulestore._drop_database()

            # Delete the created directory on the filesystem
            rmtree(fs_root, ignore_errors=True)
    def build(self, contentstore):
        """
        A contextmanager that returns an isolated versioning 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.
        """
        # pylint: disable=unreachable
        doc_store_config = dict(db='modulestore{}'.format(
            random.randint(0, 10000)),
                                collection='split_module',
                                **COMMON_DOCSTORE_CONFIG)
        # Set up a temp directory for storing filesystem content created during import
        fs_root = mkdtemp()

        modulestore = DraftVersioningModuleStore(
            contentstore,
            doc_store_config,
            fs_root,
            render_template=repr,
        )

        try:
            yield modulestore
        finally:
            # Delete the created database
            modulestore._drop_database()

            # Delete the created directory on the filesystem
            rmtree(fs_root, ignore_errors=True)
예제 #3
0
    def setUp(self):
        super(TestDraftVersioningModuleStore, self).setUp()
        self.module_store = DraftVersioningModuleStore(
            contentstore=None,
            doc_store_config={
                'host': 'localhost',
                'db': 'test_xmodule',
                'collection': 'modulestore{0}'.format(uuid.uuid4().hex[:5]),
            },
            fs_root='',
            default_class='xmodule.raw_module.RawDescriptor',
            render_template=render_to_template_mock,
            xblock_mixins=(InheritanceMixin, XModuleMixin),
        )
        self.addCleanup(self.module_store._drop_database)

        SplitModuleTest.bootstrapDB(self.module_store)
    def build_with_contentstore(self, contentstore, **kwargs):
        """
        A contextmanager that returns an isolated versioning 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=f'modulestore{THIS_UUID}',
                                collection='split_module',
                                **COMMON_DOCSTORE_CONFIG)
        # Set up a temp directory for storing filesystem content created during import
        fs_root = mkdtemp()

        modulestore = DraftVersioningModuleStore(contentstore,
                                                 doc_store_config,
                                                 fs_root,
                                                 render_template=repr,
                                                 xblock_mixins=XBLOCK_MIXINS,
                                                 **kwargs)
        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)
예제 #5
0
class TestDraftVersioningModuleStore(unittest.TestCase):
    def setUp(self):
        super(TestDraftVersioningModuleStore, self).setUp()
        self.module_store = DraftVersioningModuleStore(
            contentstore=None,
            doc_store_config={
                'host': 'localhost',
                'db': 'test_xmodule',
                'collection': 'modulestore{0}'.format(uuid.uuid4().hex[:5]),
            },
            fs_root='',
            default_class='xmodule.raw_module.RawDescriptor',
            render_template=render_to_template_mock,
            xblock_mixins=(InheritanceMixin, XModuleMixin),
        )
        self.addCleanup(self.module_store._drop_database)

        SplitModuleTest.bootstrapDB(self.module_store)

    def test_has_changes(self):
        """
        Tests that has_changes() only returns true when changes are present
        """
        draft_course = CourseLocator(
            org='testx', course='GreekHero', run='run', branch=ModuleStoreEnum.BranchName.draft
        )
        head = draft_course.make_usage_key('course', 'head12345')
        dummy_user = ModuleStoreEnum.UserID.test

        # Not yet published, so changes are present
        self.assertTrue(self.module_store.has_changes(head))

        # Publish and verify that there are no unpublished changes
        self.module_store.publish(head, dummy_user)
        self.assertFalse(self.module_store.has_changes(head))

        # Change the course, then check that there now are changes
        course = self.module_store.get_item(head)
        course.show_calculator = not course.show_calculator
        self.module_store.update_item(course, dummy_user)
        self.assertTrue(self.module_store.has_changes(head))

        # Publish and verify again
        self.module_store.publish(head, dummy_user)
        self.assertFalse(self.module_store.has_changes(head))