Ejemplo n.º 1
0
 def test_get_non_existant_course(self):
     """
     Test non-existant course returns empty list.
     """
     assert get_course_chapter_ids(None) == []
     # build a fake key
     fake_course_key = CourseKey.from_string('course-v1:FakeOrg+CN1+CR-FALLNEVER1')
     assert get_course_chapter_ids(fake_course_key) == []
Ejemplo n.º 2
0
    def setUp(self):
        """
        Set up tests
        """
        super().setUp()
        # add some info about the course for easy access
        self.master_course_key = self.course.location.course_key
        self.master_course_key_str = str(self.master_course_key)
        # OAUTH2 setup
        # create a specific user for the application
        self.app_user = app_user = UserFactory(
            username='******',
            email='*****@*****.**',
            password=USER_PASSWORD
        )

        # add staff role to the app user
        CourseStaffRole(self.master_course_key).add_users(app_user)

        # adding instructor to master course.
        instructor = UserFactory()
        allow_access(self.course, instructor, 'instructor')

        self.auth = self.prepare_auth_token(app_user)

        self.course.enable_ccx = True
        self.mstore.update_item(self.course, self.coach.id)
        # making the master course chapters easily available
        self.master_course_chapters = courses.get_course_chapter_ids(self.master_course_key)
Ejemplo n.º 3
0
 def test_get_chapters(self):
     """
     Test get_course_chapter_ids returns expected result.
     """
     course = CourseFactory()
     ItemFactory(parent=course, category='chapter')
     ItemFactory(parent=course, category='chapter')
     course_chapter_ids = get_course_chapter_ids(course.location.course_key)
     assert len(course_chapter_ids) == 2
     assert course_chapter_ids == [str(child) for child in course.children]
Ejemplo n.º 4
0
 def test_get_chapters(self):
     """
     Test get_course_chapter_ids returns expected result.
     """
     course = CourseFactory()
     ItemFactory(parent=course, category='chapter')
     ItemFactory(parent=course, category='chapter')
     course_chapter_ids = get_course_chapter_ids(course.location.course_key)
     self.assertEqual(len(course_chapter_ids), 2)
     self.assertEqual(course_chapter_ids,
                      [six.text_type(child) for child in course.children])
Ejemplo n.º 5
0
def valid_course_modules(course_module_list, master_course_key):
    """
    Function to validate that each element in the course_module_list belongs
    to the master course structure.
    Args:
        course_module_list (list): A list of strings representing Block Usage Keys
        master_course_key (CourseKey): An object representing the master course key id

    Returns:
        bool: whether or not all the course module strings belong to the master course
    """
    course_chapters = courses.get_course_chapter_ids(master_course_key)
    return set(course_module_list).intersection(set(course_chapters)) == set(course_module_list)