From 88f76e1b0ba9337aaa8d50f613eb2d2a3d931ba7 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 26 Jul 2024 15:03:24 -0400 Subject: [PATCH] test: Update a BlockStructureFactory test mixin. Previously, we were not caching BlockStructures to the database when we were adding them to the store by default. Now that we are doing that, the BlockStructureFactory test failed because it was taking a shortcut that would no longer work. It was just creating a blockstructure that had relations but not any block information. Now that we're always persisting updates to the database, this broke because to persist the structure to the database, we have to look up the block information from the block_structure which now fails. This change updates the test mixin to add more data so that the content can be persisted to the database successfully as a part of this test. --- .../djangoapps/content/block_structure/tests/helpers.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openedx/core/djangoapps/content/block_structure/tests/helpers.py b/openedx/core/djangoapps/content/block_structure/tests/helpers.py index 93655c79e16e..84c99d71e1f0 100644 --- a/openedx/core/djangoapps/content/block_structure/tests/helpers.py +++ b/openedx/core/djangoapps/content/block_structure/tests/helpers.py @@ -7,6 +7,7 @@ from uuid import uuid4 from unittest.mock import patch +from opaque_keys.edx.keys import CourseKey from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator from xmodule.modulestore.exceptions import ItemNotFoundError @@ -264,7 +265,7 @@ def block_key_factory(self, block_id): Override this method if the block_key should be anything different from the index integer values in the Children Maps. """ - return block_id + return CourseKey.from_string("course-v1:org+course+run").make_usage_key("html", str(block_id)) def create_block_structure(self, children_map, block_structure_cls=BlockStructureBlockData): """ @@ -274,10 +275,12 @@ def create_block_structure(self, children_map, block_structure_cls=BlockStructur # create empty block structure block_structure = block_structure_cls(root_block_usage_key=self.block_key_factory(0)) - # _add_relation + # _add_relation and blocks for parent, children in enumerate(children_map): + block_structure._get_or_create_block(self.block_key_factory(parent)) for child in children: block_structure._add_relation(self.block_key_factory(parent), self.block_key_factory(child)) # pylint: disable=protected-access + block_structure._get_or_create_block(self.block_key_factory(child)) return block_structure def get_parents_map(self, children_map):