コード例 #1
0
 def test_map_into_course_location(self):
     loc = Location('org', 'course', 'run', 'cat', 'name:more_name', 'rev')
     course_key = SlashSeparatedCourseKey("edX", "toy", "2012_Fall")
     self.assertEquals(
         Location("edX", "toy", "2012_Fall", 'cat', 'name:more_name', 'rev'),
         loc.map_into_course(course_key)
     )
コード例 #2
0
    def test_replacement(self):
        # pylint: disable=protected-access

        self.assertEquals(
            Location('o', 'c', 'r', 'c', 'n', 'r').replace(name='new_name'),
            Location('o', 'c', 'r', 'c', 'new_name', 'r'),
        )

        with self.assertRaises(InvalidKeyError):
            Location('o', 'c', 'r', 'c', 'n', 'r').replace(name=u'name\xae')
コード例 #3
0
    def test_equality(self):
        self.assertEquals(
            Location('tag', 'org', 'course', 'run', 'category', 'name'),
            Location('tag', 'org', 'course', 'run', 'category', 'name')
        )

        self.assertNotEquals(
            Location('tag', 'org', 'course', 'run', 'category', 'name1'),
            Location('tag', 'org', 'course', 'run', 'category', 'name')
        )
コード例 #4
0
    def _create(cls, target_class, **kwargs):

        # All class attributes (from this class and base classes) are
        # passed in via **kwargs. However, some of those aren't actual field values,
        # so pop those off for use separately
        org = kwargs.pop('org', None)
        # because the factory provides a default 'number' arg, prefer the non-defaulted 'course' arg if any
        number = kwargs.pop('course', kwargs.pop('number', None))
        store = kwargs.pop('modulestore')
        name = kwargs.get(
            'name',
            kwargs.get('run', Location.clean(kwargs.get('display_name'))))
        run = kwargs.get('run', name)

        location = Location(org, number, run, 'course', name)

        # Write the data to the mongo datastore
        new_course = store.create_xmodule(location,
                                          metadata=kwargs.get(
                                              'metadata', None))

        # The rest of kwargs become attributes on the course:
        for k, v in kwargs.iteritems():
            setattr(new_course, k, v)

        # Save the attributes we just set
        new_course.save()
        # Update the data in the mongo datastore
        store.update_item(new_course)
        return new_course
コード例 #5
0
 def test_valid_locations(self, args, kwargs, org, course, run, category, name, revision):
     location = Location(*args, **kwargs)
     self.assertEquals(org, location.org)
     self.assertEquals(course, location.course)
     self.assertEquals(run, location.run)
     self.assertEquals(category, location.category)
     self.assertEquals(name, location.name)
     self.assertEquals(revision, location.revision)
コード例 #6
0
 def setUp(self):
     field_data = Mock(spec=FieldData)
     self.descriptor = BrokenDescriptor(
         TestRuntime(Mock(spec=IdReader), field_data), field_data,
         ScopeIds(None, None, None,
                  Location('org', 'course', 'run', 'broken', 'name', None)))
     self.descriptor.xmodule_runtime = TestRuntime(Mock(spec=IdReader),
                                                   field_data)
     self.descriptor.xmodule_runtime.error_descriptor_class = ErrorDescriptor
     self.descriptor.xmodule_runtime.xmodule_instance = None
コード例 #7
0
 def test___find_corresponding_module_for_location_exceptions(self):
     """
     Unit test for the exception cases of __find_corresponding_module_for_location
     Mainly for diff coverage
     @return:
     """
     # pylint: disable=protected-access
     with self.assertRaises(ItemNotFoundError):
         self.peer_grading._find_corresponding_module_for_location(
             Location('org', 'course', 'run', 'category', 'name',
                      'revision'))
コード例 #8
0
    def parent_location(self):
        default_location = Location('MITx', '999', 'Robot_Super_Course',
                                    'course', 'Robot_Super_Course', None)
        try:
            parent = self.parent
        # This error is raised if the caller hasn't provided either parent or parent_location
        # In this case, we'll just return the default parent_location
        except CyclicDefinitionError:
            return default_location

        if parent is None:
            return default_location

        return parent.location
コード例 #9
0
ファイル: test_item.py プロジェクト: uncletomiwa/edx-platform
    def setUp(self):
        self.request_factory = RequestFactory()

        patcher = patch('contentstore.views.component.get_modulestore')
        self.get_modulestore = patcher.start()
        self.addCleanup(patcher.stop)

        self.descriptor = self.get_modulestore.return_value.get_item.return_value

        self.usage_key_string = unicode(
            Location('dummy_org', 'dummy_course', 'dummy_run',
                     'dummy_category', 'dummy_name'))

        self.user = UserFactory()

        self.request = self.request_factory.get('/dummy-url')
        self.request.user = self.user
コード例 #10
0
    def setUp(self):
        super(TabsEditingDescriptorTestCase, self).setUp()
        system = get_test_descriptor_system()
        system.render_template = Mock(
            return_value="<div>Test Template HTML</div>")
        self.tabs = [{
            'name': "Test_css",
            'template': "tabs/codemirror-edit.html",
            'current': True,
            'css': {
                'scss': [
                    resource_string(
                        __name__,
                        '../../test_files/test_tabseditingdescriptor.scss')
                ],
                'css': [
                    resource_string(
                        __name__,
                        '../../test_files/test_tabseditingdescriptor.css')
                ]
            }
        }, {
            'name': "Subtitles",
            'template': "video/subtitles.html",
        }, {
            'name': "Settings",
            'template': "tabs/video-metadata-edit-tab.html"
        }]

        TabsEditingDescriptor.tabs = self.tabs
        self.descriptor = system.construct_xblock_from_class(
            TabsEditingDescriptor,
            scope_ids=ScopeIds(
                None, None, None,
                Location('org', 'course', 'run', 'category', 'name',
                         'revision')),
            field_data=DictFieldData({}),
        )
コード例 #11
0
 def test_immutable(self, attr):
     loc = Location('o', 'c', 'r', 'c', 'n', 'r')
     with self.assertRaises(AttributeError):
         setattr(loc, attr, attr)
コード例 #12
0
 def test_html_id(self):
     loc = Location('org', 'course', 'run', 'cat', 'name:more_name', 'rev')
     self.assertEquals(loc.html_id(), "i4x-org-course-cat-name_more_name-rev")
コード例 #13
0
 def test_invalid_locations(self, *args, **kwargs):
     with self.assertRaises(TypeError):
         Location(*args, **kwargs)
コード例 #14
0
    def create(system, source_is_error_module=False):
        """
        return a dict of modules: the conditional with a single source and a single child.
        Keys are 'cond_module', 'source_module', and 'child_module'.

        if the source_is_error_module flag is set, create a real ErrorModule for the source.
        """
        descriptor_system = get_test_descriptor_system()

        # construct source descriptor and module:
        source_location = Location("edX", "conditional_test", "test_run",
                                   "problem", "SampleProblem", None)
        if source_is_error_module:
            # Make an error descriptor and module
            source_descriptor = NonStaffErrorDescriptor.from_xml(
                'some random xml data',
                system,
                id_generator=CourseLocationGenerator(
                    SlashSeparatedCourseKey('edX', 'conditional_test',
                                            'test_run')),
                error_msg='random error message')
        else:
            source_descriptor = Mock()
            source_descriptor.location = source_location

        source_descriptor.runtime = descriptor_system
        source_descriptor.render = lambda view, context=None: descriptor_system.render(
            source_descriptor, view, context)

        # construct other descriptors:
        child_descriptor = Mock()
        child_descriptor._xmodule.student_view.return_value.content = u'<p>This is a secret</p>'
        child_descriptor.student_view = child_descriptor._xmodule.student_view
        child_descriptor.displayable_items.return_value = [child_descriptor]
        child_descriptor.runtime = descriptor_system
        child_descriptor.xmodule_runtime = get_test_system()
        child_descriptor.render = lambda view, context=None: descriptor_system.render(
            child_descriptor, view, context)
        child_descriptor.location = source_location.replace(category='html',
                                                            name='child')

        descriptor_system.load_item = {
            child_descriptor.location: child_descriptor,
            source_location: source_descriptor
        }.get

        # construct conditional module:
        cond_location = Location("edX", "conditional_test", "test_run",
                                 "conditional", "SampleConditional", None)
        field_data = DictFieldData({
            'data': '<conditional/>',
            'xml_attributes': {
                'attempted': 'true'
            },
            'children': [child_descriptor.location],
        })

        cond_descriptor = ConditionalDescriptor(
            descriptor_system, field_data,
            ScopeIds(None, None, cond_location, cond_location))
        cond_descriptor.xmodule_runtime = system
        system.get_module = lambda desc: desc
        cond_descriptor.get_required_module_descriptors = Mock(
            return_value=[source_descriptor])

        # return dict:
        return {
            'cond_module': cond_descriptor,
            'source_module': source_descriptor,
            'child_module': child_descriptor
        }
コード例 #15
0
    def test_conditional_module(self):
        """Make sure that conditional module works"""

        print "Starting import"
        course = self.get_course('conditional_and_poll')

        print "Course: ", course
        print "id: ", course.id

        def inner_get_module(descriptor):
            if isinstance(descriptor, Location):
                location = descriptor
                descriptor = self.modulestore.get_item(location, depth=None)
            descriptor.xmodule_runtime = get_test_system()
            descriptor.xmodule_runtime.get_module = inner_get_module
            return descriptor

        # edx - HarvardX
        # cond_test - ER22x
        location = Location("HarvardX", "ER22x", "2013_Spring", "conditional",
                            "condone")

        def replace_urls(text,
                         staticfiles_prefix=None,
                         replace_prefix='/static/',
                         course_namespace=None):
            return text

        self.test_system.replace_urls = replace_urls
        self.test_system.get_module = inner_get_module

        module = inner_get_module(location)
        print "module: ", module
        print "module children: ", module.get_children()
        print "module display items (children): ", module.get_display_items()

        html = module.render('student_view').content
        print "html type: ", type(html)
        print "html: ", html
        html_expect = module.xmodule_runtime.render_template(
            'conditional_ajax.html',
            {
                # Test ajax url is just usage-id / handler_name
                'ajax_url':
                '{}/xmodule_handler'.format(location.to_deprecated_string()),
                'element_id':
                u'i4x-HarvardX-ER22x-conditional-condone',
                'depends':
                u'i4x-HarvardX-ER22x-problem-choiceprob'
            })
        self.assertEqual(html, html_expect)

        gdi = module.get_display_items()
        print "gdi=", gdi

        ajax = json.loads(module.handle_ajax('', ''))
        module.save()
        print "ajax: ", ajax
        html = ajax['html']
        self.assertFalse(any(['This is a secret' in item for item in html]))

        # Now change state of the capa problem to make it completed
        inner_module = inner_get_module(
            location.replace(category="problem", name='choiceprob'))
        inner_module.attempts = 1
        # Save our modifications to the underlying KeyValueStore so they can be persisted
        inner_module.save()

        ajax = json.loads(module.handle_ajax('', ''))
        module.save()
        print "post-attempt ajax: ", ajax
        html = ajax['html']
        self.assertTrue(any(['This is a secret' in item for item in html]))