forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c012fc
commit 003816e
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
""" | ||
Tests for permissions defined in courseware.rules | ||
""" | ||
from common.djangoapps.student.roles import OrgStaffRole, CourseStaffRole | ||
from common.djangoapps.student.tests.factories import UserFactory | ||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order | ||
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order | ||
from lms.djangoapps.course_home_api.permissions import CAN_MASQUARADE_LEARNER_PROGRESS | ||
|
||
|
||
class PermissionTests(ModuleStoreTestCase): | ||
""" | ||
Tests for permissions defined in courseware.rules | ||
""" | ||
def setUp(self): | ||
super().setUp() | ||
self.user = UserFactory() | ||
self.course = CourseFactory(org='org') | ||
self.another_course = CourseFactory(org='org') | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.user.delete() | ||
|
||
def test_can_masquarade_return_value(self): | ||
""" | ||
Test that only staff users should have masquarade access | ||
""" | ||
self.user.is_staff = True | ||
self.user.save() | ||
assert self.user.is_staff is True | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is True, "Global staff users should have masquarade access" | ||
|
||
self.user.is_staff = False | ||
self.user.save() | ||
assert self.user.is_staff is False | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is False, "Non staff users shouldn't have masquarade access" | ||
|
||
OrgStaffRole('another_org').add_users(self.user) | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is False, "User with staff access on another org shouldn't have masquarade access" | ||
|
||
OrgStaffRole('org').add_users(self.user) | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is True, "User with org wide staff, should have masquarade access" | ||
OrgStaffRole('org').remove_users(self.user) | ||
|
||
CourseStaffRole(self.another_course.id).add_users(self.user) | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is False, "User with staff access on another course shouldn't have masquarade access" | ||
|
||
CourseStaffRole(self.course.id).add_users(self.user) | ||
has_perm = self.user.has_perm(CAN_MASQUARADE_LEARNER_PROGRESS, self.course.id) | ||
assert has_perm is True, "User with staff access on course should have masquarade access" |