コード例 #1
0
    def test_access_denied_fragment_for_masquerading(self):
        """
        Test that a global staff sees gated content flag when viewing course as `Learner in Audit`
        Note: Global staff doesn't require to be enrolled in course.
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(
            course_key=mock_course.id)))
        mock_course_masquerade = Mock(
            role='student',
            user_partition_id=ENROLLMENT_TRACK_PARTITION_ID,
            group_id=settings.COURSE_ENROLLMENT_MODES['audit']['id'],
            user_name=None)
        CourseModeFactory.create(course_id=mock_course.id,
                                 mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False,
                                               studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
                'courseware.masquerade.get_course_masquerade',
                return_value=mock_course_masquerade
        ), patch(
                'openedx.features.content_type_gating.partitions.get_course_masquerade',
                return_value=mock_course_masquerade), patch(
                    'crum.get_current_request', return_value=mock_request):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #2
0
ファイル: test_views.py プロジェクト: cmscom/edx-platform
    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,
            )
コード例 #3
0
    def test_access_denied_fragment_for_masquerading(self):
        """
        Test that a global staff sees gated content flag when viewing course as `Learner in Audit`
        Note: Global staff doesn't require to be enrolled in course.
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(course_key=mock_course.id)))
        mock_course_masquerade = Mock(
            role='student',
            user_partition_id=ENROLLMENT_TRACK_PARTITION_ID,
            group_id=settings.COURSE_ENROLLMENT_MODES['audit']['id'],
            user_name=None
        )
        CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
            'courseware.masquerade.get_course_masquerade',
            return_value=mock_course_masquerade
        ), patch(
            'openedx.features.content_type_gating.partitions.get_course_masquerade',
            return_value=mock_course_masquerade
        ), patch(
            'crum.get_current_request',
            return_value=mock_request
        ):
            fragment = partition.access_denied_fragment(mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #4
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,
            )
コード例 #5
0
    def test_access_denied_fragment_for_masquerading(self):
        """
        Test that a global staff sees gated content flag when viewing course as `Learner in Limited Access`
        Note: Global staff doesn't require to be enrolled in course.
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(course_key=mock_course.id)))
        mock_course_masquerade = Mock(
            role='student',
            user_partition_id=CONTENT_GATING_PARTITION_ID,
            group_id=LIMITED_ACCESS.id,
            user_name=None
        )
        CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
            'crum.get_current_request',
            return_value=mock_request
        ):
            fragment = partition.access_denied_fragment(mock_block, global_staff, LIMITED_ACCESS, [FULL_ACCESS])

        self.assertIsNotNone(fragment)
コード例 #6
0
ファイル: mixins.py プロジェクト: digitalsatori/edx-platform
 def setUp(self):
     super(GradeViewTestMixin, self).setUp()
     self.password = '******'
     self.global_staff = GlobalStaffFactory.create()
     self.student = UserFactory(password=self.password, username='******')
     self.other_student = UserFactory(password=self.password, username='******')
     self._create_user_enrollments(self.student, self.other_student)
コード例 #7
0
    def test_acess_denied_fragment_for_null_request(self):
        """
        Verifies the access denied fragment is visible when HTTP request is not available.

        Given the HTTP request instance is None
        Then set the mobile_app context variable to False
        And the fragment should be created successfully
        """
        mock_request = None
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(course_key=mock_course.id)))
        CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')
        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
        partition = create_content_gating_partition(mock_course)

        with patch(
            'crum.get_current_request',
            return_value=mock_request
        ), patch(
            'openedx.features.content_type_gating.partitions.ContentTypeGatingPartition._is_audit_enrollment',
            return_value=True
        ):
            fragment = partition.access_denied_fragment(mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #8
0
    def test_access_denied_fragment_for_full_access_users(self):
        """
        Test that Full Access users do not see the access_denied_fragment or access_denied_message
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(
            course_key=mock_course.id)))

        CourseModeFactory.create(course_id=mock_course.id,
                                 mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False,
                                               studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch('crum.get_current_request', return_value=mock_request):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, FULL_ACCESS, 'test_allowed_group')
            self.assertIsNone(fragment)
            message = partition.access_denied_message(
                mock_block.scope_ids.usage_id, global_staff, FULL_ACCESS,
                'test_allowed_group')
            self.assertIsNone(message)
コード例 #9
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'
コード例 #10
0
 def setUp(self):
     super(GradeViewTestMixin, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
     self.password = '******'
     self.global_staff = GlobalStaffFactory.create()
     self.student = UserFactory(password=self.password,
                                username='******',
                                email='*****@*****.**')
     self.other_student = UserFactory(
         password=self.password,
         username='******',
         email='*****@*****.**',
     )
     self.program_student = UserFactory(
         password=self.password,
         username='******',
         email='*****@*****.**',
     )
     self.program_masters_student = UserFactory(
         password=self.password,
         username='******',
         email='*****@*****.**',
     )
     self._create_user_enrollments(self.student, self.other_student)
     self._create_user_program_enrollments(self.program_student)
     self._create_user_program_enrollments(self.program_masters_student,
                                           mode='masters')
コード例 #11
0
    def test_access_denied_fragment_for_masquerading(self):
        """
        Test that a global staff sees gated content flag when viewing course as `Learner in Limited Access`
        Note: Global staff doesn't require to be enrolled in course.
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(course_key=mock_course.id)))
        mock_course_masquerade = Mock(
            role='student',
            user_partition_id=CONTENT_GATING_PARTITION_ID,
            group_id=LIMITED_ACCESS.id,
            user_name=None
        )
        CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
            'crum.get_current_request',
            return_value=mock_request
        ):
            fragment = partition.access_denied_fragment(mock_block, global_staff, LIMITED_ACCESS, [FULL_ACCESS])

        self.assertIsNotNone(fragment)
コード例 #12
0
 def setUp(self):
     super(GradeViewTestMixin, self).setUp()
     self.password = '******'
     self.global_staff = GlobalStaffFactory.create()
     self.student = UserFactory(password=self.password)
     self.other_student = UserFactory(password=self.password)
     self._create_user_enrollments(self.student, self.other_student)
コード例 #13
0
    def test_acess_denied_fragment_for_null_request(self):
        """
        Verifies the access denied fragment is visible when HTTP request is not available.

        Given the HTTP request instance is None
        Then set the mobile_app context variable to False
        And the fragment should be created successfully
        """
        mock_request = None
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(
            course_key=mock_course.id)))
        CourseModeFactory.create(course_id=mock_course.id,
                                 mode_slug='verified')
        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=True,
                                               enabled_as_of=datetime(
                                                   2018, 1, 1))
        partition = create_content_gating_partition(mock_course)

        with patch(
                'crum.get_current_request', return_value=mock_request
        ), patch(
                'openedx.features.content_type_gating.partitions.ContentTypeGatingPartition._is_audit_enrollment',
                return_value=True):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, GroupFactory(), 'test_allowed_group')

        self.assertIsNotNone(fragment)
コード例 #14
0
 def setUpClass(cls):
     super(BaseCourseEnrollmentTestsMixin, cls).setUpClass()
     cls.start_cache_isolation()
     cls.password = '******'
     cls.student = UserFactory.create(username='******',
                                      password=cls.password)
     cls.global_staff = GlobalStaffFactory.create(username='******',
                                                  password=cls.password)
コード例 #15
0
 def setUpClass(cls):
     super(ProgramEnrollmentListTest, cls).setUpClass()
     cls.program_uuid = '00000000-1111-2222-3333-444444444444'
     cls.curriculum_uuid = 'aaaaaaaa-1111-2222-3333-444444444444'
     cls.password = '******'
     cls.student = UserFactory.create(username='******',
                                      password=cls.password)
     cls.global_staff = GlobalStaffFactory.create(username='******',
                                                  password=cls.password)
コード例 #16
0
    def setUpClass(cls):
        super(ListViewTestMixin, cls).setUpClass()
        cls.program_uuid = '00000000-1111-2222-3333-444444444444'
        cls.curriculum_uuid = 'aaaaaaaa-1111-2222-3333-444444444444'
        cls.other_curriculum_uuid = 'bbbbbbbb-1111-2222-3333-444444444444'

        cls.course_id = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
        _ = CourseOverviewFactory.create(id=cls.course_id)

        cls.password = '******'
        cls.student = UserFactory.create(username='******', password=cls.password)
        cls.global_staff = GlobalStaffFactory.create(username='******', password=cls.password)
コード例 #17
0
ファイル: test_views.py プロジェクト: mreyk/edx-platform
    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'
コード例 #18
0
    def setUpClass(cls):
        super(ListViewTestMixin, cls).setUpClass()
        cls.program_uuid = '00000000-1111-2222-3333-444444444444'
        cls.curriculum_uuid = 'aaaaaaaa-1111-2222-3333-444444444444'
        cls.other_curriculum_uuid = 'bbbbbbbb-1111-2222-3333-444444444444'

        cls.course_id = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
        _ = CourseOverviewFactory.create(id=cls.course_id)

        cls.password = '******'
        cls.student = UserFactory.create(username='******',
                                         password=cls.password)
        cls.global_staff = GlobalStaffFactory.create(username='******',
                                                     password=cls.password)
コード例 #19
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()
        cls._create_user_enrollments(cls.course, cls.student, cls.other_student)
コード例 #20
0
    def setUp(self):
        super(ProgramEnrollmentViewPatchTests, self).setUp()

        self.program_uuid = '00000000-1111-2222-3333-444444444444'
        self.curriculum_uuid = 'aaaaaaaa-1111-2222-3333-444444444444'
        self.other_curriculum_uuid = 'bbbbbbbb-1111-2222-3333-444444444444'

        self.course_id = CourseKey.from_string('course-v1:edX+ToyX+Toy_Course')
        _ = CourseOverviewFactory.create(id=self.course_id)

        self.password = '******'
        self.student = UserFactory.create(username='******',
                                          password=self.password)
        self.global_staff = GlobalStaffFactory.create(username='******',
                                                      password=self.password)

        self.client.login(username=self.global_staff.username,
                          password=self.password)
コード例 #21
0
    def test_access_denied_fragment_for_full_access_users(self):
        """
        Test that Full Access users do not see the access_denied_fragment or access_denied_message
        """
        mock_request = RequestFactory().get('/')
        mock_course = Mock(id=self.course_key, user_partitions={})
        mock_block = Mock(scope_ids=Mock(usage_id=Mock(course_key=mock_course.id)))

        CourseModeFactory.create(course_id=mock_course.id, mode_slug='verified')

        global_staff = GlobalStaffFactory.create()
        ContentTypeGatingConfig.objects.create(enabled=False, studio_override_enabled=True)

        partition = create_content_gating_partition(mock_course)

        with patch(
            'crum.get_current_request',
            return_value=mock_request
        ):
            fragment = partition.access_denied_fragment(mock_block, global_staff, FULL_ACCESS, 'test_allowed_group')
            self.assertIsNone(fragment)
            message = partition.access_denied_message(mock_block, global_staff, FULL_ACCESS, 'test_allowed_group')
            self.assertIsNone(message)
コード例 #22
0
 def create_user_and_access_token(self):
     self.user = GlobalStaffFactory.create()
     self.oauth_client = ApplicationFactory.create()
     self.access_token = AccessTokenFactory.create(
         user=self.user, application=self.oauth_client).token
コード例 #23
0
 def setUpClass(cls):
     super(BaseCourseEnrollmentTestsMixin, cls).setUpClass()
     cls.start_cache_isolation()
     cls.password = '******'
     cls.student = UserFactory.create(username='******', password=cls.password)
     cls.global_staff = GlobalStaffFactory.create(username='******', password=cls.password)
コード例 #24
0
 def setUp(self):
     super(ProgramEnrollmentViewPostTests, self).setUp()
     global_staff = GlobalStaffFactory.create(username='******', password='******')
     self.client.login(username=global_staff.username, password='******')
コード例 #25
0
 def create_user_and_access_token(self):
     # pylint: disable=missing-docstring
     self.user = GlobalStaffFactory.create()
     self.oauth_client = ClientFactory.create()
     self.access_token = AccessTokenFactory.create(
         user=self.user, client=self.oauth_client).token
コード例 #26
0
ファイル: test_views.py プロジェクト: cmscom/edx-platform
 def create_user_and_access_token(self):
     self.user = GlobalStaffFactory.create()
     self.oauth_client = ClientFactory.create()
     self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token
コード例 #27
0
ファイル: test_views.py プロジェクト: mreyk/edx-platform
 def create_user_and_access_token(self):
     # pylint: disable=missing-docstring
     self.user = GlobalStaffFactory.create()
     self.oauth_client = ClientFactory.create()
     self.access_token = AccessTokenFactory.create(user=self.user, client=self.oauth_client).token
コード例 #28
0
 def setUp(self):
     super(ProgramEnrollmentViewPostTests, self).setUp()
     global_staff = GlobalStaffFactory.create(username='******',
                                              password='******')
     self.client.login(username=global_staff.username, password='******')