예제 #1
0
 def test_get_structure_non_existing_key(self):
     """
     Test to get the course structure
     """
     self.assertEqual(utils.get_course_chapters(None), None)
     # build a fake key
     fake_course_key = CourseKey.from_string('course-v1:FakeOrg+CN1+CR-FALLNEVER1')
     self.assertEqual(utils.get_course_chapters(fake_course_key), None)
예제 #2
0
 def test_get_structure_non_existing_key(self):
     """
     Test to get the course structure
     """
     self.assertEqual(utils.get_course_chapters(None), None)
     # build a fake key
     fake_course_key = CourseKey.from_string(
         'course-v1:FakeOrg+CN1+CR-FALLNEVER1')
     self.assertEqual(utils.get_course_chapters(fake_course_key), None)
예제 #3
0
 def test_get_chapters(self):
     """
     Happy path
     """
     course_chapters = utils.get_course_chapters(self.course_key)
     self.assertEqual(len(course_chapters), 2)
     self.assertEqual(sorted(course_chapters), sorted([unicode(child) for child in self.course.children]))
예제 #4
0
 def setUp(self):
     """
     Set up tests
     """
     super(CcxRestApiTest, self).setUp()
     # add some info about the course for easy access
     self.master_course_key = self.course.location.course_key
     self.master_course_key_str = unicode(self.master_course_key)
     # OAUTH2 setup
     # create a specific user for the application
     app_user = User.objects.create_user('test_app_user', '*****@*****.**', 'test')
     # add staff role to the app user
     CourseStaffRole(self.master_course_key).add_users(app_user)
     # create an oauth client app entry
     self.app_client = Client.objects.create(
         user=app_user,
         name='test client',
         url='http://localhost//',
         redirect_uri='http://localhost//',
         client_type=CONFIDENTIAL
     )
     # create an authorization code
     self.app_grant = Grant.objects.create(
         user=app_user,
         client=self.app_client,
         redirect_uri='http://localhost//'
     )
     self.course.enable_ccx = True
     self.mstore.update_item(self.course, self.coach.id)
     self.auth = self.get_auth_token()
     # making the master course chapters easily available
     self.master_course_chapters = get_course_chapters(self.master_course_key)
예제 #5
0
 def setUp(self):
     """
     Set up tests
     """
     super(CcxRestApiTest, self).setUp()
     # add some info about the course for easy access
     self.master_course_key = self.course.location.course_key
     self.master_course_key_str = unicode(self.master_course_key)
     # OAUTH2 setup
     # create a specific user for the application
     app_user = User.objects.create_user("test_app_user", "*****@*****.**", "test")
     # add staff role to the app user
     CourseStaffRole(self.master_course_key).add_users(app_user)
     # create an oauth client app entry
     self.app_client = Client.objects.create(
         user=app_user,
         name="test client",
         url="http://localhost//",
         redirect_uri="http://localhost//",
         client_type=CONFIDENTIAL,
     )
     # create an authorization code
     self.app_grant = Grant.objects.create(user=app_user, client=self.app_client, redirect_uri="http://localhost//")
     self.course.enable_ccx = True
     self.mstore.update_item(self.course, self.coach.id)
     self.auth = self.get_auth_token()
     # making the master course chapters easily available
     self.master_course_chapters = get_course_chapters(self.master_course_key)
예제 #6
0
 def test_get_chapters(self):
     """
     Happy path
     """
     course_chapters = utils.get_course_chapters(self.course_key)
     self.assertEqual(len(course_chapters), 2)
     self.assertEqual(
         sorted(course_chapters),
         sorted([unicode(child) for child in self.course.children]))
예제 #7
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 = get_course_chapters(master_course_key)
    if course_chapters is None:
        return False
    return set(course_module_list).intersection(set(course_chapters)) == set(course_module_list)
예제 #8
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 = get_course_chapters(master_course_key)
    if course_chapters is None:
        return False
    return set(course_module_list).intersection(set(course_chapters)) == set(course_module_list)
예제 #9
0
    def setUp(self):
        """
        Set up tests
        """
        super(CcxRestApiTest, self).setUp()
        # add some info about the course for easy access
        self.master_course_key = self.course.location.course_key
        self.master_course_key_str = unicode(self.master_course_key)
        # OAUTH2 setup
        # create a specific user for the application
        app_user = UserFactory(username='******', email='*****@*****.**', 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')

        # create an oauth client app entry
        self.app_client = Client.objects.create(
            user=app_user,
            name='test client',
            url='http://localhost//',
            redirect_uri='http://localhost//',
            client_type=CONFIDENTIAL
        )
        # create an authorization code
        self.app_grant = Grant.objects.create(
            user=app_user,
            client=self.app_client,
            redirect_uri='http://localhost//'
        )
        self.course.enable_ccx = True
        self.mstore.update_item(self.course, self.coach.id)
        self.auth = self.get_auth_token()
        # making the master course chapters easily available
        self.master_course_chapters = get_course_chapters(self.master_course_key)
예제 #10
0
 def test_wrong_course_structure(self, mocked_attr):
     """
     Test the case where the course  has an unexpected structure.
     """
     mocked_attr.return_value = {'foo': 'bar'}
     self.assertEqual(utils.get_course_chapters(self.course_key), [])
예제 #11
0
 def test_wrong_course_structure(self, mocked_attr):
     """
     Test the case where the course  has an unexpected structure.
     """
     mocked_attr.return_value = {'foo': 'bar'}
     self.assertEqual(utils.get_course_chapters(self.course_key), [])