Skip to content

Commit d43e7bf

Browse files
committed
feat: add utility function to create namespaced course keys
1 parent ae22641 commit d43e7bf

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

openedx_authz/tests/test_utils.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
"""Test utilities for creating namespaced keys using class constants."""
22

3-
from openedx_authz.api.data import GLOBAL_SCOPE_WILDCARD, ActionData, ContentLibraryData, RoleData, ScopeData, UserData
3+
from openedx_authz.api.data import (
4+
GLOBAL_SCOPE_WILDCARD,
5+
ActionData,
6+
ContentLibraryData,
7+
CourseOverviewData,
8+
RoleData,
9+
ScopeData,
10+
UserData,
11+
)
412

513

614
def make_user_key(key: str) -> str:
@@ -51,6 +59,18 @@ def make_library_key(key: str) -> str:
5159
return f"{ContentLibraryData.NAMESPACE}{ContentLibraryData.SEPARATOR}{key}"
5260

5361

62+
def make_course_key(key: str) -> str:
63+
"""Create a namespaced course key.
64+
65+
Args:
66+
key: The course identifier (e.g., 'course-v1:DemoX+DemoCourse+2026_T1')
67+
68+
Returns:
69+
str: Namespaced course key (e.g., 'course-v1^course-v1:DemoX+DemoCourse+2026_T1')
70+
"""
71+
return f"{CourseOverviewData.NAMESPACE}{CourseOverviewData.SEPARATOR}{key}"
72+
73+
5474
def make_scope_key(namespace: str, key: str) -> str:
5575
"""Create a namespaced scope key with custom namespace.
5676

0 commit comments

Comments
 (0)