Skip to content

Commit 4dfdb3a

Browse files
committed
refactor: update role assertion methods
1 parent 6055a3d commit 4dfdb3a

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

common/djangoapps/student/tests/test_roles.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,24 @@ def test_get_authz_compat_course_access_roles_for_user_org_scope(self):
319319
with patch("openedx_authz.api.users.get_user_role_assignments", return_value=[assignment]):
320320
result = get_authz_compat_course_access_roles_for_user(self.student)
321321

322-
assert result == {
323-
AuthzCompatCourseAccessRole(
324-
user_id=self.student.id,
325-
username=self.student.username,
326-
org="OpenedX",
327-
course_id=None,
328-
role="instructor",
329-
)
330-
}
322+
self.assertCountEqual( # noqa: PT009
323+
result,
324+
{
325+
AuthzCompatCourseAccessRole(
326+
user_id=self.student.id,
327+
username=self.student.username,
328+
org="OpenedX",
329+
course_id=None,
330+
role="instructor",
331+
)
332+
},
333+
)
331334

332335
def test_org_scope_authz_role_grants_instructor_dashboard_permissions(self):
333336
"""
334337
Org-wide AuthZ course_admin should grant legacy org instructor access used by the instructor dashboard.
335338
"""
339+
# pylint: disable=protected-access
336340
course_key = CourseKey.from_string("course-v1:OpenedX+DemoX+DemoCourse")
337341
org_scope = OrgCourseOverviewGlobData(external_key="course-v1:OpenedX+*")
338342
assignment = RoleAssignmentData(
@@ -343,12 +347,12 @@ def test_org_scope_authz_role_grants_instructor_dashboard_permissions(self):
343347
with patch("openedx_authz.api.users.get_user_role_assignments", return_value=[assignment]):
344348
if hasattr(self.student, "_roles"):
345349
del self.student._roles
346-
cache = RoleCache(self.student)
350+
self.student._roles = RoleCache(self.student)
347351

348-
assert cache.has_role("instructor", None, "OpenedX")
349-
assert OrgInstructorRole("OpenedX").has_user(self.student)
350-
assert self.student.has_perm(instructor_permissions.VIEW_DASHBOARD, course_key)
351-
assert self.student.has_perm(instructor_permissions.SHOW_TASKS, course_key)
352+
self.assertTrue(self.student._roles.has_role("instructor", None, "OpenedX")) # noqa: PT009
353+
self.assertTrue(OrgInstructorRole("OpenedX").has_user(self.student)) # noqa: PT009
354+
self.assertTrue(self.student.has_perm(instructor_permissions.VIEW_DASHBOARD, course_key)) # noqa: PT009
355+
self.assertTrue(self.student.has_perm(instructor_permissions.SHOW_TASKS, course_key)) # noqa: PT009
352356

353357

354358
@ddt.ddt

0 commit comments

Comments
 (0)