Skip to content

Commit

Permalink
fix: tests and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
monteri committed Jan 31, 2024
1 parent 8b8f71e commit 6229101
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ class ChildVerticalContainerSerializer(serializers.Serializer):
Serializer for representing a xblock child of vertical container.
"""

name = serializers.CharField(source="display_name_with_default")
block_id = serializers.CharField(source="location")
block_type = serializers.CharField(source="location.block_type")
name = serializers.CharField()
block_id = serializers.CharField()
block_type = serializers.CharField()
actions = serializers.SerializerMethodField()
user_partition_info = serializers.DictField()
user_partitions = serializers.ListField()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework import status

from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID
from xmodule.modulestore.django import (
modulestore,
) # lint-amnesty, pylint: disable=wrong-import-order
Expand Down Expand Up @@ -154,6 +155,28 @@ def test_children_content(self):
url = self.get_reverse_url(self.vertical.location)
response = self.client.get(url)

expected_user_partition_info = {
"selectable_partitions": [],
"selected_partition_index": -1,
"selected_groups_label": ""
}

expected_user_partitions = [
{
"id": ENROLLMENT_TRACK_PARTITION_ID,
"name": "Enrollment Track Groups",
"scheme": "enrollment_track",
"groups": [
{
"id": 1,
"name": "Audit",
"selected": False,
"deleted": False
}
]
}
]

expected_response = [
{
"name": self.html_unit_first.display_name_with_default,
Expand All @@ -165,7 +188,9 @@ def test_children_content(self):
"can_move": True,
"can_manage_access": True,
"can_delete": True
}
},
"user_partition_info": expected_user_partition_info,
"user_partitions": expected_user_partitions
},
{
"name": self.html_unit_second.display_name_with_default,
Expand All @@ -177,7 +202,9 @@ def test_children_content(self):
"can_move": True,
"can_manage_access": True,
"can_delete": True
}
},
"user_partition_info": expected_user_partition_info,
"user_partitions": expected_user_partitions,
},
]
self.assertEqual(response.data["children"], expected_response)
Expand Down
14 changes: 9 additions & 5 deletions cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,22 @@ def get(self, request: Request, usage_key_string: str):
"""
usage_key = self.get_object(usage_key_string)
current_xblock = get_xblock(usage_key, request.user)
# load course once to reuse it for user_partitions query
course = modulestore().get_course(current_xblock.location.course_key)

with modulestore().bulk_operations(usage_key.course_key):
# load course once to reuse it for user_partitions query
course = modulestore().get_course(current_xblock.location.course_key)
children = []
for child in current_xblock.children:
child_info = modulestore().get_item(child)
user_partition_info = get_visibility_partition_info(child_info, course=course)
user_partitions = get_user_partition_info(child_info, course=course)
setattr(child_info, 'user_partition_info', user_partition_info)
setattr(child_info, 'user_partitions', user_partitions)
children.append(child_info)
children.append({
"name": child_info.display_name_with_default,
"block_id": child_info.location,
"block_type": child_info.location.block_type,
"user_partition_info": user_partition_info,
"user_partitions": user_partitions,
})

is_published = not modulestore().has_changes(current_xblock)
container_data = {"children": children, "is_published": is_published}
Expand Down

0 comments on commit 6229101

Please sign in to comment.