def test_course_structure_to_assignments(self):
        factory = CourseStructureFactory()
        structure = factory.structure

        actual = CourseStructure.course_structure_to_assignments(structure, graded=True)
        expected = self._prepare_structure(structure, factory.assignments)
        self.assertListEqual(actual, expected)

        # Test for assignment type filtering
        assignment_type = factory.grading_policy[0]['assignment_type']
        actual = CourseStructure.course_structure_to_assignments(structure, graded=True,
                                                                 assignment_type=assignment_type)
        assignments = [assignment for assignment in factory.assignments if assignment['format'] == assignment_type]
        expected = self._prepare_structure(structure, assignments)
        self.assertListEqual(actual, expected)
 def _get_sections(self):
     blocks = self.course_api_client.blocks().get()
     sections = CourseStructure.course_structure_to_sections(blocks, 'problem', graded=False)
     problems = self._get_problems_dict()
     for section in sections:
         self._build_submissions(section['children'], problems)
     return self._build_submissions(sections, problems)
    def _get_assignments(self, assignment_type=None):
        structure = self.course_api_client.course_structures(self.page.course_id).get()
        assignments = CourseStructure.course_structure_to_assignments(
            structure, graded=True, assignment_type=assignment_type
        )

        return self._build_submissions(assignments, self._get_problems_dict())
Пример #4
0
    def assignments(self, assignment_type=None):
        """ Returns the assignments (and problems) for the represented course. """

        assignment_type_name = None if assignment_type is None else assignment_type['name']
        assignment_type_key = self.get_cache_key(u'assignments_{}'.format(assignment_type_name))
        assignments = cache.get(assignment_type_key)

        if not assignments:
            all_assignments_key = self.get_cache_key(u'assignments')
            assignments = cache.get(all_assignments_key)

            if not assignments:
                structure = self._get_structure()
                assignments = CourseStructure.course_structure_to_assignments(
                    structure, graded=True, assignment_type=None)
                cache.set(all_assignments_key, assignments)

            if assignment_type:
                assignment_type['name'] = assignment_type['name'].lower()
                assignments = [assignment for assignment in assignments if
                               assignment['assignment_type'].lower() == assignment_type['name']]

            self.add_child_data_to_parent_blocks(assignments, self._build_graded_answer_distribution_url)
            self.attach_data_to_parents(assignments, self._build_assignment_url)

            # Cache the data for the course-assignment_type combination.
            cache.set(assignment_type_key, assignments)

        return assignments
    def assignments(self, assignment_type=None):
        """ Returns the assignments (and problems) for the represented course. """

        assignment_type_name = None if assignment_type is None else assignment_type['name']
        assignment_type_key = self.get_cache_key(u'assignments_{}'.format(assignment_type_name))
        assignments = cache.get(assignment_type_key)

        if not assignments:
            all_assignments_key = self.get_cache_key(u'assignments')
            assignments = cache.get(all_assignments_key)

            if not assignments:
                structure = self._get_structure()
                assignments = CourseStructure.course_structure_to_assignments(
                    structure, graded=True, assignment_type=None)
                cache.set(all_assignments_key, assignments)

            if assignment_type:
                assignment_type['name'] = assignment_type['name'].lower()
                assignments = [assignment for assignment in assignments if
                               assignment['assignment_type'].lower() == assignment_type['name']]

            self.add_child_data_to_parent_blocks(assignments, self._build_graded_answer_distribution_url)
            self.attach_data_to_parents(assignments, self._build_assignment_url)

            # Cache the data for the course-assignment_type combination.
            cache.set(assignment_type_key, assignments)

        return assignments
 def _get_sections(self):
     structure = self.course_api_client.course_structures(self.page.course_id).get()
     sections = CourseStructure.course_structure_to_sections(structure, graded=False)
     problems = self._get_problems_dict()
     for section in sections:
         self._build_submissions(section['children'], problems)
     return self._build_submissions(sections, problems)
    def _ungraded_structure(self, section_id=None, subsection_id=None):
        section_type_key = self.get_cache_key(u'sections_{}_{}'.format(section_id, subsection_id))
        found_structure = cache.get(section_type_key)

        if not found_structure:
            all_sections_key = self.get_cache_key(u'sections')
            found_structure = cache.get(all_sections_key)

            if not found_structure:
                structure = self._structure()
                found_structure = CourseStructure.course_structure_to_sections(structure, graded=False)
                cache.set(all_sections_key, found_structure)

            for section in found_structure:
                self._add_submissions_and_part_ids(section['children'],
                                                   self._build_ungraded_answer_distribution_url_func(
                                                       section['id']))
                self._build_submission_collections(section['children'],
                                                   self._build_subsection_url_func(section['id']))

            self._build_submission_collections(found_structure, self._build_section_url)

            if found_structure:
                if section_id:
                    found_structure = [section for section in found_structure if section['id'] == section_id]

                if found_structure and subsection_id:
                    found_structure = \
                        [section for section in found_structure[0]['children'] if section['id'] == subsection_id]

            cache.set(section_type_key, found_structure)

        return found_structure
Пример #8
0
 def _get_sections(self):
     blocks = self.course_api_client.blocks().get()
     sections = CourseStructure.course_structure_to_sections(blocks, 'problem', graded=False)
     problems = self._get_problems_dict()
     for section in sections:
         self._build_submissions(section['children'], problems)
     return self._build_submissions(sections, problems)
    def _get_assignments(self, assignment_type=None):
        structure = self.course_api_client.course_structures(
            self.page.course_id).get()
        assignments = CourseStructure.course_structure_to_assignments(
            structure, graded=True, assignment_type=assignment_type)

        return self._build_submissions(assignments, self._get_problems_dict())
    def test_course_structure_to_sections(self):
        factory = CourseStructureFactory()
        structure = factory.structure

        actual = CourseStructure.course_structure_to_sections(structure, False)
        self.assertListEqual(
            actual, self._prepare_structure(structure, factory.sections,
                                            False))
Пример #11
0
 def _get_sections(self):
     structure = self.course_api_client.course_structures(
         self.page.course_id).get()
     sections = CourseStructure.course_structure_to_sections(structure,
                                                             graded=False)
     problems = self._get_problems_dict()
     for section in sections:
         self._build_submissions(section['children'], problems)
     return self._build_submissions(sections, problems)
    def test_course_structure_to_assignments(self):
        factory = CourseStructureFactory()
        structure = factory.structure

        actual = CourseStructure.course_structure_to_assignments(structure,
                                                                 graded=True)
        expected = self._prepare_structure(structure, factory.assignments)
        self.assertListEqual(actual, expected)

        # Test for assignment type filtering
        assignment_type = factory.grading_policy[0]['assignment_type']
        actual = CourseStructure.course_structure_to_assignments(
            structure, graded=True, assignment_type=assignment_type)
        assignments = [
            assignment for assignment in factory.assignments
            if assignment['format'] == assignment_type
        ]
        expected = self._prepare_structure(structure, assignments)
        self.assertListEqual(actual, expected)
    def course_structure(self, section_id=None, subsection_id=None):
        """
        Returns course structure from cache.  If structure isn't found, it is fetched from the
        course structure API.  If no arguments are provided, all sections and children are returned.
        If only section_id is provided, that section is returned.  If both section_id and
        subsection_id is provided, the structure for the subsection is returned.
        """
        if section_id is None and subsection_id is not None:
            raise ValueError(
                'section_id must be specified if subsection_id is specified.')

        structure_type_key = self.get_cache_key(
            self.section_type_template.format(section_id, subsection_id))
        found_structure = cache.get(structure_type_key)

        if not found_structure:
            all_sections_key = self.get_cache_key(self.all_sections_key)
            found_structure = cache.get(all_sections_key)

            if not found_structure:
                structure = self._get_structure()
                found_structure = CourseStructure.course_structure_to_sections(
                    structure,
                    self.module_type,
                    graded=self.module_graded_type)
                cache.set(all_sections_key, found_structure)

            for section in found_structure:
                self.add_child_data_to_parent_blocks(
                    section['children'],
                    self.build_module_url_func(section['id']))
                self.attach_data_to_parents(
                    section['children'],
                    self.build_subsection_url_func(section['id']))
                section['num_modules'] = sum(
                    child.get('num_modules', 0)
                    for child in section['children'])

            self.attach_data_to_parents(found_structure,
                                        self.build_section_url)

            if found_structure:
                if section_id:
                    found_structure = [
                        section for section in found_structure
                        if section['id'] == section_id
                    ]

                    if found_structure and subsection_id:
                        found_structure = \
                            [section for section in found_structure[0]['children'] if section['id'] == subsection_id]

            cache.set(structure_type_key, found_structure)

        return found_structure
    def course_structure(self, section_id=None, subsection_id=None):
        """
        Returns course structure from cache.  If structure isn't found, it is fetched from the
        course structure API.  If no arguments are provided, all sections and children are returned.
        If only section_id is provided, that section is returned.  If both section_id and
        subsection_id is provided, the structure for the subsection is returned.
        """
        if section_id is None and subsection_id is not None:
            raise ValueError('section_id must be specified if subsection_id is specified.')

        structure_type_key = self.get_cache_key(self.section_type_template.format(section_id, subsection_id))
        found_structure = cache.get(structure_type_key)

        if not found_structure:
            all_sections_key = self.get_cache_key(self.all_sections_key)
            found_structure = cache.get(all_sections_key)

            if not found_structure:
                structure = self._get_structure()
                found_structure = CourseStructure.course_structure_to_sections(structure, self.module_type,
                                                                               graded=self.module_graded_type)
                cache.set(all_sections_key, found_structure)

            for section in found_structure:
                self.add_child_data_to_parent_blocks(section['children'],
                                                     self.build_module_url_func(section['id']))
                self.attach_data_to_parents(section['children'],
                                            self.build_subsection_url_func(section['id']))
                section['num_modules'] = sum(child.get('num_modules', 0) for child in section['children'])

            self.attach_data_to_parents(found_structure, self.build_section_url)

            if found_structure:
                if section_id:
                    found_structure = [section for section in found_structure if section['id'] == section_id]

                    if found_structure and subsection_id:
                        found_structure = \
                            [section for section in found_structure[0]['children'] if section['id'] == subsection_id]

            cache.set(structure_type_key, found_structure)

        return found_structure
Пример #15
0
    def _ungraded_structure(self, section_id=None, subsection_id=None):
        section_type_key = self.get_cache_key(u'sections_{}_{}'.format(
            section_id, subsection_id))
        found_structure = cache.get(section_type_key)

        if not found_structure:
            all_sections_key = self.get_cache_key(u'sections')
            found_structure = cache.get(all_sections_key)

            if not found_structure:
                structure = self._structure()
                found_structure = CourseStructure.course_structure_to_sections(
                    structure, graded=False)
                cache.set(all_sections_key, found_structure)

            for section in found_structure:
                self._add_submissions_and_part_ids(
                    section['children'],
                    self._build_ungraded_answer_distribution_url_func(
                        section['id']))
                self._build_submission_collections(
                    section['children'],
                    self._build_subsection_url_func(section['id']))

            self._build_submission_collections(found_structure,
                                               self._build_section_url)

            if found_structure:
                if section_id:
                    found_structure = [
                        section for section in found_structure
                        if section['id'] == section_id
                    ]

                if found_structure and subsection_id:
                    found_structure = \
                        [section for section in found_structure[0]['children'] if section['id'] == subsection_id]

            cache.set(section_type_key, found_structure)

        return found_structure
 def _assignments(self, assignment_type=None):
     structure = self._structure()
     return CourseStructure.course_structure_to_assignments(structure, graded=True, assignment_type=assignment_type)
 def _assignments(self, assignment_type=None):
     structure = self._structure()
     return CourseStructure.course_structure_to_assignments(
         structure, graded=True, assignment_type=assignment_type)
    def test_course_structure_to_sections(self):
        factory = CourseStructureFactory()
        structure = factory.structure

        actual = CourseStructure.course_structure_to_sections(structure, False)
        self.assertListEqual(actual, self._prepare_structure(structure, factory.sections, False))