From 660cdf79c0f157ad6b0e84d9babc7d9a22eca0e1 Mon Sep 17 00:00:00 2001 From: Usman Khalid <2200617@gmail.com> Date: Thu, 11 Sep 2014 19:17:57 +0500 Subject: [PATCH] Added instructor persmission to _has_access_error_desc() in courseware.access. TNL-208 --- lms/djangoapps/courseware/access.py | 3 ++- .../courseware/tests/test_access.py | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lms/djangoapps/courseware/access.py b/lms/djangoapps/courseware/access.py index 57b7a3543a..9c900185ab 100644 --- a/lms/djangoapps/courseware/access.py +++ b/lms/djangoapps/courseware/access.py @@ -230,7 +230,8 @@ def _has_access_error_desc(user, action, descriptor, course_key): checkers = { 'load': check_for_staff, - 'staff': check_for_staff + 'staff': check_for_staff, + 'instructor': lambda: _has_instructor_access_to_descriptor(user, descriptor, course_key) } return _dispatch(checkers, action, user, descriptor) diff --git a/lms/djangoapps/courseware/tests/test_access.py b/lms/djangoapps/courseware/tests/test_access.py index 74a03099c0..aa92ce31d6 100644 --- a/lms/djangoapps/courseware/tests/test_access.py +++ b/lms/djangoapps/courseware/tests/test_access.py @@ -83,17 +83,34 @@ class AccessTestCase(TestCase): self.assertRaises(ValueError, access._has_access_string, user, 'not_staff', 'global', self.course.course_key) + def test__has_access_error_desc(self): + descriptor = Mock() + + self.assertFalse(access._has_access_error_desc(self.student, 'load', descriptor, self.course.course_key)) + self.assertTrue(access._has_access_error_desc(self.course_staff, 'load', descriptor, self.course.course_key)) + self.assertTrue(access._has_access_error_desc(self.course_instructor, 'load', descriptor, self.course.course_key)) + + self.assertFalse(access._has_access_error_desc(self.student, 'staff', descriptor, self.course.course_key)) + self.assertTrue(access._has_access_error_desc(self.course_staff, 'staff', descriptor, self.course.course_key)) + self.assertTrue(access._has_access_error_desc(self.course_instructor, 'staff', descriptor, self.course.course_key)) + + self.assertFalse(access._has_access_error_desc(self.student, 'instructor', descriptor, self.course.course_key)) + self.assertFalse(access._has_access_error_desc(self.course_staff, 'instructor', descriptor, self.course.course_key)) + self.assertTrue(access._has_access_error_desc(self.course_instructor, 'instructor', descriptor, self.course.course_key)) + + with self.assertRaises(ValueError): + access._has_access_error_desc(self.course_instructor, 'not_load_or_staff', descriptor, self.course.course_key) + def test__has_access_descriptor(self): # TODO: override DISABLE_START_DATES and test the start date branch of the method user = Mock() - date = Mock() - date.start = datetime.datetime.now(pytz.utc) - datetime.timedelta(days=1) # make sure the start time is in the past + descriptor = Mock() # Always returns true because DISABLE_START_DATES is set in test.py - self.assertTrue(access._has_access_descriptor(user, 'load', date)) - self.assertTrue(access._has_access_descriptor(user, 'instructor', date)) + self.assertTrue(access._has_access_descriptor(user, 'load', descriptor)) + self.assertTrue(access._has_access_descriptor(user, 'instructor', descriptor)) with self.assertRaises(ValueError): - access._has_access_descriptor(user, 'not_load_or_staff', date) + access._has_access_descriptor(user, 'not_load_or_staff', descriptor) @mock.patch.dict('django.conf.settings.FEATURES', {'DISABLE_START_DATES': False}) def test__has_access_descriptor_staff_lock(self):