Exemplo n.º 1
0
    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)

        CourseEnrollmentFactory.create(
            mode=CourseMode.AUDIT,
            course_id=self.course.id,
            user=expired_staff,
        )
        Schedule.objects.update(start_date=self.THREE_YEARS_AGO)

        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=[str(self.course.id)])
        response = self.client.get(course_home_url, follow=True)
        assert response.status_code == 200
        self.assertCountEqual(response.redirect_chain, [])
        banner_text = 'This learner does not have access to this course. Their access expired on'
        self.assertNotContains(response, banner_text)
    def test_no_banner_when_masquerading_as_staff(self, role_factory,
                                                  mock_get_course_run_details):
        """
        When masquerading as a specific expired user, if that user has a staff role
        the expired course banner will not show up.
        """
        mock_get_course_run_details.return_value = {'weeks_to_complete': 1}

        if role_factory == GlobalStaffFactory:
            expired_staff = role_factory.create(password=TEST_PASSWORD)
        else:
            expired_staff = role_factory.create(password=TEST_PASSWORD,
                                                course_key=self.course.id)

        CourseEnrollmentFactory.create(
            mode=CourseMode.AUDIT,
            course_id=self.course.id,
            user=expired_staff,
        )
        Schedule.objects.update(start_date=self.THREE_YEARS_AGO)
        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)

        response = self.get_courseware()
        assert response.status_code == 200
        self.assertCountEqual(response.redirect_chain, [])
        banner_text = 'This learner does not have access to this course. Their access expired on'
        self.assertNotContains(response, banner_text)
Exemplo n.º 3
0
    def test_entrance_exam_requirement_message_hidden(self):
        """
        Unit Test: entrance exam message should not be present outside the context of entrance exam subsection.
        """
        # Login as staff to avoid redirect to entrance exam
        self.client.logout()
        staff_user = StaffFactory(course_key=self.course.id)
        self.client.login(username=staff_user.username, password='******')
        CourseEnrollment.enroll(staff_user, self.course.id)

        url = reverse('courseware_section',
                      kwargs={
                          'course_id': str(self.course.id),
                          'chapter': self.chapter.location.block_id,
                          'section': self.chapter_subsection.location.block_id
                      })
        resp = self.client.get(url)
        assert resp.status_code == 200
        self.assertNotContains(resp,
                               'To access course materials, you must score')
        self.assertNotContains(resp, 'You have passed the entrance exam.')
Exemplo n.º 4
0
    def test_reset_course_deadlines_masquerade_generic_student(self):
        course = self.courses[0]

        staff = StaffFactory(course_key=course.id)
        CourseEnrollment.enroll(staff, course.id)

        start_date = timezone.now() - datetime.timedelta(days=30)
        Schedule.objects.update(start_date=start_date)

        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(
            enrollment__user=self.user, enrollment__course_id=course.id)
        assert updated_student_schedule.start_date == start_date
        updated_staff_schedule = Schedule.objects.get(
            enrollment__user=staff, enrollment__course_id=course.id)
        assert updated_staff_schedule.start_date.date() == datetime.date.today(
        )
Exemplo n.º 5
0
    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'
        )
    def create_user_for_course(self,
                               course,
                               user_type=CourseUserType.ENROLLED):
        """
        Create a test user for a course.
        """
        if user_type is CourseUserType.ANONYMOUS:
            return AnonymousUser()

        is_enrolled = user_type is CourseUserType.ENROLLED
        is_unenrolled_staff = user_type is CourseUserType.UNENROLLED_STAFF

        # Set up the test user
        if is_unenrolled_staff:
            user = StaffFactory(course_key=course.id,
                                password=self.TEST_PASSWORD)
        elif user_type is CourseUserType.GLOBAL_STAFF:
            user = AdminFactory(password=self.TEST_PASSWORD)
        else:
            user = UserFactory(password=self.TEST_PASSWORD)
        self.client.login(username=user.username, password=self.TEST_PASSWORD)
        if is_enrolled:
            CourseEnrollment.enroll(user, course.id)
        return user
Exemplo n.º 7
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.º 8
0
 def create_user(self):
     """
     Creates a staff user.
     """
     return StaffFactory(course_key=self.course.id)
Exemplo n.º 9
0
 def setUpTestData(cls):
     """Set up and enroll our fake user in the course."""
     super().setUpTestData()
     cls.staff_user = StaffFactory(course_key=cls.course.id,
                                   password=TEST_PASSWORD)
Exemplo n.º 10
0
    def setUp(self):
        super().setUp()

        UserPartition.scheme_extensions = ExtensionManager.make_test_instance(
            [
                Extension("memory", USER_PARTITION_SCHEME_NAMESPACE,
                          MemoryUserPartitionScheme(), None),
                Extension("random", USER_PARTITION_SCHEME_NAMESPACE,
                          MemoryUserPartitionScheme(), None)
            ],
            namespace=USER_PARTITION_SCHEME_NAMESPACE)

        self.cat_group = Group(10, 'cats')
        self.dog_group = Group(20, 'dogs')
        self.worm_group = Group(30, 'worms')
        self.animal_partition = UserPartition(
            0,
            'Pet Partition',
            'which animal are you?',
            [self.cat_group, self.dog_group, self.worm_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.red_group = Group(1000, 'red')
        self.blue_group = Group(2000, 'blue')
        self.gray_group = Group(3000, 'gray')
        self.color_partition = UserPartition(
            100,
            'Color Partition',
            'what color are you?',
            [self.red_group, self.blue_group, self.gray_group],
            scheme=UserPartition.get_scheme("memory"),
        )

        self.course = CourseFactory.create(
            user_partitions=[self.animal_partition, self.color_partition], )
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(category='chapter',
                                         parent=self.course)
            section = ItemFactory.create(category='sequential', parent=chapter)
            vertical = ItemFactory.create(category='vertical', parent=section)
            component = ItemFactory.create(category='problem', parent=vertical)

            self.chapter_location = chapter.location
            self.section_location = section.location
            self.vertical_location = vertical.location
            self.component_location = component.location

        self.red_cat = UserFactory()  # student in red and cat groups
        self.set_user_group(self.red_cat, self.animal_partition,
                            self.cat_group)
        self.set_user_group(self.red_cat, self.color_partition, self.red_group)

        self.blue_dog = UserFactory()  # student in blue and dog groups
        self.set_user_group(self.blue_dog, self.animal_partition,
                            self.dog_group)
        self.set_user_group(self.blue_dog, self.color_partition,
                            self.blue_group)

        self.white_mouse = UserFactory()  # student in no group

        self.gray_worm = UserFactory()  # student in deleted group
        self.set_user_group(self.gray_worm, self.animal_partition,
                            self.worm_group)
        self.set_user_group(self.gray_worm, self.color_partition,
                            self.gray_group)
        # delete the gray/worm groups from the partitions now so we can test scenarios
        # for user whose group is missing.
        self.animal_partition.groups.pop()
        self.color_partition.groups.pop()

        # add a staff user, whose access will be unconditional in spite of group access.
        self.staff = StaffFactory.create(course_key=self.course.id)