示例#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 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])

        assert fragment is not None
示例#2
0
 def setUp(self):
     super().setUp()
     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')
示例#3
0
    def test_is_user_staff_or_instructor(self):
        """
        Verify the correct value is returned for users with different access levels.
        """
        course_id_string = str(self.course.id)
        global_staff_user = GlobalStaffFactory.create()
        staff_user = StaffFactory.create(course_key=self.course_run_key)
        instructor = InstructorFactory.create(course_key=self.course_run_key)

        different_course = CourseFactory.create()
        instructor_different_course = InstructorFactory.create(
            course_key=different_course.id)

        assert is_user_staff_or_instructor_in_course(instructor,
                                                     course_id_string)
        assert is_user_staff_or_instructor_in_course(global_staff_user,
                                                     self.course_run_key)
        assert is_user_staff_or_instructor_in_course(staff_user,
                                                     self.course_run_key)
        assert is_user_staff_or_instructor_in_course(instructor,
                                                     self.course_run_key)
        assert not is_user_staff_or_instructor_in_course(
            self.user, self.course_run_key)
        assert not is_user_staff_or_instructor_in_course(
            instructor_different_course, self.course_run_key)
示例#4
0
    def test_access_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='audit')
        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):
            fragment = partition.access_denied_fragment(
                mock_block, global_staff, LIMITED_ACCESS, [FULL_ACCESS])

        assert fragment is not None
示例#5
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')
            assert fragment is None
            message = partition.access_denied_message(
                mock_block.scope_ids.usage_id, global_staff, FULL_ACCESS,
                'test_allowed_group')
            assert message is None
示例#6
0
 def setUp(self) -> None:
     super().setUp()
     self.test_course_id = 'course-v1:edX+Test+1'
     self.user = UserFactory()
     self.global_staff = GlobalStaffFactory.create()
     _ = FinancialAssistanceConfigurationFactory(
         api_base_url='http://financial.assistance.test:1234',
         service_username=self.global_staff.username,
         fa_backend_enabled_courses_percentage=100,
         enabled=True)
     _ = Application.objects.create(
         name='Test Application',
         user=self.global_staff,
         client_type=Application.CLIENT_PUBLIC,
         authorization_grant_type=Application.GRANT_CLIENT_CREDENTIALS,
     )
 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