class PermissionTests(TestCase): """ Tests for permissions defined in courseware.rules """ def setUp(self): super(PermissionTests, self).setUp() self.user = UserFactory() self.course_id = CourseLocator('MITx', '000', 'Perm_course') CourseModeFactory(mode_slug='verified', course_id=self.course_id) CourseModeFactory(mode_slug='masters', course_id=self.course_id) CourseModeFactory(mode_slug='professional', course_id=self.course_id) CourseEnrollment.unenroll(self.user, self.course_id) def tearDown(self): super(PermissionTests, self).tearDown() self.user.delete() @ddt.data( (None, False), ('audit', False), ('verified', True), ('masters', True), ('professional', True), ('no-id-professional', False), ) @ddt.unpack def test_proctoring_perm(self, mode, should_have_perm): """ Test that the user has the edx_proctoring.can_take_proctored_exam permission """ if mode is not None: CourseEnrollment.enroll(self.user, self.course_id, mode=mode) has_perm = self.user.has_perm( 'edx_proctoring.can_take_proctored_exam', {'course_id': six.text_type(self.course_id)}) assert has_perm == should_have_perm @override_settings(PROCTORING_BACKENDS={ 'mock_proctoring_allow_honor_mode': { 'allow_honor_mode': True, }, }) def test_proctoring_perm_with_honor_mode_permission(self): """ Test that the user has the edx_proctoring.can_take_proctored_exam permission in honor enrollment mode. If proctoring backend configuration allows exam in honor mode {`allow_honor_mode`: True} the user is granter proctored exam permission. """ CourseEnrollment.enroll(self.user, self.course_id, mode='honor') self.assertTrue( self.user.has_perm( 'edx_proctoring.can_take_proctored_exam', { 'course_id': six.text_type(self.course_id), 'backend': 'mock_proctoring_allow_honor_mode', 'is_proctored': True }))
class PermissionTests(ModuleStoreTestCase): """ Tests for permissions defined in courseware.rules """ def setUp(self): super().setUp() self.user = UserFactory() self.course = CourseFactory(enable_proctored_exams=True) self.course_id = self.course.id # pylint: disable=no-member CourseModeFactory(mode_slug='verified', course_id=self.course_id) CourseModeFactory(mode_slug='masters', course_id=self.course_id) CourseModeFactory(mode_slug='professional', course_id=self.course_id) CourseEnrollment.unenroll(self.user, self.course_id) def tearDown(self): super().tearDown() self.user.delete() @ddt.data( ('audit', False), ('verified', True), ('masters', True), ('professional', True), ('no-id-professional', False), ) @ddt.unpack def test_proctoring_perm(self, mode, should_have_perm): """ Test that the user has the edx_proctoring.can_take_proctored_exam permission """ if mode is not None: CourseEnrollment.enroll(self.user, self.course_id, mode=mode) has_perm = self.user.has_perm('edx_proctoring.can_take_proctored_exam', {'course_id': str(self.course_id)}) assert has_perm == should_have_perm @patch.dict( 'django.conf.settings.PROCTORING_BACKENDS', {'mock_proctoring_allow_honor_mode': { 'allow_honor_mode': True }}) def test_proctoring_perm_with_honor_mode_permission(self): """ Test that the user has the edx_proctoring.can_take_proctored_exam permission in honor enrollment mode. If proctoring backend configuration allows exam in honor mode {`allow_honor_mode`: True} the user is granted proctored exam permission. """ course_allow_honor = CourseFactory( enable_proctored_exams=True, proctoring_provider='mock_proctoring_allow_honor_mode') CourseEnrollment.enroll(self.user, course_allow_honor.id, mode='honor') self.assertTrue( self.user.has_perm('edx_proctoring.can_take_proctored_exam', {'course_id': str(course_allow_honor.id)}))
class PermissionTests(TestCase): """ Tests for permissions defined in courseware.rules """ def setUp(self): super(PermissionTests, self).setUp() self.user = UserFactory() self.course_id = CourseLocator('MITx', '000', 'Perm_course') CourseModeFactory(mode_slug='verified', course_id=self.course_id) CourseModeFactory(mode_slug='masters', course_id=self.course_id) CourseModeFactory(mode_slug='professional', course_id=self.course_id) CourseEnrollment.unenroll(self.user, self.course_id) def tearDown(self): super(PermissionTests, self).tearDown() self.user.delete() @ddt.data( (None, False), ('audit', False), ('verified', True), ('masters', True), ('professional', True), ('no-id-professional', False), ) @ddt.unpack def test_proctoring_perm(self, mode, should_have_perm): """ Test that the user has the edx_proctoring.can_take_proctored_exam permission """ if mode is not None: CourseEnrollment.enroll(self.user, self.course_id, mode=mode) has_perm = self.user.has_perm('edx_proctoring.can_take_proctored_exam', {'course_id': six.text_type(self.course_id)}) assert has_perm == should_have_perm