Skip to content

Commit

Permalink
refactor: rename minimum partition ID constant to be more generic
Browse files Browse the repository at this point in the history
Rename MINIMUM_STATIC_PARTITION_ID to MINIMUM_UNUSED_PARTITION_ID
so it's not confusing when used to generate IDs for static or dynamic
partitions.
  • Loading branch information
mariajgrimaldi committed Apr 17, 2024
1 parent 96f6349 commit 7ac4df3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/course_group_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
from common.djangoapps.util.db import MYSQL_MAX_INT, generate_int_id
from lms.lib.utils import get_parent_unit
from openedx.core.djangoapps.course_groups.partition_scheme import get_cohorted_user_partition
from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, ReadOnlyUserPartitionError, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, ReadOnlyUserPartitionError, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions_service import get_all_partitions_for_course # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.split_test_block import get_split_user_partitions # lint-amnesty, pylint: disable=wrong-import-order

MINIMUM_GROUP_ID = MINIMUM_STATIC_PARTITION_ID
MINIMUM_GROUP_ID = MINIMUM_UNUSED_PARTITION_ID

RANDOM_SCHEME = "random"
COHORT_SCHEME = "cohort"
Expand Down
32 changes: 16 additions & 16 deletions cms/djangoapps/contentstore/views/tests/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
)
from xmodule.partitions.partitions import (
ENROLLMENT_TRACK_PARTITION_ID,
MINIMUM_STATIC_PARTITION_ID,
MINIMUM_UNUSED_PARTITION_ID,
Group,
UserPartition,
)
Expand Down Expand Up @@ -424,16 +424,16 @@ def test_get_user_partitions_and_groups(self):
# by dynamic user partitions.
self.course.user_partitions = [
UserPartition(
id=MINIMUM_STATIC_PARTITION_ID,
id=MINIMUM_UNUSED_PARTITION_ID,
name="Random user partition",
scheme=UserPartition.get_scheme("random"),
description="Random user partition",
groups=[
Group(
id=MINIMUM_STATIC_PARTITION_ID + 1, name="Group A"
id=MINIMUM_UNUSED_PARTITION_ID + 1, name="Group A"
), # See note above.
Group(
id=MINIMUM_STATIC_PARTITION_ID + 2, name="Group B"
id=MINIMUM_UNUSED_PARTITION_ID + 2, name="Group B"
), # See note above.
],
),
Expand Down Expand Up @@ -465,18 +465,18 @@ def test_get_user_partitions_and_groups(self):
],
},
{
"id": MINIMUM_STATIC_PARTITION_ID,
"id": MINIMUM_UNUSED_PARTITION_ID,
"name": "Random user partition",
"scheme": "random",
"groups": [
{
"id": MINIMUM_STATIC_PARTITION_ID + 1,
"id": MINIMUM_UNUSED_PARTITION_ID + 1,
"name": "Group A",
"selected": False,
"deleted": False,
},
{
"id": MINIMUM_STATIC_PARTITION_ID + 2,
"id": MINIMUM_UNUSED_PARTITION_ID + 2,
"name": "Group B",
"selected": False,
"deleted": False,
Expand Down Expand Up @@ -2446,13 +2446,13 @@ def setUp(self):
self.user = UserFactory()

self.first_user_partition_group_1 = Group(
str(MINIMUM_STATIC_PARTITION_ID + 1), "alpha"
str(MINIMUM_UNUSED_PARTITION_ID + 1), "alpha"
)
self.first_user_partition_group_2 = Group(
str(MINIMUM_STATIC_PARTITION_ID + 2), "beta"
str(MINIMUM_UNUSED_PARTITION_ID + 2), "beta"
)
self.first_user_partition = UserPartition(
MINIMUM_STATIC_PARTITION_ID,
MINIMUM_UNUSED_PARTITION_ID,
"first_partition",
"First Partition",
[self.first_user_partition_group_1, self.first_user_partition_group_2],
Expand All @@ -2461,16 +2461,16 @@ def setUp(self):
# There is a test point below (test_create_groups) that purposefully wants the group IDs
# of the 2 partitions to overlap (which is not something that normally happens).
self.second_user_partition_group_1 = Group(
str(MINIMUM_STATIC_PARTITION_ID + 1), "Group 1"
str(MINIMUM_UNUSED_PARTITION_ID + 1), "Group 1"
)
self.second_user_partition_group_2 = Group(
str(MINIMUM_STATIC_PARTITION_ID + 2), "Group 2"
str(MINIMUM_UNUSED_PARTITION_ID + 2), "Group 2"
)
self.second_user_partition_group_3 = Group(
str(MINIMUM_STATIC_PARTITION_ID + 3), "Group 3"
str(MINIMUM_UNUSED_PARTITION_ID + 3), "Group 3"
)
self.second_user_partition = UserPartition(
MINIMUM_STATIC_PARTITION_ID + 10,
MINIMUM_UNUSED_PARTITION_ID + 10,
"second_partition",
"Second Partition",
[
Expand Down Expand Up @@ -2543,10 +2543,10 @@ def test_create_groups(self):
self.assertEqual("vertical", vertical_0.category)
self.assertEqual("vertical", vertical_1.category)
self.assertEqual(
"Group ID " + str(MINIMUM_STATIC_PARTITION_ID + 1), vertical_0.display_name
"Group ID " + str(MINIMUM_UNUSED_PARTITION_ID + 1), vertical_0.display_name
)
self.assertEqual(
"Group ID " + str(MINIMUM_STATIC_PARTITION_ID + 2), vertical_1.display_name
"Group ID " + str(MINIMUM_UNUSED_PARTITION_ID + 2), vertical_1.display_name
)

# Verify that the group_id_to_child mapping is correct.
Expand Down
4 changes: 2 additions & 2 deletions cms/lib/xblock/test/test_authoring_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
from xmodule.partitions.partitions import (
ENROLLMENT_TRACK_PARTITION_ID,
MINIMUM_STATIC_PARTITION_ID,
MINIMUM_UNUSED_PARTITION_ID,
Group,
UserPartition
)
Expand Down Expand Up @@ -78,7 +78,7 @@ def create_content_groups(self, content_groups):
"""
# pylint: disable=attribute-defined-outside-init
self.content_partition = UserPartition(
MINIMUM_STATIC_PARTITION_ID,
MINIMUM_UNUSED_PARTITION_ID,
self.CONTENT_GROUPS_TITLE,
'Contains Groups for Cohorted Courseware',
content_groups,
Expand Down
8 changes: 4 additions & 4 deletions lms/djangoapps/courseware/tests/test_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
SharedModuleStoreTestCase
)
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, Group, UserPartition # lint-amnesty, pylint: disable=wrong-import-order
from openedx.features.enterprise_support.api import add_enterprise_customer_to_session
from enterprise.api.v1.serializers import EnterpriseCustomerSerializer
from openedx.features.enterprise_support.tests.factories import (
Expand Down Expand Up @@ -288,9 +288,9 @@ def test_has_access_in_preview_mode_with_group(self):
"""
# Note about UserPartition and UserPartition Group IDs: these must not conflict with IDs used
# by dynamic user partitions.
partition_id = MINIMUM_STATIC_PARTITION_ID
group_0_id = MINIMUM_STATIC_PARTITION_ID + 1
group_1_id = MINIMUM_STATIC_PARTITION_ID + 2
partition_id = MINIMUM_UNUSED_PARTITION_ID
group_0_id = MINIMUM_UNUSED_PARTITION_ID + 1
group_1_id = MINIMUM_UNUSED_PARTITION_ID + 2
user_partition = UserPartition(
partition_id, 'Test User Partition', '',
[Group(group_0_id, 'Group 1'), Group(group_1_id, 'Group 2')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from common.djangoapps.student.tests.factories import UserFactory
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import CourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, UserPartition, ReadOnlyUserPartitionError # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, UserPartition, ReadOnlyUserPartitionError # lint-amnesty, pylint: disable=wrong-import-order

from ..partition_scheme import ENROLLMENT_GROUP_IDS, EnrollmentTrackPartitionScheme, EnrollmentTrackUserPartition

Expand Down Expand Up @@ -63,11 +63,11 @@ def test_from_json_not_supported(self):

def test_group_ids(self):
"""
Test that group IDs are all less than MINIMUM_STATIC_PARTITION_ID (to avoid overlapping
Test that group IDs are all less than MINIMUM_UNUSED_PARTITION_ID (to avoid overlapping
with group IDs associated with cohort and random user partitions).
"""
for mode in ENROLLMENT_GROUP_IDS:
assert ENROLLMENT_GROUP_IDS[mode]['id'] < MINIMUM_STATIC_PARTITION_ID
assert ENROLLMENT_GROUP_IDS[mode]['id'] < MINIMUM_UNUSED_PARTITION_ID

@staticmethod
def get_group_by_name(partition, name):
Expand Down
2 changes: 1 addition & 1 deletion xmodule/partitions/partitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# ID is stored in the xblock group_access dict).
ENROLLMENT_TRACK_PARTITION_ID = 50

MINIMUM_STATIC_PARTITION_ID = 100
MINIMUM_UNUSED_PARTITION_ID = 100


class UserPartitionError(Exception):
Expand Down
8 changes: 4 additions & 4 deletions xmodule/tests/test_split_test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from xmodule.modulestore.tests.factories import CourseFactory
from xmodule.modulestore.tests.utils import MixedSplitTestCase
from xmodule.partitions.partitions import MINIMUM_STATIC_PARTITION_ID, Group, UserPartition
from xmodule.partitions.partitions import MINIMUM_UNUSED_PARTITION_ID, Group, UserPartition
from xmodule.partitions.tests.test_partitions import MockPartitionService, MockUserPartitionScheme, PartitionTestCase
from xmodule.split_test_block import (
SplitTestBlock,
Expand Down Expand Up @@ -94,10 +94,10 @@ def setUp(self):
self.course.user_partitions = [
self.user_partition,
UserPartition(
MINIMUM_STATIC_PARTITION_ID, 'second_partition', 'Second Partition',
MINIMUM_UNUSED_PARTITION_ID, 'second_partition', 'Second Partition',
[
Group(str(MINIMUM_STATIC_PARTITION_ID + 1), 'abel'),
Group(str(MINIMUM_STATIC_PARTITION_ID + 2), 'baker'), Group("103", 'charlie')
Group(str(MINIMUM_UNUSED_PARTITION_ID + 1), 'abel'),
Group(str(MINIMUM_UNUSED_PARTITION_ID + 2), 'baker'), Group("103", 'charlie')
],
MockUserPartitionScheme()
)
Expand Down

0 comments on commit 7ac4df3

Please sign in to comment.