Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions cms/lib/xblock/tagging/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.test.client import RequestFactory
from lxml import etree
from opaque_keys.edx.asides import AsideUsageKeyV1, AsideUsageKeyV2
from xblock.fields import ScopeIds
from opaque_keys.edx.keys import CourseKey
from xblock.runtime import DictKeyValueStore, KvsFieldData
from xblock.test.tools import TestRuntime

Expand All @@ -31,6 +31,7 @@
BlockFactory,
CourseFactory,
)
from xmodule.tests import make_test_scope_ids # pylint: disable=wrong-import-order


@ddt.ddt
Expand Down Expand Up @@ -122,10 +123,12 @@ def test_aside_contains_tags(self):
"""
Checks that available_tags list is not empty
"""
sids = ScopeIds(user_id="bob",
block_type="bobs-type",
def_id="definition-id",
usage_id="usage-id")
sids = make_test_scope_ids(
"bobs-type",
"usage-id",
course_key=CourseKey.from_string("course-v1:myOrg+myCourse+myRun"),
user_id="bob",
)
key_store = DictKeyValueStore()
field_data = KvsFieldData(key_store)
runtime = TestRuntime(services={'field-data': field_data})
Expand Down
4 changes: 2 additions & 2 deletions lms/djangoapps/courseware/tests/test_discussion_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from openedx.core.djangoapps.discussions.services import DiscussionConfigService
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import BlockFactory, ToyCourseFactory
from xmodule.tests import make_test_scope_ids
from xmodule.tests.helpers import mock_render_template


Expand All @@ -52,8 +53,7 @@ def setUp(self):
self.data = DictFieldData({
'discussion_id': self.discussion_id
})
scope_ids = mock.Mock()
scope_ids.usage_id.context_key = self.course_id
scope_ids = make_test_scope_ids('discussion', 'test_discussion', course_key=self.course_id)
self.block = DiscussionXBlock(
self.runtime,
field_data=self.data,
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/tests/test_video_mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def instantiate_block(**field_data):
usage_key = course_key.make_usage_key('video', 'SampleProblem')
return system.construct_xblock_from_class(
VideoBlock,
scope_ids=ScopeIds(None, None, usage_key, usage_key),
scope_ids=ScopeIds(None, 'video', usage_key, usage_key),
field_data=DictFieldData(field_data),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def instantiate_video_block(self, **field_data):
usage_key = course_key.make_usage_key('video', 'SampleProblem')
return system.construct_xblock_from_class(
VideoBlock,
scope_ids=ScopeIds(None, None, usage_key, usage_key),
scope_ids=ScopeIds(None, 'video', usage_key, usage_key),
field_data=DictFieldData(field_data),
)

Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/xblock/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from xblock.exceptions import NoSuchServiceError
from xblock.field_data import DictFieldData, FieldData, SplitFieldData
from xblock.fields import Scope, ScopeIds
from xblock.runtime import IdReader, KvsFieldData, MemoryIdManager, Runtime
from xblock.runtime import IdReader, KvsFieldData, Runtime

from common.djangoapps.edxmako.services import MakoService
from common.djangoapps.static_replace.services import ReplaceURLService
Expand Down Expand Up @@ -130,7 +130,7 @@ def __init__(
),
default_class=None,
select=None,
id_generator=MemoryIdManager(), # We don't really use id_generator until we need to support asides
id_generator=None, # We won't need an id_generator until we need to support asides
)
assert student_data_mode in (StudentDataMode.Ephemeral, StudentDataMode.Persisted)
self.authored_data_mode = authored_data_mode
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ default-groups = [] # explicit, not omitted -- uv's own default-groups fallback
# tested at once, list them here as one set, e.g. [[{ group = "django52" }, { group = "django60" }]],
# otherwise uv refuses to resolve both into one lock.
conflicts = []
# TEMP: Kyle's XBlock fork (see [tool.uv.sources] below) has no git tags, so setuptools-scm
# would build it as version 0.0. Give the build a version explicitly. Remove together
# with the xblock source once https://github.com/openedx/XBlock/pull/809 is released.
extra-build-variables = { xblock = { SETUPTOOLS_SCM_PRETEND_VERSION = "6.3.5" } }

# DO NOT EDIT constraint-dependencies DIRECTLY.
# This list is managed by `edx_lint write_uv_constraints` and will be
Expand Down Expand Up @@ -290,6 +294,12 @@ constraint-dependencies = [
"pytest<9.2.0",
"lti-consumer-xblock==11.5.1",
]

[tool.uv.sources]
# TEMP: test against the unreleased XBlock change that mandates OpaqueKey scope IDs
# (https://github.com/openedx/XBlock/pull/809). Remove once it is released to PyPI.
xblock = { git = "https://github.com/kdmccormick/XBlock.git", branch = "kdmccormick/scope-id-types" }

[tool.edx_lint]
uv_constraints = [
# Date: 2025-10-07
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ wrapt==2.5.2
# via
# openedx-platform
# xblocks-core
xblock==6.3.5
xblock @ git+https://github.com/kdmccormick/XBlock.git@ad65b7255ab68b3f274c048ea8a79a91a129aea3
# via
# acid-xblock
# crowdsourcehinter-xblock
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ wrapt==2.5.2
# via
# openedx-platform
# xblocks-core
xblock==6.3.5
xblock @ git+https://github.com/kdmccormick/XBlock.git@ad65b7255ab68b3f274c048ea8a79a91a129aea3
# via
# acid-xblock
# crowdsourcehinter-xblock
Expand Down
8 changes: 2 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion xmodule/modulestore/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
get_root_module_name,
get_xblock_root_module_name,
)
from xmodule.tests import make_test_scope_ids


def test_get_root_module_name():
Expand All @@ -43,7 +44,7 @@ def test_get_xblock_root_module_name():
})
runtime = TestRuntime(Mock(), mixins=[TestSimpleMixin], services={'field-data': field_data})

mixed_done_xblock = runtime.construct_xblock_from_class(DoneXBlock, Mock())
mixed_done_xblock = runtime.construct_xblock_from_class(DoneXBlock, make_test_scope_ids('done'))

assert mixed_done_xblock.__module__ == 'xblock.core'
assert mixed_done_xblock.unmixed_class == DoneXBlock, 'The unmixed_class property retains the original property.'
Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import ddt
from django.utils.timezone import now, timedelta
from xblock.core import XBlock
from xblock.fields import ScopeIds
from xblock.test.tools import TestRuntime

from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.tests import make_test_scope_ids


class TestXBlock(XBlock):
Expand All @@ -36,7 +36,7 @@ def setUp(self):
Mock(entry_point=XBlock.entry_point), mixins=[InheritanceMixin], services={'field-data': {}}
)
self.xblock = runtime.construct_xblock_from_class(
TestXBlock, ScopeIds('user', 'TestXBlock', 'def_id', 'usage_id')
TestXBlock, make_test_scope_ids('TestXBlock', user_id='user')
)
super().setUp()

Expand Down
4 changes: 2 additions & 2 deletions xmodule/modulestore/tests/test_semantics.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ def _do_create(self, block_type, with_asides=False):
block.fields[test_data.field_name].write_to(block, initial_field_value)
asides = []
if with_asides:
asides = self._prepare_asides(self.course.scope_ids.usage_id)
asides = self._prepare_asides(self.course.scope_ids)
self.store.update_item(block, ModuleStoreEnum.UserID.test, asides=asides, allow_not_found=True)
else:
asides = []
if with_asides:
asides = self._prepare_asides(self.course.scope_ids.usage_id)
asides = self._prepare_asides(self.course.scope_ids)
self.store.create_child(
user_id=ModuleStoreEnum.UserID.test,
parent_usage_key=self.course.scope_ids.usage_id,
Expand Down
6 changes: 3 additions & 3 deletions xmodule/modulestore/tests/test_xml_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
from path import Path as path
from xblock.fields import List, Scope, ScopeIds, String
from xblock.fields import List, Scope, String
from xblock.runtime import DictKeyValueStore, KvsFieldData, Runtime

from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.modulestore.tests.mongo_connection import MONGO_HOST, MONGO_PORT_NUM
from xmodule.modulestore.xml_importer import StaticContentImporter, _update_and_import_block, _update_block_location
from xmodule.tests import DATA_DIR
from xmodule.tests import DATA_DIR, make_test_scope_ids
from xmodule.x_module import XModuleMixin

OPEN_BUILTIN = 'builtins.open'
Expand Down Expand Up @@ -156,7 +156,7 @@ def setUp(self):
"""
self.runtime = mock.MagicMock(Runtime)
self.field_data = KvsFieldData(kvs=DictKeyValueStore())
self.scope_ids = ScopeIds('Bob', 'mutablestubxblock', '123', 'import')
self.scope_ids = make_test_scope_ids('mutablestubxblock', 'import', user_id='Bob')
self.xblock = StubXBlockWithMutableFields(self.runtime, self.field_data, self.scope_ids)

self.fake_children_locations = [
Expand Down
16 changes: 14 additions & 2 deletions xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def get_test_system(
descriptor_system = get_test_descriptor_system(id_reader=id_manager, id_generator=id_manager)

if not user:
user = Mock(name='get_test_system.user', is_staff=False)
user = Mock(name='get_test_system.user', is_staff=False, id=1)
if not user_location:
user_location = Mock(name='get_test_system.user_location')
user_service = StubUserService(
Expand Down Expand Up @@ -185,7 +185,7 @@ def prepare_block_runtime(
"""

if not user:
user = Mock(name='get_test_system.user', is_staff=False)
user = Mock(name='get_test_system.user', is_staff=False, id=1)
if not user_location:
user_location = Mock(name='get_test_system.user_location')
user_service = StubUserService(
Expand Down Expand Up @@ -241,6 +241,18 @@ def get_block(block):
return runtime


def make_test_scope_ids(block_type, block_id='test_block', course_key=None, user_id=None):
"""
Return valid ScopeIds for a test block of the given type.

XBlock validates ScopeIds, so tests can no longer pass a Mock or None for them.
"""
id_generator = CourseLocationManager(course_key or CourseKey.from_string('org/course/run'))
def_id = id_generator.create_definition(block_type, block_id)
usage_id = id_generator.create_usage(def_id)
return ScopeIds(user_id, block_type, def_id, usage_id)


def get_test_descriptor_system(render_template=None, **kwargs):
"""
Construct a test ModuleStoreRuntime instance.
Expand Down
4 changes: 3 additions & 1 deletion xmodule/tests/test_annotatable_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def setUp(self):
self.annotatable = self.annotatable_class(
get_test_system(),
DictFieldData({'data': self.sample_xml}),
ScopeIds(None, None, None, BlockUsageLocator(CourseLocator('org', 'course', 'run'), 'category', 'name'))
ScopeIds(
None, 'category', None, BlockUsageLocator(CourseLocator('org', 'course', 'run'), 'category', 'name')
)
)

def test_annotation_data_attr(self):
Expand Down
6 changes: 3 additions & 3 deletions xmodule/tests/test_capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from xmodule.tests import DATA_DIR

from ..capa_block import RANDOMIZATION, SHOWANSWER
from . import get_test_system
from . import get_test_system, make_test_scope_ids


class CapaFactory:
Expand Down Expand Up @@ -4046,15 +4046,15 @@ def _user_state(self, username="testuser", response_count=10, suffix=""):

def _get_block(self):
"""Create and return a mock ProblemBlock with default test data."""
scope_ids = Mock(block_type="problem")
scope_ids = make_test_scope_ids('problem')
block = ProblemBlock(get_test_system(), scope_ids=scope_ids)
block.runtime = Mock()
block.data = "<problem/>"
return block

def test_generate_report_data_not_implemented(self):
"""Verify report generation is not supported for non-problem blocks."""
scope_ids = Mock(block_type="noproblem")
scope_ids = make_test_scope_ids('noproblem')
block = ProblemBlock(get_test_system(), scope_ids=scope_ids)
with pytest.raises(NotImplementedError):
next(block.generate_report_data(iter([])))
Expand Down
6 changes: 3 additions & 3 deletions xmodule/tests/test_conditional.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def load_item(usage_id, for_parent=None): # pylint: disable=unused-argument
cond_block = ConditionalBlock(
system,
field_data,
ScopeIds(None, None, cond_location, cond_location)
ScopeIds(None, 'conditional', cond_location, cond_location)
)
system.get_block_for_descriptor = lambda desc: desc if visible_to_nonstaff_users(desc) else None
cond_block.get_required_blocks = [
Expand Down Expand Up @@ -281,7 +281,7 @@ def test_conditional_block_with_empty_sources_list(self):
dummy_system = Mock()
dummy_location = BlockUsageLocator(CourseLocator("edX", "conditional_test", "test_run"),
"conditional", "SampleConditional")
dummy_scope_ids = ScopeIds(None, None, dummy_location, dummy_location)
dummy_scope_ids = ScopeIds(None, 'conditional', dummy_location, dummy_location)
dummy_field_data = DictFieldData({
'data': '<conditional/>',
'xml_attributes': {'sources': 'i4x://HarvardX/ER22x/poll_question/T15_poll'},
Expand All @@ -301,7 +301,7 @@ def test_conditional_block_parse_sources(self):
dummy_system = Mock()
dummy_location = BlockUsageLocator(CourseLocator("edX", "conditional_test", "test_run"),
"conditional", "SampleConditional")
dummy_scope_ids = ScopeIds(None, None, dummy_location, dummy_location)
dummy_scope_ids = ScopeIds(None, 'conditional', dummy_location, dummy_location)
dummy_field_data = DictFieldData({
'data': '<conditional/>',
'xml_attributes': {'sources': 'i4x://HarvardX/ER22x/poll_question/T15_poll;i4x://HarvardX/ER22x/poll_question/T16_poll'}, # pylint: disable=line-too-long
Expand Down
2 changes: 1 addition & 1 deletion xmodule/tests/test_delay_between_attempts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def create(
block = ProblemBlock(
system,
DictFieldData(field_data),
ScopeIds(None, None, location, location),
ScopeIds(None, 'problem', location, location),
)

if correct:
Expand Down
6 changes: 3 additions & 3 deletions xmodule/tests/test_html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from xmodule.html_block import CourseInfoBlock

from . import get_test_system
from . import get_test_system, make_test_scope_ids


class CourseInfoBlockTestCase(unittest.TestCase):
Expand Down Expand Up @@ -37,7 +37,7 @@ def test_updates_render(self):
info_block = CourseInfoBlock(
get_test_system(),
DictFieldData({'items': sample_update_data, 'data': ""}),
Mock()
make_test_scope_ids('course_info')
)

# Prior to TNL-4115, an exception would be raised when trying to parse invalid dates in this method
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_updates_order(self):
info_block = CourseInfoBlock(
Mock(),
DictFieldData({'items': sample_update_data, 'data': ""}),
Mock()
make_test_scope_ids('course_info')
)

expected_context = {
Expand Down
4 changes: 2 additions & 2 deletions xmodule/tests/test_lti20_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from xmodule.lti_2_util import LTIError as BuiltInLTIError
from xmodule.tests.helpers import StubUserService

from . import get_test_system
from . import get_test_system, make_test_scope_ids


class _LTI20RESTResultServiceTestBase(TestCase):
Expand All @@ -41,7 +41,7 @@ def setUp(self):
self.runtime.publish = Mock()
self.runtime._services['rebind_user'] = Mock() # pylint: disable=protected-access

self.xblock = self.lti_class(self.runtime, DictFieldData({}), Mock())
self.xblock = self.lti_class(self.runtime, DictFieldData({}), make_test_scope_ids('lti'))
self.lti_id = self.xblock.lti_id
self.xblock.due = None
self.xblock.graceperiod = None
Expand Down
Loading
Loading