refactor: xblock api upstream info and course details api (#37971)

- Returns top parent key instead of boolean in upstream info api
- Adds edited_on raw time in course outline api
- Adds has_changes to course details api
This commit is contained in:
Navin Karkera
2026-02-10 04:39:06 +05:30
committed by GitHub
parent 3c4cf0e2d2
commit 8ca70db552
11 changed files with 52 additions and 20 deletions

View File

@@ -1,15 +1,15 @@
"""
Tests for xmodule/util/keys.py
"""
import ddt
import pytest
from unittest import TestCase
from unittest.mock import Mock
from opaque_keys.edx.locator import BlockUsageLocator
import ddt
import pytest
from opaque_keys.edx.keys import CourseKey
from xmodule.util.keys import BlockKey, derive_key
from opaque_keys.edx.locator import BlockUsageLocator
from xmodule.util.keys import BlockKey, derive_key
mock_block = Mock()
mock_block.id = CourseKey.from_string('course-v1:Beeper+B33P+BOOP')
@@ -70,3 +70,19 @@ class TestBlockKeyParsing(TestCase):
@ddt.unpack
def test_block_key_to_string(self, block_key, block_key_str):
assert str(block_key) == block_key_str
@ddt.data(
[BlockKey('chapter', 'some-id'), BlockUsageLocator(
mock_block.id,
'chapter',
'some-id'
)],
[BlockKey('section', 'one-more-id'), BlockUsageLocator(
mock_block.id,
'section',
'one-more-id'
)]
)
@ddt.unpack
def test_block_key_to_usage_key(self, block_key: BlockKey, block_key_str):
assert block_key.to_usage_key(mock_block.id) == block_key_str

View File

@@ -6,7 +6,7 @@ Consider moving these into opaque-keys if they generalize well.
import hashlib
from typing import NamedTuple, Self
from opaque_keys.edx.keys import UsageKey
from opaque_keys.edx.keys import CourseKey, UsageKey
class BlockKey(NamedTuple):
@@ -40,6 +40,12 @@ class BlockKey(NamedTuple):
raise ValueError(f"Invalid string format for BlockKey: {s}")
return cls(parts[0], parts[1])
def to_usage_key(self, course_key: CourseKey) -> UsageKey:
"""
Converts this BlockKey into a UsageKey.
"""
return course_key.make_usage_key(self.type, self.id)
def derive_key(source: UsageKey, dest_parent: BlockKey) -> BlockKey:
"""