def test_contentstore_views_entrance_exam_delete(self): """ Unit Test: test_contentstore_views_entrance_exam_delete """ resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200) resp = self.client.delete(self.exam_url) self.assertEqual(resp.status_code, 204) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 404) user = User.objects.create( username='******', email='*****@*****.**', is_active=True, ) user.set_password('test') user.save() milestones = milestones_helpers.get_course_milestones( six.text_type(self.course_key)) self.assertEqual(len(milestones), 1) milestone_key = '{}.{}'.format(milestones[0]['namespace'], milestones[0]['name']) paths = milestones_helpers.get_course_milestones_fulfillment_paths( six.text_type(self.course_key), milestones_helpers.serialize_user(user)) # What we have now is a course milestone requirement and no valid fulfillment # paths for the specified user. The LMS is going to have to ignore this situation, # because we can't confidently prevent it from occuring at some point in the future. # milestone_key_1 = self.assertEqual(len(paths[milestone_key]), 0) # Re-adding an entrance exam to the course should fix the missing link # It wipes out any old entrance exam artifacts and inserts a new exam course chapter/module resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200) # Confirm that we have only one Entrance Exam grader after re-adding the exam (validates SOL-475) graders = CourseGradingModel.fetch(self.course_key).graders count = 0 for grader in graders: if grader['type'] == GRADER_TYPES['ENTRANCE_EXAM']: count += 1 self.assertEqual(count, 1)
def test_contentstore_views_entrance_exam_delete(self): """ Unit Test: test_contentstore_views_entrance_exam_delete """ resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200) resp = self.client.delete(self.exam_url) self.assertEqual(resp.status_code, 204) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 404) user = User.objects.create( username='******', email='*****@*****.**', is_active=True, ) user.set_password('test') user.save() milestones = milestones_helpers.get_course_milestones(unicode(self.course_key)) self.assertEqual(len(milestones), 1) milestone_key = '{}.{}'.format(milestones[0]['namespace'], milestones[0]['name']) paths = milestones_helpers.get_course_milestones_fulfillment_paths( unicode(self.course_key), milestones_helpers.serialize_user(user) ) # What we have now is a course milestone requirement and no valid fulfillment # paths for the specified user. The LMS is going to have to ignore this situation, # because we can't confidently prevent it from occuring at some point in the future. # milestone_key_1 = self.assertEqual(len(paths[milestone_key]), 0) # Re-adding an entrance exam to the course should fix the missing link # It wipes out any old entrance exam artifacts and inserts a new exam course chapter/module resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200) # Confirm that we have only one Entrance Exam grader after re-adding the exam (validates SOL-475) graders = CourseGradingModel.fetch(self.course_key).graders count = 0 for grader in graders: if grader['type'] == GRADER_TYPES['ENTRANCE_EXAM']: count += 1 self.assertEqual(count, 1)
def get_course_tab_list(course, user): """ Retrieves the course tab list from xmodule.tabs and manipulates the set as necessary """ user_is_enrolled = user.is_authenticated() and CourseEnrollment.is_enrolled(user, course.id) xmodule_tab_list = CourseTabList.iterate_displayable( course, settings, user.is_authenticated(), has_access(user, 'staff', course, course.id), user_is_enrolled ) # Entrance Exams Feature # If the course has an entrance exam, we'll need to see if the user has not passed it # If so, we'll need to hide away all of the tabs except for Courseware and Instructor entrance_exam_mode = False if settings.FEATURES.get('ENTRANCE_EXAMS', False): if getattr(course, 'entrance_exam_enabled', False): course_milestones_paths = get_course_milestones_fulfillment_paths( unicode(course.id), serialize_user(user) ) for __, value in course_milestones_paths.iteritems(): if len(value.get('content', [])): for content in value['content']: if content == course.entrance_exam_id \ and not EntranceExamConfiguration.user_can_skip_entrance_exam(user, course.id): entrance_exam_mode = True break # Now that we've loaded the tabs for this course, perform the Entrance Exam mode work # Majority case is no entrance exam defined course_tab_list = [] for tab in xmodule_tab_list: if entrance_exam_mode: # Hide all of the tabs except for 'Courseware' and 'Instructor' # Rename 'Courseware' tab to 'Entrance Exam' if tab.type not in ['courseware', 'instructor']: continue if tab.type == 'courseware': tab.name = _("Entrance Exam") course_tab_list.append(tab) return course_tab_list
def test_contentstore_views_entrance_exam_delete(self): """ Unit Test: test_contentstore_views_entrance_exam_delete """ resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200) resp = self.client.delete(self.exam_url) self.assertEqual(resp.status_code, 204) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 404) user = User.objects.create( username='******', email='*****@*****.**', is_active=True, ) user.set_password('test') user.save() milestones = milestones_api.get_course_milestones( unicode(self.course_key)) self.assertEqual(len(milestones), 1) milestone_key = '{}.{}'.format(milestones[0]['namespace'], milestones[0]['name']) paths = milestones_api.get_course_milestones_fulfillment_paths( unicode(self.course_key), serialize_user(user)) # What we have now is a course milestone requirement and no valid fulfillment # paths for the specified user. The LMS is going to have to ignore this situation, # because we can't confidently prevent it from occuring at some point in the future. # milestone_key_1 = self.assertEqual(len(paths[milestone_key]), 0) # Re-adding an entrance exam to the course should fix the missing link # It wipes out any old entrance exam artifacts and inserts a new exam course chapter/module resp = self.client.post(self.exam_url, {}, http_accept='application/json') self.assertEqual(resp.status_code, 201) resp = self.client.get(self.exam_url) self.assertEqual(resp.status_code, 200)
def _get_required_content(course, user): """ Queries milestones subsystem to see if the specified course is gated on one or more milestones, and if those milestones can be fulfilled via completion of a particular course content module """ required_content = [] if settings.FEATURES.get('MILESTONES_APP', False): # Get all of the outstanding milestones for this course, for this user try: milestone_paths = milestones_api.get_course_milestones_fulfillment_paths( unicode(course.id), serialize_user(user)) except InvalidMilestoneRelationshipTypeException: return required_content # For each outstanding milestone, see if this content is one of its fulfillment paths for path_key in milestone_paths: milestone_path = milestone_paths[path_key] if milestone_path.get('content') and len( milestone_path['content']): for content in milestone_path['content']: required_content.append(content) return required_content
def _get_required_content(course, user): """ Queries milestones subsystem to see if the specified course is gated on one or more milestones, and if those milestones can be fulfilled via completion of a particular course content module """ required_content = [] if settings.FEATURES.get("MILESTONES_APP", False): # Get all of the outstanding milestones for this course, for this user try: milestone_paths = milestones_api.get_course_milestones_fulfillment_paths( unicode(course.id), serialize_user(user) ) except InvalidMilestoneRelationshipTypeException: return required_content # For each outstanding milestone, see if this content is one of its fulfillment paths for path_key in milestone_paths: milestone_path = milestone_paths[path_key] if milestone_path.get("content") and len(milestone_path["content"]): for content in milestone_path["content"]: required_content.append(content) return required_content