Commit 25b4a6e2 by Adam Palay

addresses issue where branch information was not being stripped from child…

addresses issue where branch information was not being stripped from child blocks when serializing courses (PLAT-1794)
parent 801a948d
......@@ -25,6 +25,7 @@ from openedx.core.djangoapps.coursegraph.tasks import (
serialize_course,
coerce_types,
should_dump_course,
strip_branch_and_version,
)
from openedx.core.djangoapps.content.course_structures.signals import (
listen_for_course_publish
......@@ -262,6 +263,25 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
# the course has 7 "PARENT_OF" relationships and 3 "PRECEDES"
self.assertEqual(len(relationships), 10)
def test_strip_version_and_branch(self):
"""
Tests that the _strip_version_and_branch function strips the version
and branch from a location
"""
location = self.course.id.make_usage_key(
'test_block_type', 'test_block_id'
).for_branch(
'test_branch'
).for_version('test_version')
self.assertIsNotNone(location.branch)
self.assertIsNotNone(location.version)
stripped_location = strip_branch_and_version(location)
self.assertIsNone(stripped_location.branch)
self.assertIsNone(stripped_location.version)
@staticmethod
def _extract_relationship_pairs(relationships, relationship_type):
"""
......@@ -503,7 +523,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
"""
mock_get_command_last_run.return_value = last_command_run
mock_get_course_last_published.return_value = last_course_published
mock_course_key = mock.Mock
mock_course_key = mock.Mock()
mock_graph = mock.Mock()
self.assertEqual(
should_dump_course(mock_course_key, mock_graph),
......
......@@ -144,6 +144,16 @@ def get_course_last_published(course_key):
return course_last_published_date
def strip_branch_and_version(location):
"""
Removes the branch and version information from a location.
Args:
location: an xblock's location.
Returns: that xblock's location without branch and version information.
"""
return location.for_branch(None)
def serialize_course(course_id):
"""
Serializes a course into py2neo Nodes and Relationships
......@@ -170,15 +180,15 @@ def serialize_course(course_id):
fields[field_name] = coerce_types(value)
node = Node(block_type, 'item', **fields)
location_to_node[item.location.version_agnostic()] = node
location_to_node[strip_branch_and_version(item.location)] = node
# create relationships
relationships = []
for item in items:
previous_child_node = None
for index, child in enumerate(item.get_children()):
parent_node = location_to_node.get(item.location.version_agnostic())
child_node = location_to_node.get(child.location.version_agnostic())
parent_node = location_to_node.get(strip_branch_and_version(item.location))
child_node = location_to_node.get(strip_branch_and_version(child.location))
if parent_node is not None and child_node is not None:
child_node["index"] = index
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment