33"""
44
55import logging
6+ from unittest .mock import Mock
67
78from django .utils .translation import gettext_lazy as _
8- from lms .djangoapps .courseware .masquerade import (
9- get_course_masquerade ,
10- get_masquerading_user_group ,
11- is_masquerading_as_specific_student ,
12- )
9+
10+ try :
11+ from lms .djangoapps .courseware .masquerade import (
12+ get_course_masquerade ,
13+ get_masquerading_user_group ,
14+ is_masquerading_as_specific_student ,
15+ )
16+ from openedx .core import types
17+ from xmodule .partitions .partitions import Group , UserPartition , UserPartitionError
18+ except ImportError :
19+ get_course_masquerade = Mock ()
20+ get_masquerading_user_group = Mock ()
21+ is_masquerading_as_specific_student = Mock ()
22+ types = Mock ()
23+ Group = Mock ()
24+
25+ class UserPartitionError (Exception ):
26+ """Mock UserPartitionError class for testing."""
27+
28+ class UserPartition :
29+ """Mock UserPartition class for testing."""
30+
31+ # pylint: disable=redefined-builtin, too-many-positional-arguments, unused-argument
32+ def __init__ (self , id , name , description , groups , scheme , parameters , active = True ):
33+ self .parameters = parameters
34+ self .scheme = scheme
35+ self .id = id
36+ self .name = name
37+ self .description = description
38+ self .active = active
39+
40+ @property
41+ def groups (self ):
42+ return self .groups
43+
44+
1345from opaque_keys .edx .keys import CourseKey
14- from openedx .core import types
15- from xmodule .partitions .partitions import Group , UserPartition , UserPartitionError
1646
1747from openedx_user_groups .models import UserGroup , UserGroupMembership
1848from openedx_user_groups .toggles import is_user_groups_enabled
@@ -31,7 +61,7 @@ class UserGroupPartition(UserPartition):
3161 """
3262
3363 @property
34- def groups (self ):
64+ def groups (self ) -> list [ Group ] :
3565 """
3666 Dynamically generate groups (based on user groups) for this partition.
3767 """
@@ -98,7 +128,7 @@ def get_group_for_user(
98128
99129 return user_groups
100130
101- # pylint: disable=redefined-builtin, invalid-name
131+ # pylint: disable=redefined-builtin, invalid-name, too-many-positional-arguments
102132 @classmethod
103133 def create_user_partition (
104134 cls ,
@@ -152,7 +182,7 @@ def create_user_partition(
152182 return user_group_partition
153183
154184
155- def create_user_group_partition_with_course_id (course_id ) :
185+ def create_user_group_partition_with_course_id (course_id : CourseKey ) -> UserPartition | None :
156186 """
157187 Create and return the user group partition based only on course_id.
158188 If it cannot be created, None is returned.
0 commit comments