Skip to content

Commit

Permalink
test: Update a BlockStructureFactory test mixin.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
feanil committed Jul 26, 2024
1 parent e8bc7e0 commit 88f76e1
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down

0 comments on commit 88f76e1

Please sign in to comment.