Example #1
0
def utility_bulksettings_handler(request, course_key_string):
    """
    Handler for bulk settings view requests in the utilities tool.
    Queries for all settings for a given section, subsection & xblocks.

    In order to reduce the amount of embedding of functions in the template,
    store section - subsection - units - problems as list of hashes
    """

    course_key = CourseKey.from_string(course_key_string)
    response_format = request.REQUEST.get('format', 'html')

    if response_format == 'html':
        if request.method == 'GET':

            # load data
            course = get_course_and_check_access(course_key, request.user, depth=3)

            # traverse into the course tree and extract problem settings information
            settings_data = BulkSettingsUtil.get_bulksettings_metadata(course)
            return render_to_response(
                'bulksettings.html',
                {
                    'context_course': course,
                    'settings_data': settings_data,
                    'setting_type_list_map': SETTING_TYPE_LIST_MAP,
                    'section_setting_map': SECTION_SETTING_MAP,
                    'subsection_setting_map': SUBSECTION_SETTING_MAP
                }
            )
Example #2
0
    def test_empty_course(self):
        """
        Test that the computed settings data is empty when the course is empty.
        """
        empty_course = CourseFactory.create(org="edx", number="999", display_name="test_course")

        computed_settings_data = BulkSettingsUtil.get_bulksettings_metadata(empty_course)
        self.assertEqual(len(computed_settings_data), 0, msg="empty course should contain no settings")
Example #3
0
 def test_empty_problem(self):
     """
     Test with no problems. If no unit holds any problems, the list should be empty.
     """
     empty_problem_course = CourseFactory.create(org="edx", number="999", display_name="no_problem_course")
     self.do_recursive_population(empty_problem_course, ["chapter", "sequential", "vertical"])
     computed_settings_data = BulkSettingsUtil.get_bulksettings_metadata(empty_problem_course)
     self.assertEqual(len(computed_settings_data), 0, msg="course with no problem should yield no bulksettings")
Example #4
0
    def test_bulksettings_data_correctness(self):
        """
        Test that the populated course settings correctly match the result
        from _get_bulksettings_metadata.

        _get_bulksettings_metatdata is from contentstore.views.utilities.bulksettings

        Since the test populated course only contains problems, assume that indices
        match between computed settings & block.children

        Populate self.course with 2 chapters, 4 sections, 8 verticals, 16 problems
        and for each node, put in random settings
        """
        self.populate_course_with_seed_data()
        course_module = self.store.get_items(self.course.id, category="course")[0]
        computed_settings_data = BulkSettingsUtil.get_bulksettings_metadata(course_module)

        num_sections = len(computed_settings_data)
        sections = course_module.get_children()

        """ Dive into the course hierarchy and check correct values."""

        """ Section Layer"""
        for index in range(num_sections):
            section = sections[index]
            computed_section_settings = computed_settings_data[index]
            self.assertTrue(self.do_values_match(self.SECTION_SETTING_TYPES, section, computed_section_settings))

            num_subsections = len(section.get_children())

            """ Subsection Layer """
            for index in range(num_subsections):
                subsection = section.get_children()[index]
                computed_subsection_settings = computed_section_settings["children"][index]

                self.assertTrue(
                    self.do_values_match(self.SUBSECTION_SETTING_TYPES, subsection, computed_subsection_settings)
                )

                num_units = len(subsection.get_children())

                """ Unit Layer """
                for index in range(num_units):
                    unit = subsection.get_children()[index]
                    num_components = len(unit.get_children())
                    computed_unit_settings = computed_subsection_settings["children"][index]

                    """ Component Layer (Problems)"""
                    for index in range(num_components):
                        component = unit.get_children()[index]
                        computed_component_settings = computed_unit_settings["children"][index]
                        self.assertTrue(
                            self.do_values_match(self.PROBLEM_SETTING_TYPES, component, computed_component_settings)
                        )