Skip to content

Commit 9cde568

Browse files
test: add unittest for role assignment after content library creation
1 parent 8fad717 commit 9cde568

File tree

1 file changed

+24
-0
lines changed
  • openedx/core/djangoapps/content_libraries/tests

1 file changed

+24
-0
lines changed

openedx/core/djangoapps/content_libraries/tests/test_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
LIBRARY_COLLECTION_UPDATED,
2929
LIBRARY_CONTAINER_UPDATED,
3030
)
31+
from openedx_authz.api.users import get_user_role_assignments_in_scope
3132
from openedx_learning.api import authoring as authoring_api
3233

3334
from .. import api
@@ -1479,3 +1480,26 @@ def test_get_backup_task_status_failed(self) -> None:
14791480
assert status is not None
14801481
assert status['state'] == UserTaskStatus.FAILED
14811482
assert status['file'] is None
1483+
1484+
1485+
class ContentLibraryRoleAssignmentTest(ContentLibrariesRestApiTest):
1486+
"""
1487+
Tests for Content Library API role assignment methods.
1488+
"""
1489+
1490+
def setUp(self) -> None:
1491+
super().setUp()
1492+
1493+
# Create Content Libraries
1494+
self._create_library("test-lib-role-1", "Test Library Role 1")
1495+
1496+
# Fetch the created ContentLibrary objects so we can access their learning_package.id
1497+
self.lib1 = ContentLibrary.objects.get(slug="test-lib-role-1")
1498+
1499+
def test_assign_library_role_to_user(self) -> None:
1500+
"""Test assigning a library role to a user."""
1501+
api.assign_library_role_to_user(self.lib1.library_key, self.user, api.AccessLevel.ADMIN_LEVEL)
1502+
1503+
roles = get_user_role_assignments_in_scope(self.user.username, str(self.lib1.library_key))
1504+
assert len(roles) == 1
1505+
assert "library_admin" in repr(roles[0].roles[0])

0 commit comments

Comments
 (0)