Exemplo n.º 1
0
    def test_access_masquerade_as_course_team_users(self, role_factory):
        """
        Test that when masquerading as members of the course team you do not lose access to graded content
        """
        # There are two types of course team members: instructor and staff
        # they have different privileges, but for the purpose of this test the important thing is that they should both
        # have access to all graded content
        staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id)
        CourseEnrollmentFactory.create(
            user=staff_user,
            course_id=self.course.id,
            mode='audit'
        )
        self.client.login(username=staff_user.username, password=TEST_PASSWORD)

        if role_factory == GlobalStaffFactory:
            user = role_factory.create()
        else:
            user = role_factory.create(course_key=self.course.id)
        self.update_masquerade(username=user.username)

        block = self.blocks_dict['problem']
        block_view_url = reverse('render_xblock', kwargs={'usage_key_string': six.text_type(block.scope_ids.usage_id)})
        response = self.client.get(block_view_url)
        self.assertEquals(response.status_code, 200)
    def test_instructor_tab(self):
        """
        Verify that the instructor tab appears for staff only.
        """
        def has_instructor_tab(user, course):
            """Returns true if the "Instructor" tab is shown."""
            tabs = get_course_tab_list(user, course)
            return len([tab for tab in tabs if tab.name == 'Instructor']) == 1

        self.assertTrue(has_instructor_tab(self.instructor, self.course))

        staff = StaffFactory(course_key=self.course.id)
        self.assertTrue(has_instructor_tab(staff, self.course))

        student = UserFactory.create()
        self.assertFalse(has_instructor_tab(student, self.course))

        researcher = UserFactory.create()
        CourseAccessRoleFactory(course_id=self.course.id,
                                user=researcher,
                                role='data_researcher',
                                org=self.course.id.org)
        self.assertTrue(has_instructor_tab(researcher, self.course))

        org_researcher = UserFactory.create()
        CourseAccessRoleFactory(course_id=None,
                                user=org_researcher,
                                role='data_researcher',
                                org=self.course.id.org)
        self.assertTrue(has_instructor_tab(org_researcher, self.course))
Exemplo n.º 3
0
 def setUpTestData(cls):
     """Set up and enroll our fake user in the course."""
     super(CourseHomePageTestCase, cls).setUpTestData()
     cls.staff_user = StaffFactory(course_key=cls.course.id,
                                   password=TEST_PASSWORD)
     cls.user = UserFactory(password=TEST_PASSWORD)
     CourseEnrollment.enroll(cls.user, cls.course.id)
Exemplo n.º 4
0
    def test_access_on_course_with_pre_requisites(self):
        """
        Test course access when a course has pre-requisite course yet to be completed
        """
        user = UserFactory.create()

        pre_requisite_course = CourseFactory.create(org='test_org',
                                                    number='788',
                                                    run='test_run')

        pre_requisite_courses = [six.text_type(pre_requisite_course.id)]
        course = CourseFactory.create(
            org='test_org',
            number='786',
            run='test_run',
            pre_requisite_courses=pre_requisite_courses)
        set_prerequisite_courses(course.id, pre_requisite_courses)

        # user should not be able to load course even if enrolled
        CourseEnrollmentFactory(user=user, course_id=course.id)
        response = access._has_access_course(user, 'load', course)
        self.assertFalse(response)
        self.assertIsInstance(response, access_response.MilestoneAccessError)
        # Staff can always access course
        staff = StaffFactory.create(course_key=course.id)
        self.assertTrue(access._has_access_course(staff, 'load', course))

        # User should be able access after completing required course
        fulfill_course_milestone(pre_requisite_course.id, user)
        self.assertTrue(access._has_access_course(user, 'load', course))
    def test_entrance_exam_gating_for_staff(self):
        """
        Tests gating is disabled if user is member of staff.
        """

        # Login as member of staff
        self.client.logout()
        staff_user = StaffFactory(course_key=self.course.id)
        staff_user.is_staff = True
        self.client.login(username=staff_user.username, password='******')

        # assert staff has access to all toc
        self.request.user = staff_user
        unlocked_toc = self._return_table_of_contents()
        for toc_section in self.expected_unlocked_toc:
            self.assertIn(toc_section, unlocked_toc)
Exemplo n.º 6
0
    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_staff=False, is_enrolled=True)
        self.addCleanup(set_current_request, None)
        course_tab_list = get_course_tab_list(user, self.course)
        name_list = [x.name for x in course_tab_list]
        assert 'Static Tab Free' in name_list
        assert 'Static Tab Instructors Only' not in 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='******')
        course_tab_list_staff = get_course_tab_list(staff_user, self.course)
        name_list_staff = [x.name for x in course_tab_list_staff]
        assert 'Static Tab Free' in name_list_staff
        assert 'Static Tab Instructors Only' in name_list_staff
Exemplo n.º 7
0
    def setUpClass(cls):
        super(CurrentGradeViewTest, cls).setUpClass()

        cls.course = CourseFactory.create(display_name='test course',
                                          run="Testing_course")
        with cls.store.bulk_operations(cls.course.id):

            chapter = ItemFactory.create(
                category='chapter',
                parent_location=cls.course.location,
                display_name="Chapter 1",
            )
            # create a problem for each type and minimum count needed by the grading policy
            # A section is not considered if the student answers less than "min_count" problems
            for grading_type, min_count in (("Homework", 12), ("Lab", 12),
                                            ("Midterm Exam", 1), ("Final Exam",
                                                                  1)):
                for num in xrange(min_count):
                    section = ItemFactory.create(
                        category='sequential',
                        parent_location=chapter.location,
                        due=datetime(2013, 9, 18, 11, 30, 00, tzinfo=UTC),
                        display_name='Sequential {} {}'.format(
                            grading_type, num),
                        format=grading_type,
                        graded=True,
                    )
                    vertical = ItemFactory.create(
                        category='vertical',
                        parent_location=section.location,
                        display_name='Vertical {} {}'.format(
                            grading_type, num),
                    )
                    ItemFactory.create(
                        category='problem',
                        parent_location=vertical.location,
                        display_name='Problem {} {}'.format(grading_type, num),
                    )

        cls.course_key = cls.course.id

        cls.password = '******'
        cls.student = UserFactory(username='******', password=cls.password)
        cls.other_student = UserFactory(username='******', password=cls.password)
        cls.other_user = UserFactory(username='******', password=cls.password)
        cls.staff = StaffFactory(course_key=cls.course.id,
                                 password=cls.password)
        cls.global_staff = GlobalStaffFactory.create()
        date = datetime(2013, 1, 22, tzinfo=UTC)
        for user in (
                cls.student,
                cls.other_student,
        ):
            CourseEnrollmentFactory(
                course_id=cls.course.id,
                user=user,
                created=date,
            )

        cls.namespaced_url = 'grades_api:user_grade_detail'
Exemplo n.º 8
0
    def test_reset_course_deadlines_masquerade_generic_student(self):
        course = self.courses[0]

        student_schedule = CourseEnrollment.objects.get(
            course_id=course.id, user=self.user).schedule
        student_schedule.start_date = timezone.now() - datetime.timedelta(
            days=30)
        student_schedule.save()

        staff = StaffFactory(course_key=course.id)
        staff_schedule = ScheduleFactory(
            start_date=timezone.now() - datetime.timedelta(days=30),
            enrollment__course__id=course.id,
            enrollment__user=staff,
        )

        self.client.login(username=staff.username, password=TEST_PASSWORD)
        self.update_masquerade(course=course)

        post_dict = {'course_id': str(course.id)}
        self.client.post(reverse(RESET_COURSE_DEADLINES_NAME), post_dict)
        updated_student_schedule = Schedule.objects.get(id=student_schedule.id)
        self.assertEqual(updated_student_schedule.start_date,
                         student_schedule.start_date)
        updated_staff_schedule = Schedule.objects.get(id=staff_schedule.id)
        self.assertEqual(updated_staff_schedule.start_date.date(),
                         datetime.date.today())
Exemplo n.º 9
0
    def test_access_masquerade_as_course_team_users(self, role_factory):
        """
        Test that when masquerading as members of the course team you do not lose access to graded content
        """
        # There are two types of course team members: instructor and staff
        # they have different privileges, but for the purpose of this test the important thing is that they should both
        # have access to all graded content
        staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id)
        CourseEnrollmentFactory.create(
            user=staff_user,
            course_id=self.course.id,
            mode='audit'
        )
        self.client.login(username=staff_user.username, password=TEST_PASSWORD)

        if role_factory == GlobalStaffFactory:
            user = role_factory.create()
        else:
            user = role_factory.create(course_key=self.course.id)
        self.update_masquerade(username=user.username)

        block = self.blocks_dict['problem']
        block_view_url = reverse('render_xblock', kwargs={'usage_key_string': six.text_type(block.scope_ids.usage_id)})
        response = self.client.get(block_view_url)
        self.assertEquals(response.status_code, 200)
Exemplo n.º 10
0
    def test_access_masquerade_as_user_with_forum_role(self, role_name):
        """
        Test that when masquerading as a user with a given forum role you do not lose access to graded content
        """
        staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id)
        CourseEnrollmentFactory.create(
            user=staff_user,
            course_id=self.course.id,
            mode='audit'
        )
        self.client.login(username=staff_user.username, password=TEST_PASSWORD)

        user = UserFactory.create()
        role = RoleFactory(name=role_name, course_id=self.course.id)
        role.users.add(user)

        CourseEnrollmentFactory.create(
            user=user,
            course_id=self.course.id,
            mode='audit'
        )

        self.update_masquerade(username=user.username)

        _assert_block_is_gated(
            block=self.blocks_dict['problem'],
            user=user,
            course=self.course,
            is_gated=False,
            request_factory=self.factory,
        )
Exemplo n.º 11
0
    def setUpClass(cls):
        super(GradeViewTestMixin, cls).setUpClass()

        cls.course = cls._create_test_course_with_default_grading_policy(
            display_name='test course', run="Testing_course")
        cls.empty_course = cls._create_test_course_with_default_grading_policy(
            display_name='empty test course', run="Empty_testing_course")

        cls.course_key = cls.course.id

        cls.password = '******'
        cls.student = UserFactory(username='******', password=cls.password)
        cls.other_student = UserFactory(username='******', password=cls.password)
        cls.other_user = UserFactory(username='******', password=cls.password)
        cls.staff = StaffFactory(course_key=cls.course_key,
                                 password=cls.password)
        cls.global_staff = GlobalStaffFactory.create()
        date = datetime(2013, 1, 22, tzinfo=UTC)
        for user in (
                cls.student,
                cls.other_student,
        ):
            CourseEnrollmentFactory(
                course_id=cls.course.id,
                user=user,
                created=date,
            )
Exemplo n.º 12
0
    def test__catalog_visibility(self):
        """
        Tests the catalog visibility tri-states
        """
        user = UserFactory.create()
        course_id = CourseLocator('edX', 'test', '2012_Fall')
        staff = StaffFactory.create(course_key=course_id)

        course = Mock(id=course_id,
                      catalog_visibility=CATALOG_VISIBILITY_CATALOG_AND_ABOUT)
        assert access._has_access_course(user, 'see_in_catalog', course)
        assert access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)

        # Now set visibility to just about page
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_ABOUT)
        assert not access._has_access_course(user, 'see_in_catalog', course)
        assert access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)

        # Now set visibility to none, which means neither in catalog nor about pages
        course = Mock(id=CourseLocator('edX', 'test', '2012_Fall'),
                      catalog_visibility=CATALOG_VISIBILITY_NONE)
        assert not access._has_access_course(user, 'see_in_catalog', course)
        assert not access._has_access_course(user, 'see_about_page', course)
        assert access._has_access_course(staff, 'see_in_catalog', course)
        assert access._has_access_course(staff, 'see_about_page', course)
Exemplo n.º 13
0
    def test_access_masquerade_as_user_with_forum_role(self, role_name):
        """
        Test that when masquerading as a user with a given forum role you do not lose access to graded content
        """
        staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id)
        CourseEnrollmentFactory.create(
            user=staff_user,
            course_id=self.course.id,
            mode='audit'
        )
        self.client.login(username=staff_user.username, password=TEST_PASSWORD)

        user = UserFactory.create()
        role = RoleFactory(name=role_name, course_id=self.course.id)
        role.users.add(user)

        CourseEnrollmentFactory.create(
            user=user,
            course_id=self.course.id,
            mode='audit'
        )

        self.update_masquerade(username=user.username)

        _assert_block_is_gated(
            block=self.blocks_dict['problem'],
            user=user,
            course=self.course,
            is_gated=False,
            request_factory=self.factory,
        )
Exemplo n.º 14
0
    def test_reset_course_deadlines_masquerade_generic_student(self):
        course = self.courses[0]

        student_schedule = CourseEnrollment.objects.get(course_id=course.id, user=self.user).schedule
        student_schedule.start_date = timezone.now() - datetime.timedelta(days=30)
        student_schedule.save()

        staff = StaffFactory(course_key=course.id)
        staff_schedule = ScheduleFactory(
            start_date=timezone.now() - datetime.timedelta(days=30),
            enrollment__course__id=course.id,
            enrollment__user=staff,
        )

        self.client.login(username=staff.username, password=TEST_PASSWORD)
        masquerade_url = reverse(
            'masquerade_update',
            kwargs={
                'course_key_string': six.text_type(course.id),
            }
        )
        response = self.client.post(
            masquerade_url,
            json.dumps({"role": 'student', "group_id": None, "user_name": None}),
            "application/json"
        )

        assert response.status_code == 200

        post_dict = {'reset_deadlines_redirect_url_id_dict': json.dumps({'course_id': str(course.id)})}
        self.client.post(reverse(RESET_COURSE_DEADLINES_NAME), post_dict)
        updated_student_schedule = Schedule.objects.get(id=student_schedule.id)
        self.assertEqual(updated_student_schedule.start_date, student_schedule.start_date)
        updated_staff_schedule = Schedule.objects.get(id=staff_schedule.id)
        self.assertEqual(updated_staff_schedule.start_date.date(), datetime.date.today())
Exemplo n.º 15
0
 def test_staff_authorized(self):
     """
     The view should return a 200 when provided an access token
     for course staff.
     """
     user = StaffFactory(course_key=self.course.id)
     auth_header = self.get_auth_header(user)
     self.assert_get_for_course(HTTP_AUTHORIZATION=auth_header)
Exemplo n.º 16
0
 def setUp(self):
     super(UserRoleTestCase, self).setUp()
     self.course_key = CourseLocator('edX', 'toy', '2012_Fall')
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course_key)
Exemplo n.º 17
0
 def test_courseware_page_access_with_staff_user_after_passing_entrance_exam(self):
     """
     Test courseware access page after passing entrance exam but with staff user
     """
     self.logout()
     staff_user = StaffFactory.create(course_key=self.course.id)
     self.login(staff_user.email, 'test')
     CourseEnrollmentFactory(user=staff_user, course_id=self.course.id)
     self._assert_chapter_loaded(self.course, self.chapter)
Exemplo n.º 18
0
 def setUp(self):
     super().setUp()
     self.course_key = CourseKey.from_string('edX/toy/2012_Fall')
     self.course_loc = self.course_key.make_usage_key('course', '2012_Fall')
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course_key)
Exemplo n.º 19
0
 def setUp(self):
     super(RolesTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course_key = CourseKey.from_string('edX/toy/2012_Fall')
     self.course_loc = self.course_key.make_usage_key('course', '2012_Fall')
     self.anonymous_user = AnonymousUserFactory()
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course_key)
     self.course_instructor = InstructorFactory(course_key=self.course_key)
Exemplo n.º 20
0
    def create_staff_for_course(self, course):
        """Creates and returns users with instructor and staff access to course."""

        return [
            InstructorFactory(course_key=course.id
                              ),  # Creates instructor_org/number/run role name
            StaffFactory(course_key=course.id
                         ),  # Creates staff_org/number/run role name
        ]
Exemplo n.º 21
0
 def setUp(self):
     super(CohortHandlerTestCase, self).setUp()
     self.course_staff_user = StaffFactory(
         username="******",
         course_key=self.course.id
     )
     self.course_instructor_user = InstructorFactory(
         username='******',
         course_key=self.course.id
     )
Exemplo n.º 22
0
 def setUp(self):
     super(AccessTestCase, self).setUp()
     self.course = CourseFactory.create(org='edX', course='toy', run='test_run')
     self.anonymous_user = AnonymousUserFactory()
     self.beta_user = BetaTesterFactory(course_key=self.course.id)
     self.student = UserFactory()
     self.global_staff = UserFactory(is_staff=True)
     self.course_staff = StaffFactory(course_key=self.course.id)
     self.course_instructor = InstructorFactory(course_key=self.course.id)
     self.staff = GlobalStaffFactory()
Exemplo n.º 23
0
 def setUp(self):
     super(CohortHandlerTestCase, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.course_staff_user = StaffFactory(
         username="******",
         course_key=self.course.id
     )
     self.course_instructor_user = InstructorFactory(
         username='******',
         course_key=self.course.id
     )
Exemplo n.º 24
0
    def setUpClass(cls):
        super(CourseValidationViewTest, cls).setUpClass()

        cls.course = CourseFactory.create(display_name='test course', run="Testing_course")
        cls.course_key = cls.course.id

        cls.password = '******'
        cls.student = UserFactory(username='******', password=cls.password)
        cls.staff = StaffFactory(course_key=cls.course.id, password=cls.password)

        cls.initialize_course(cls.course)
Exemplo n.º 25
0
    def create_staff_and_instructor(self):
        """
        Creates one instructor and several course staff for self.course. Assigns
        them to self.instructor (single user) and self.staff (list of users),
        respectively.
        """
        self.instructor = InstructorFactory(course_key=self.course.id)

        self.staff = [
            StaffFactory(course_key=self.course.id) for __ in range(STAFF_COUNT)
        ]
Exemplo n.º 26
0
 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='******')
     course_tab_list = get_course_tab_list(staff_user, self.course)
     self.assertEqual(len(course_tab_list), 4)
Exemplo n.º 27
0
 def setUp(self):
     super().setUp()
     self.track_function = make_track_function(HttpRequest())
     self.student_data = Mock()
     self.course = self.import_test_course()
     self.descriptor = ItemFactory(category="pure", parent=self.course)
     self.course_id = self.course.id
     self.instructor = StaffFactory.create(course_key=self.course_id)
     self.runtime = self.make_runtime()
     self.runtime.error_tracker = None
     self.staff = AdminFactory.create()
     self.course.bind_for_student(self.runtime, self.instructor)
    def setUpClass(cls):
        super(CourseImportViewTest, cls).setUpClass()

        cls.course = CourseFactory.create(display_name='test course',
                                          run="Testing_course")
        cls.course_key = cls.course.id

        cls.restricted_course = CourseFactory.create(
            display_name='restricted test course', run="Restricted_course")
        cls.restricted_course_key = cls.restricted_course.id

        cls.password = '******'
        cls.student = UserFactory(username='******', password=cls.password)
        cls.staff = StaffFactory(course_key=cls.course.id,
                                 password=cls.password)
        cls.restricted_staff = StaffFactory(
            course_key=cls.restricted_course.id, password=cls.password)

        cls.content_dir = path(tempfile.mkdtemp())

        # Create tar test files -----------------------------------------------
        # OK course:
        good_dir = tempfile.mkdtemp(dir=cls.content_dir)
        # test course being deeper down than top of tar file
        embedded_dir = os.path.join(good_dir, "grandparent", "parent")
        os.makedirs(os.path.join(embedded_dir, "course"))
        with open(os.path.join(embedded_dir, "course.xml"), "w+") as f:
            f.write(
                '<course url_name="2013_Spring" org="EDx" course="0.00x"/>')

        with open(os.path.join(embedded_dir, "course", "2013_Spring.xml"),
                  "w+") as f:
            f.write('<course></course>')

        cls.good_tar_filename = "good.tar.gz"
        cls.good_tar_fullpath = os.path.join(cls.content_dir,
                                             cls.good_tar_filename)
        with tarfile.open(cls.good_tar_fullpath, "w:gz") as gtar:
            gtar.add(good_dir)
Exemplo n.º 29
0
 def setUp(self):
     """
     Creates a test course ID, mocks the runtime, and creates a fake storage
     engine for use in all tests
     """
     super(StaffGradedAssignmentXblockTests, self).setUp()
     self.course = CourseFactory.create(org='foo',
                                        number='bar',
                                        display_name='baz')
     self.descriptor = ItemFactory(category="pure", parent=self.course)
     self.course_id = self.course.id
     self.instructor = StaffFactory.create(course_key=self.course_id)
     self.student_data = mock.Mock()
     self.staff = AdminFactory.create(password="******")
     self.runtime = self.make_runtime()
     self.scope_ids = self.make_scope_ids(self.runtime)
    def test_student_admin_staff_instructor(self):
        """
        Verify that staff users are not able to see course-wide options, while still
        seeing individual learner options.
        """
        # Original (instructor) user can see both specific grades, and course-wide grade adjustment tools
        response = self.client.get(self.url)
        self.assertContains(response, '<h4 class="hd hd-4">Adjust all enrolled learners')
        self.assertContains(response, '<h4 class="hd hd-4">View a specific learner&#39;s grades and progress')

        # But staff user can only see specific grades
        staff = StaffFactory(course_key=self.course.id)
        self.client.login(username=staff.username, password="******")
        response = self.client.get(self.url)
        self.assertNotContains(response, '<h4 class="hd hd-4">Adjust all enrolled learners')
        self.assertContains(response, '<h4 class="hd hd-4">View a specific learner&#39;s grades and progress')
Exemplo n.º 31
0
    def test_instructor_tab(self):
        """
        Verify that the instructor tab appears for staff only.
        """
        def has_instructor_tab(user, course):
            """Returns true if the "Instructor" tab is shown."""
            tabs = get_course_tab_list(user, course)
            return len([tab for tab in tabs if tab.name == 'Instructor']) == 1

        self.assertTrue(has_instructor_tab(self.instructor, self.course))

        staff = StaffFactory(course_key=self.course.id)
        self.assertTrue(has_instructor_tab(staff, self.course))

        student = UserFactory.create()
        self.assertFalse(has_instructor_tab(student, self.course))
    def setUp(self):
        super(TestViewAuth, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments

        self.course = CourseFactory.create(number='999',
                                           display_name='Robot_Super_Course')
        self.courseware_chapter = ItemFactory.create(display_name='courseware')
        self.overview_chapter = ItemFactory.create(
            parent_location=self.course.location,
            display_name='Super Overview')
        self.welcome_section = ItemFactory.create(
            parent_location=self.overview_chapter.location,
            display_name='Super Welcome')
        self.welcome_unit = ItemFactory.create(
            parent_location=self.welcome_section.location,
            display_name='Super Unit')
        self.course = modulestore().get_course(self.course.id)

        self.test_course = CourseFactory.create(org=self.course.id.org)
        self.other_org_course = CourseFactory.create(org='Other_Org_Course')
        self.sub_courseware_chapter = ItemFactory.create(
            parent_location=self.test_course.location,
            display_name='courseware')
        self.sub_overview_chapter = ItemFactory.create(
            parent_location=self.sub_courseware_chapter.location,
            display_name='Overview')
        self.sub_welcome_section = ItemFactory.create(
            parent_location=self.sub_overview_chapter.location,
            display_name='Welcome')
        self.sub_welcome_unit = ItemFactory.create(
            parent_location=self.sub_welcome_section.location,
            display_name='New Unit')
        self.test_course = modulestore().get_course(self.test_course.id)

        self.global_staff_user = GlobalStaffFactory()
        self.unenrolled_user = UserFactory(last_name="Unenrolled")

        self.enrolled_user = UserFactory(last_name="Enrolled")
        CourseEnrollmentFactory(user=self.enrolled_user,
                                course_id=self.course.id)
        CourseEnrollmentFactory(user=self.enrolled_user,
                                course_id=self.test_course.id)

        self.staff_user = StaffFactory(course_key=self.course.id)
        self.instructor_user = InstructorFactory(course_key=self.course.id)
        self.org_staff_user = OrgStaffFactory(course_key=self.course.id)
        self.org_instructor_user = OrgInstructorFactory(
            course_key=self.course.id)
    def test_no_banner_when_masquerading_as_forum_staff(self, role_name, mock_get_course_run_details):
        """
        When masquerading as a specific expired user, if that user has a forum staff role
        the expired course banner will not show up.
        """
        mock_get_course_run_details.return_value = {'weeks_to_complete': 1}

        expired_staff = UserFactory.create()
        role = RoleFactory(name=role_name, course_id=self.course.id)
        role.users.add(expired_staff)

        ScheduleFactory(
            start=self.THREE_YEARS_AGO,
            enrollment__mode=CourseMode.AUDIT,
            enrollment__course_id=self.course.id,
            enrollment__user=expired_staff
        )

        CourseDurationLimitConfig.objects.create(
            enabled=True,
            course=CourseOverview.get_from_id(self.course.id),
            enabled_as_of=self.course.start,
        )

        staff_user = StaffFactory.create(password=TEST_PASSWORD, course_key=self.course.id)
        CourseEnrollmentFactory.create(
            user=staff_user,
            course_id=self.course.id,
            mode='audit'
        )

        self.client.login(username=staff_user.username, password='******')

        self.update_masquerade(username=expired_staff.username)

        course_home_url = reverse('openedx.course_experience.course_home', args=[six.text_type(self.course.id)])
        response = self.client.get(course_home_url, follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertItemsEqual(response.redirect_chain, [])
        banner_text = 'This learner does not have access to this course. Their access expired on'
        self.assertNotIn(banner_text, response.content)