示例#1
0
 def test_library_metadata_override_default(self):
     """
     Checks that due date can be overriden at child level when a library is the root.
     """
     system = self.get_system()
     course_due = 'March 20 17:00'
     child_due = 'April 10 00:00'
     url_name = 'test1'
     start_xml = '''
     <library org="TestOrg" library="TestLib" display_name="stuff">
         <course org="{org}" course="{course}"
                 due="{due}" url_name="{url_name}" unicorn="purple">
             <chapter url="hi" url_name="ch" display_name="CH">
                 <html url_name="h" display_name="H">Two houses, ...</html>
             </chapter>
         </course>
     </library>'''.format(due=course_due,
                          org=ORG,
                          course=COURSE,
                          url_name=url_name)
     descriptor = system.process_xml(start_xml)
     LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
     # Chapter is two levels down here.
     child = descriptor.get_children()[0].get_children()[0]
     # pylint: disable=protected-access
     child._field_data.set(child, 'due', child_due)
     compute_inherited_metadata(descriptor)
     descriptor = descriptor.get_children()[0]
     self.override_metadata_check(descriptor, child, course_due, child_due)
示例#2
0
    def test_library_metadata_import_export(self):
        """Two checks:
            - unknown metadata is preserved across import-export
            - inherited metadata doesn't leak to children.
        """
        system = self.get_system(library=True)
        from_date_string = 'March 26 17:00'
        url_name = 'test2'
        unicorn_color = 'rainbow'
        start_xml = '''
        <library org="TestOrg" library="TestLib" display_name="stuff">
            <course org="{org}" course="{course}"
                due="{due}" url_name="{url_name}" unicorn="{unicorn_color}">
                <chapter url="hi" url_name="ch" display_name="CH">
                    <html url_name="h" display_name="H">Two houses, ...</html>
                </chapter>
            </course>
        </library>'''.format(due=from_date_string,
                             org=ORG,
                             course=COURSE,
                             url_name=url_name,
                             unicorn_color=unicorn_color)
        descriptor = system.process_xml(start_xml)

        # pylint: disable=protected-access
        original_unwrapped = descriptor._unwrapped_field_data
        LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
        # '_unwrapped_field_data' is reset in `patch_descriptor_kvs`
        # pylint: disable=protected-access
        self.assertIsNot(original_unwrapped, descriptor._unwrapped_field_data)
        compute_inherited_metadata(descriptor)
        # Check the course module, since it has inheritance
        descriptor = descriptor.get_children()[0]
        self.course_descriptor_inheritance_check(descriptor, from_date_string,
                                                 unicorn_color)
示例#3
0
 def test_library_metadata_override_default(self):
     """
     Checks that due date can be overriden at child level when a library is the root.
     """
     system = self.get_system()
     course_due = 'March 20 17:00'
     child_due = 'April 10 00:00'
     url_name = 'test1'
     start_xml = '''
     <library org="TestOrg" library="TestLib" display_name="stuff">
         <course org="{org}" course="{course}"
                 due="{due}" url_name="{url_name}" unicorn="purple">
             <chapter url="hi" url_name="ch" display_name="CH">
                 <html url_name="h" display_name="H">Two houses, ...</html>
             </chapter>
         </course>
     </library>'''.format(due=course_due, org=ORG, course=COURSE, url_name=url_name)
     descriptor = system.process_xml(start_xml)
     LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
     # Chapter is two levels down here.
     child = descriptor.get_children()[0].get_children()[0]
     # pylint: disable=protected-access
     child._field_data.set(child, 'due', child_due)
     compute_inherited_metadata(descriptor)
     descriptor = descriptor.get_children()[0]
     self.override_metadata_check(descriptor, child, course_due, child_due)
示例#4
0
    def test_library_metadata_import_export(self):
        """Two checks:
            - unknown metadata is preserved across import-export
            - inherited metadata doesn't leak to children.
        """
        system = self.get_system(library=True)
        from_date_string = 'March 26 17:00'
        url_name = 'test2'
        unicorn_color = 'rainbow'
        start_xml = '''
        <library org="TestOrg" library="TestLib" display_name="stuff">
            <course org="{org}" course="{course}"
                due="{due}" url_name="{url_name}" unicorn="{unicorn_color}">
                <chapter url="hi" url_name="ch" display_name="CH">
                    <html url_name="h" display_name="H">Two houses, ...</html>
                </chapter>
            </course>
        </library>'''.format(
            due=from_date_string, org=ORG, course=COURSE, url_name=url_name, unicorn_color=unicorn_color
        )
        descriptor = system.process_xml(start_xml)

        # pylint: disable=protected-access
        original_unwrapped = descriptor._unwrapped_field_data
        LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
        # '_unwrapped_field_data' is reset in `patch_descriptor_kvs`
        # pylint: disable=protected-access
        self.assertIsNot(original_unwrapped, descriptor._unwrapped_field_data)
        compute_inherited_metadata(descriptor)
        # Check the course module, since it has inheritance
        descriptor = descriptor.get_children()[0]
        self.course_descriptor_inheritance_check(descriptor, from_date_string, unicorn_color, url_name)
示例#5
0
 def test_library_metadata_no_inheritance(self):
     """
     Checks that the default value of None (for due) does not get marked as inherited when a
     library is the root block.
     """
     system = self.get_system()
     url_name = 'test1'
     start_xml = '''
     <library org="TestOrg" library="TestLib" display_name="stuff">
         <course org="{org}" course="{course}"
                 url_name="{url_name}" unicorn="purple">
             <chapter url="hi" url_name="ch" display_name="CH">
                 <html url_name="h" display_name="H">Two houses, ...</html>
             </chapter>
         </course>
     </library>'''.format(org=ORG, course=COURSE, url_name=url_name)
     descriptor = system.process_xml(start_xml)
     LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
     compute_inherited_metadata(descriptor)
     # Run the checks on the course node instead.
     descriptor = descriptor.get_children()[0]
     self.course_descriptor_no_inheritance_check(descriptor)
示例#6
0
 def test_library_metadata_no_inheritance(self):
     """
     Checks that the default value of None (for due) does not get marked as inherited when a
     library is the root block.
     """
     system = self.get_system()
     url_name = 'test1'
     start_xml = '''
     <library org="TestOrg" library="TestLib" display_name="stuff">
         <course org="{org}" course="{course}"
                 url_name="{url_name}" unicorn="purple">
             <chapter url="hi" url_name="ch" display_name="CH">
                 <html url_name="h" display_name="H">Two houses, ...</html>
             </chapter>
         </course>
     </library>'''.format(org=ORG, course=COURSE, url_name=url_name)
     descriptor = system.process_xml(start_xml)
     LibraryXMLModuleStore.patch_descriptor_kvs(descriptor)
     compute_inherited_metadata(descriptor)
     # Run the checks on the course node instead.
     descriptor = descriptor.get_children()[0]
     self.course_descriptor_no_inheritance_check(descriptor)
示例#7
0
    def __init__(self, load_error_modules, library=False):

        if library:
            xmlstore = LibraryXMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
        else:
            xmlstore = XMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
        course_id = SlashSeparatedCourseKey(ORG, COURSE, 'test_run')
        course_dir = "test_dir"
        error_tracker = Mock()

        super(DummySystem, self).__init__(
            xmlstore=xmlstore,
            course_id=course_id,
            course_dir=course_dir,
            error_tracker=error_tracker,
            load_error_modules=load_error_modules,
            mixins=(InheritanceMixin, XModuleMixin),
            field_data=KvsFieldData(DictKeyValueStore()),
        )
示例#8
0
    def __init__(self, load_error_modules, library=False):

        if library:
            xmlstore = LibraryXMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
        else:
            xmlstore = XMLModuleStore("data_dir", source_dirs=[], load_error_modules=load_error_modules)
        course_id = CourseKey.from_string('/'.join([ORG, COURSE, RUN]))
        course_dir = "test_dir"
        error_tracker = Mock()

        super(DummySystem, self).__init__(  # lint-amnesty, pylint: disable=super-with-arguments
            xmlstore=xmlstore,
            course_id=course_id,
            course_dir=course_dir,
            error_tracker=error_tracker,
            load_error_modules=load_error_modules,
            mixins=(InheritanceMixin, XModuleMixin),
            field_data=KvsFieldData(DictKeyValueStore()),
        )