Esempio n. 1
0
    def test_template_cleanup(self):
        module_store = modulestore('direct')

        # insert a bogus template in the store
        bogus_template_location = Location('i4x', 'edx', 'templates', 'html',
                                           'bogus')
        source_template_location = Location('i4x', 'edx', 'templates', 'html',
                                            'Blank_HTML_Page')

        module_store.clone_item(source_template_location,
                                bogus_template_location)

        verify_create = module_store.get_item(bogus_template_location)
        self.assertIsNotNone(verify_create)

        # now run cleanup
        update_templates(modulestore('direct'))

        # now try to find dangling template, it should not be in DB any longer
        asserted = False
        try:
            verify_create = module_store.get_item(bogus_template_location)
        except ItemNotFoundError:
            asserted = True

        self.assertTrue(asserted)
    def test_template_cleanup(self):
        module_store = modulestore('direct')

        # insert a bogus template in the store
        bogus_template_location = Location(
            'i4x', 'edx', 'templates', 'html', 'bogus')
        source_template_location = Location(
            'i4x', 'edx', 'templates', 'html', 'Blank_HTML_Page')

        module_store.clone_item(
            source_template_location, bogus_template_location)

        verify_create = module_store.get_item(bogus_template_location)
        self.assertIsNotNone(verify_create)

        # now run cleanup
        update_templates(modulestore('direct'))

        # now try to find dangling template, it should not be in DB any longer
        asserted = False
        try:
            verify_create = module_store.get_item(bogus_template_location)
        except ItemNotFoundError:
            asserted = True

        self.assertTrue(asserted)
Esempio n. 3
0
 def initdb():
     # connect to the db
     store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS)
     # Explicitly list the courses to load (don't want the big one)
     courses = ['toy', 'simple']
     import_from_xml(store, DATA_DIR, courses)
     update_templates(store)
     return store
Esempio n. 4
0
def clear_courses():
    # Flush and initialize the module store
    # It needs the templates because it creates new records
    # by cloning from the template.
    # Note that if your test module gets in some weird state
    # (though it shouldn't), do this manually
    # from the bash shell to drop it:
    # $ mongo test_xmodule --eval "db.dropDatabase()"
    _MODULESTORES = {}
    modulestore().collection.drop()
    update_templates(modulestore('direct'))
Esempio n. 5
0
def clear_courses():
    # Flush and initialize the module store
    # It needs the templates because it creates new records
    # by cloning from the template.
    # Note that if your test module gets in some weird state
    # (though it shouldn't), do this manually
    # from the bash shell to drop it:
    # $ mongo test_xmodule --eval "db.dropDatabase()"
    _MODULESTORES = {}
    modulestore().collection.drop()
    update_templates(modulestore('direct'))
Esempio n. 6
0
    def load_templates_if_necessary():
        """
        Load templates into the direct modulestore only if they do not already exist.
        We need the templates, because they are copied to create
        XModules such as sections and problems.
        """
        modulestore = xmodule.modulestore.django.modulestore('direct')

        # Count the number of templates
        query = {"_id.course": "templates"}
        num_templates = modulestore.collection.find(query).count()

        if num_templates < 1:
            update_templates(modulestore)
Esempio n. 7
0
 def handle(self, *args, **options):
     update_templates(modulestore('direct'))