def test_course_tabs_staff_only(self): """ Tests the static tabs that available only for instructor """ self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Free', url_slug='extra_tab_1', course_staff_only=False)) self.course.tabs.append(xmodule_tabs.CourseTab.load('static_tab', name='Static Tab Instructors Only', url_slug='extra_tab_2', course_staff_only=True)) self.course.save() user = self.create_mock_user(is_authenticated=True, is_staff=False, is_enrolled=True) request = get_mock_request(user) course_tab_list = get_course_tab_list(request, self.course) name_list = [x.name for x in course_tab_list] self.assertIn('Static Tab Free', name_list) self.assertNotIn('Static Tab Instructors Only', name_list) # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_mock_request(staff_user) course_tab_list_staff = get_course_tab_list(request, self.course) name_list_staff = [x.name for x in course_tab_list_staff] self.assertIn('Static Tab Free', name_list_staff) self.assertIn('Static Tab Instructors Only', name_list_staff)
def test_get_course_tabs_list_entrance_exam_enabled(self): """ Unit Test: test_get_course_tabs_list_entrance_exam_enabled """ entrance_exam = ItemFactory.create( category="chapter", parent_location=self.course.location, data="Exam Data", display_name="Entrance Exam" ) entrance_exam.is_entrance_exam = True milestone = { "name": "Test Milestone", "namespace": "{}.entrance_exams".format(unicode(self.course.id)), "description": "Testing Courseware Tabs", } self.course.entrance_exam_enabled = True self.course.entrance_exam_id = unicode(entrance_exam.location) milestone = milestones_helpers.add_milestone(milestone) milestones_helpers.add_course_milestone( unicode(self.course.id), self.relationship_types["REQUIRES"], milestone ) milestones_helpers.add_course_content_milestone( unicode(self.course.id), unicode(entrance_exam.location), self.relationship_types["FULFILLS"], milestone ) course_tab_list = get_course_tab_list(self.course, self.user) self.assertEqual(len(course_tab_list), 2) self.assertEqual(course_tab_list[0]["tab_id"], "courseware") self.assertEqual(course_tab_list[0]["name"], "Entrance Exam") self.assertEqual(course_tab_list[1]["tab_id"], "instructor")
def test_get_course_tabs_list_entrance_exam_enabled(self): """ Unit Test: test_get_course_tabs_list_entrance_exam_enabled """ entrance_exam = ItemFactory.create( category="chapter", parent_location=self.course.location, data="Exam Data", display_name="Entrance Exam", is_entrance_exam=True ) milestone = { 'name': 'Test Milestone', 'namespace': '{}.entrance_exams'.format(unicode(self.course.id)), 'description': 'Testing Courseware Tabs' } self.user.is_staff = False self.course.entrance_exam_enabled = True self.course.entrance_exam_id = unicode(entrance_exam.location) milestone = milestones_helpers.add_milestone(milestone) milestones_helpers.add_course_milestone( unicode(self.course.id), self.relationship_types['REQUIRES'], milestone ) milestones_helpers.add_course_content_milestone( unicode(self.course.id), unicode(entrance_exam.location), self.relationship_types['FULFILLS'], milestone ) course_tab_list = get_course_tab_list(self.course, self.user) self.assertEqual(len(course_tab_list), 1) self.assertEqual(course_tab_list[0]['tab_id'], 'courseware') self.assertEqual(course_tab_list[0]['name'], 'Entrance Exam')
def get_wiki_tab(self, user, course): """Returns true if the "Wiki" tab is shown.""" request = RequestFactory().request() request.user = user all_tabs = get_course_tab_list(request, course) wiki_tabs = [tab for tab in all_tabs if tab.name == 'Wiki'] return wiki_tabs[0] if len(wiki_tabs) == 1 else None
def test_course_tabs_list_for_staff_members(self): """ Tests tab list is not limited if user is member of staff and has not passed entrance exam. """ # Login as member of staff self.client.logout() staff_user = StaffFactory(course_key=self.course.id) self.client.login(username=staff_user.username, password='******') request = get_request_for_user(staff_user) course_tab_list = get_course_tab_list(request, self.course) self.assertEqual(len(course_tab_list), 5)
def test_pdf_textbook_tabs(self): """ Test that all textbooks tab links generating correctly. """ type_to_reverse_name = {"textbook": "book", "pdftextbook": "pdf_book", "htmltextbook": "html_book"} course_tab_list = get_course_tab_list(self.course, self.user) num_of_textbooks_found = 0 for tab in course_tab_list: # Verify links of all textbook type tabs. if isinstance(tab, tabs.SingleTextbookTab): book_type, book_index = tab.tab_id.split("/", 1) expected_link = reverse( type_to_reverse_name[book_type], args=[self.course.id.to_deprecated_string(), book_index] ) tab_link = tab.link_func(self.course, reverse) self.assertEqual(tab_link, expected_link) num_of_textbooks_found += 1 self.assertEqual(num_of_textbooks_found, self.num_textbooks)
def test_get_course_tabs_list_skipped_entrance_exam(self): """ Tests tab list is not limited if user is allowed to skip entrance exam. """ # create a user student = UserFactory() # login as instructor hit skip entrance exam api in instructor app instructor = InstructorFactory(course_key=self.course.id) self.client.logout() self.client.login(username=instructor.username, password="******") url = reverse("mark_student_can_skip_entrance_exam", kwargs={"course_id": unicode(self.course.id)}) response = self.client.post(url, {"unique_student_identifier": student.email}) self.assertEqual(response.status_code, 200) # log in again as student self.client.logout() self.login(self.email, self.password) course_tab_list = get_course_tab_list(self.course, self.user) self.assertEqual(len(course_tab_list), 5)
def test_pdf_textbook_tabs(self): """ Test that all textbooks tab links generating correctly. """ type_to_reverse_name = {'textbook': 'book', 'pdftextbook': 'pdf_book', 'htmltextbook': 'html_book'} request = get_request_for_user(self.user) course_tab_list = get_course_tab_list(request, self.course) num_of_textbooks_found = 0 for tab in course_tab_list: # Verify links of all textbook type tabs. if tab.type == 'single_textbook': book_type, book_index = tab.tab_id.split("/", 1) expected_link = reverse( type_to_reverse_name[book_type], args=[self.course.id.to_deprecated_string(), book_index] ) tab_link = tab.link_func(self.course, reverse) self.assertEqual(tab_link, expected_link) num_of_textbooks_found += 1 self.assertEqual(num_of_textbooks_found, self.num_textbooks)
def test_default_tab_for_new_course_experience(self): # Verify that the unified course experience hides the course info tab tabs = get_course_tab_list(self.request, self.course) self.assertEqual(tabs[0].type, 'courseware')
def test_default_tab(self): # Verify that the course info tab is the first tab tabs = get_course_tab_list(self.request, self.course) self.assertEqual(tabs[0].type, 'course_info')
def discussion_tab_present(self, user): """ Returns true if the user has access to the discussion tab. """ request = RequestFactory().request() request.user = user all_tabs = get_course_tab_list(request, self.course) return any(tab.type == 'discussion' for tab in all_tabs)
def check_ccx_tab(self, course): """Helper function for verifying the ccx tab.""" request = RequestFactory().request() request.user = self.user all_tabs = get_course_tab_list(request, course) return any(tab.type == 'ccx_coach' for tab in all_tabs)
def has_notes_tab(user, course): """Returns true if the "Notes" tab is shown.""" request = RequestFactory().request() request.user = user tabs = get_course_tab_list(request, course) return len([tab for tab in tabs if tab.type == 'edxnotes']) == 1
def has_instructor_tab(user, course): """Returns true if the "Instructor" tab is shown.""" request = RequestFactory().request() request.user = user tabs = get_course_tab_list(request, course) return len([tab for tab in tabs if tab.name == 'Instructor']) == 1
def has_notes_tab(self, course, user): """ Returns true if the current course and user have a notes tab, false otherwise. """ request = RequestFactory().request() request.user = user all_tabs = get_course_tab_list(request, course) return any([tab.name == u'My Notes' for tab in all_tabs])