def test_update_section(self, mock_update):
        mock_update.return_value = None
        canvas = Sections()

        canvas.update_section("999999", "New Name", "test-section-id")
        mock_update.assert_called_with(
            '/api/v1/sections/999999', {
                'course_section': {
                    'name': 'New Name',
                    'sis_section_id': 'test-section-id'
                }
            })
    def test_create_section(self, mock_create):
        mock_create.return_value = None
        canvas = Sections()

        canvas.create_section("123456", "Test Section", "test-section-id")
        mock_create.assert_called_with(
            '/api/v1/courses/123456/sections', {
                'course_section': {
                    'name': 'Test Section',
                    'sis_section_id': 'test-section-id'
                }
            })
    def test_sections_with_students(self):
        canvas = Sections()

        sections = canvas.get_sections_with_students_in_course_by_sis_id(
            '2013-spring-CSE-142-A')

        self.assertEquals(len(sections), 16, "Too few sections")

        n = 0
        for section in sections:
            n += len(section.students)

        self.assertEquals(n, 32, "Too few students")
Ejemplo n.º 4
0
def get_course_sections(course, user_id):
    sections = []
    canvas = Sections(as_user=user_id)
    for section in canvas.get_sections_in_course(course.course_id):
        if not valid_group_section(section.sis_section_id):
            sections.append({
                'id': section.section_id,
                'sis_id': section.sis_section_id,
                'name': section.name
            })

    if not len(sections):
        canvas_course = CanvasCourse(sis_course_id=course.sis_course_id)
        if canvas_course.is_academic_sis_id():
            raise MissingSectionException(
                'Adding users to this course not allowed')
        else:
            sections.append({'id': 0, 'sis_id': '', 'name': course.name})

    return sections
Ejemplo n.º 5
0
def get_sis_sections_for_course(course_sis_id):
    sis_sections = []
    try:
        for section in Sections().get_sections_in_course_by_sis_id(
                course_sis_id):
            try:
                valid_academic_section_sis_id(section.sis_section_id)
                sis_sections.append(section)
            except CoursePolicyException:
                pass
    except DataFailureException as err:
        if err.status != 404:
            raise
    return sis_sections
Ejemplo n.º 6
0
def get_section_by_sis_id(section_sis_id):
    return Sections().get_section_by_sis_id(section_sis_id)
Ejemplo n.º 7
0
def get_sections_in_course(course_id, user_id):
    return Sections(as_user=user_id).get_sections_in_course(course_id)