def test_loading_tagged_classes(): @XBlock.tag("thetag") class HasTag1(XBlock): """Toy XBlock""" class HasTag2(HasTag1): """Toy XBlock""" class HasntTag(XBlock): """Toy XBlock""" the_classes = [('hastag1', HasTag1), ('hastag2', HasTag2), ('hasnttag', HasntTag)] tagged_classes = [('hastag1', HasTag1), ('hastag2', HasTag2)] with patch('xblock.core.XBlock.load_classes', return_value=the_classes): assert set(XBlock.load_tagged_classes('thetag')) == set(tagged_classes)
def get_orphans(self, course_location, _branch): """ Return an array all of the locations for orphans in the course. """ detached_categories = [name for name, __ in XBlock.load_tagged_classes("detached")] all_items = self.collection.find({ '_id.org': course_location.org, '_id.course': course_location.course, '_id.category': {'$nin': detached_categories} }) all_reachable = set() item_locs = set() for item in all_items: if item['_id']['category'] != 'course': item_locs.add(Location(item['_id']).replace(revision=None).url()) all_reachable = all_reachable.union(item.get('definition', {}).get('children', [])) item_locs -= all_reachable return list(item_locs)
def get_orphans(self, course_key): """ Return an array of all of the locations (deprecated string format) for orphans in the course. """ course_key = self.fill_in_run(course_key) detached_categories = [name for name, __ in XBlock.load_tagged_classes("detached")] query = self._course_key_to_son(course_key) query["_id.category"] = {"$nin": detached_categories} all_items = self.collection.find(query) all_reachable = set() item_locs = set() for item in all_items: if item["_id"]["category"] != "course": # It would be nice to change this method to return UsageKeys instead of the deprecated string. item_locs.add( as_published(Location._from_deprecated_son(item["_id"], course_key.run)).to_deprecated_string() ) all_reachable = all_reachable.union(item.get("definition", {}).get("children", []))
def get_orphans(self, course_location, _branch): """ Return an array all of the locations for orphans in the course. """ detached_categories = [name for name, __ in XBlock.load_tagged_classes("detached")] all_items = self.collection.find({ '_id.org': course_location.org, '_id.course': course_location.course, '_id.category': {'$nin': detached_categories} }) all_reachable = set() item_locs = set() for item in all_items: if item['_id']['category'] != 'course': item_locs.add(Location(item['_id']).replace(revision=None).url()) all_reachable = all_reachable.union(item.get('definition', {}).get('children', [])) item_locs -= all_reachable return list(item_locs)
def get_orphans(self, course_key): """ Return an array all of the locations (deprecated string format) for orphans in the course. """ detached_categories = [name for name, __ in XBlock.load_tagged_classes("detached")] query = self._course_key_to_son(course_key) query['_id.category'] = {'$nin': detached_categories} all_items = self.collection.find(query) all_reachable = set() item_locs = set() for item in all_items: if item['_id']['category'] != 'course': # It would be nice to change this method to return UsageKeys instead of the deprecated string. item_locs.add( Location._from_deprecated_son(item['_id'], course_key.run).replace(revision=None).to_deprecated_string() ) all_reachable = all_reachable.union(item.get('definition', {}).get('children', [])) item_locs -= all_reachable return list(item_locs)
def test_loading_tagged_classes(): @XBlock.tag("thetag") class HasTag1(XBlock): """Toy XBlock""" pass class HasTag2(HasTag1): """Toy XBlock""" pass class HasntTag(XBlock): """Toy XBlock""" pass the_classes = [('hastag1', HasTag1), ('hastag2', HasTag2), ('hasnttag', HasntTag)] tagged_classes = [('hastag1', HasTag1), ('hastag2', HasTag2)] with patch('xblock.core.XBlock.load_classes', return_value=the_classes): assert_equals(set(XBlock.load_tagged_classes('thetag')), set(tagged_classes))
def get_orphans(self, course_key): """ Return an array all of the locations (deprecated string format) for orphans in the course. """ detached_categories = [name for name, __ in XBlock.load_tagged_classes("detached")] query = self._course_key_to_son(course_key) query['_id.category'] = {'$nin': detached_categories} all_items = self.collection.find(query) all_reachable = set() item_locs = set() for item in all_items: if item['_id']['category'] != 'course': # It would be nice to change this method to return UsageKeys instead of the deprecated string. item_locs.add( Location._from_deprecated_son(item['_id'], course_key.run).replace(revision=None).to_deprecated_string() ) all_reachable = all_reachable.union(item.get('definition', {}).get('children', [])) item_locs -= all_reachable return list(item_locs)
import ddt from mock import patch from xblock.core import XBlock, XBlockAside from xblock.fields import Scope, String from xblock.runtime import DictKeyValueStore, KvsFieldData from xblock.test.tools import TestRuntime from xmodule.course_module import CourseSummary from xmodule.modulestore import ModuleStoreEnum from xmodule.modulestore.draft_and_published import DIRECT_ONLY_CATEGORIES from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.utils import SPLIT_MODULESTORE_SETUP, MongoModulestoreBuilder, PureModulestoreTestCase DETACHED_BLOCK_TYPES = dict(XBlock.load_tagged_classes('detached')) # These tests won't work with courses, since they're creating blocks inside courses TESTABLE_BLOCK_TYPES = set(DIRECT_ONLY_CATEGORIES) TESTABLE_BLOCK_TYPES.discard('course') TestField = namedtuple('TestField', ['field_name', 'initial', 'updated']) class AsideTest(XBlockAside): """ Test xblock aside class """ content = String(default="content", scope=Scope.content)
import re import logging from collections import namedtuple import uuid from xblock.core import XBlock DETACHED_XBLOCK_TYPES = set( name for name, __ in XBlock.load_tagged_classes("detached")) def _prefix_only_url_replace_regex(pattern): """ Match urls in quotes pulling out the fields from pattern """ return re.compile(u""" (?x) # flags=re.VERBOSE (?P<quote>\\\\?['"]) # the opening quotes {} (?P=quote) # the first matching closing quote """.format(pattern)) def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ rewrite any non-portable links to (->) relative links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ def portable_asset_link_subtitution(match): quote = match.group('quote')
import re import logging from collections import namedtuple import uuid from xblock.core import XBlock DETACHED_XBLOCK_TYPES = set(name for name, __ in XBlock.load_tagged_classes("detached")) def _prefix_only_url_replace_regex(pattern): """ Match urls in quotes pulling out the fields from pattern """ return re.compile(ur""" (?x) # flags=re.VERBOSE (?P<quote>\\?['"]) # the opening quotes {} (?P=quote) # the first matching closing quote """.format(pattern)) def rewrite_nonportable_content_links(source_course_id, dest_course_id, text): """ rewrite any non-portable links to (->) relative links: /c4x/<org>/<course>/asset/<name> -> /static/<name> /jump_to/i4x://<org>/<course>/<category>/<name> -> /jump_to_id/<id> """ def portable_asset_link_subtitution(match): quote = match.group('quote')