Unverified Commit 9520fe03 by Adam Committed by GitHub

Merge pull request #16553 from edx/adam/fix-branch-versioning-issues-coursegraph

addresses issue where branch information was not being stripped from …
parents c411b6b8 25b4a6e2
...@@ -25,6 +25,7 @@ from openedx.core.djangoapps.coursegraph.tasks import ( ...@@ -25,6 +25,7 @@ from openedx.core.djangoapps.coursegraph.tasks import (
serialize_course, serialize_course,
coerce_types, coerce_types,
should_dump_course, should_dump_course,
strip_branch_and_version,
) )
from openedx.core.djangoapps.content.course_structures.signals import ( from openedx.core.djangoapps.content.course_structures.signals import (
listen_for_course_publish listen_for_course_publish
...@@ -262,6 +263,25 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): ...@@ -262,6 +263,25 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
# the course has 7 "PARENT_OF" relationships and 3 "PRECEDES" # the course has 7 "PARENT_OF" relationships and 3 "PRECEDES"
self.assertEqual(len(relationships), 10) 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 @staticmethod
def _extract_relationship_pairs(relationships, relationship_type): def _extract_relationship_pairs(relationships, relationship_type):
""" """
...@@ -503,7 +523,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase): ...@@ -503,7 +523,7 @@ class TestModuleStoreSerializer(TestDumpToNeo4jCommandBase):
""" """
mock_get_command_last_run.return_value = last_command_run mock_get_command_last_run.return_value = last_command_run
mock_get_course_last_published.return_value = last_course_published mock_get_course_last_published.return_value = last_course_published
mock_course_key = mock.Mock mock_course_key = mock.Mock()
mock_graph = mock.Mock() mock_graph = mock.Mock()
self.assertEqual( self.assertEqual(
should_dump_course(mock_course_key, mock_graph), should_dump_course(mock_course_key, mock_graph),
......
...@@ -145,6 +145,16 @@ def get_course_last_published(course_key): ...@@ -145,6 +145,16 @@ def get_course_last_published(course_key):
return course_last_published_date 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): def serialize_course(course_id):
""" """
Serializes a course into py2neo Nodes and Relationships Serializes a course into py2neo Nodes and Relationships
...@@ -171,15 +181,15 @@ def serialize_course(course_id): ...@@ -171,15 +181,15 @@ def serialize_course(course_id):
fields[field_name] = coerce_types(value) fields[field_name] = coerce_types(value)
node = Node(block_type, 'item', **fields) 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 # create relationships
relationships = [] relationships = []
for item in items: for item in items:
previous_child_node = None previous_child_node = None
for index, child in enumerate(item.get_children()): for index, child in enumerate(item.get_children()):
parent_node = location_to_node.get(item.location.version_agnostic()) parent_node = location_to_node.get(strip_branch_and_version(item.location))
child_node = location_to_node.get(child.location.version_agnostic()) child_node = location_to_node.get(strip_branch_and_version(child.location))
if parent_node is not None and child_node is not None: if parent_node is not None and child_node is not None:
child_node["index"] = index 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