本文整理匯總了Python中xblock.test.tools.TestRuntime.get_block方法的典型用法代碼示例。如果您正苦於以下問題:Python TestRuntime.get_block方法的具體用法?Python TestRuntime.get_block怎麽用?Python TestRuntime.get_block使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類xblock.test.tools.TestRuntime
的用法示例。
在下文中一共展示了TestRuntime.get_block方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_cached_parent
# 需要導入模塊: from xblock.test.tools import TestRuntime [as 別名]
# 或者: from xblock.test.tools.TestRuntime import get_block [as 別名]
def test_cached_parent():
class HasParent(XBlock):
"""
Dummy empty class
"""
pass
runtime = TestRuntime(services={'field-data': DictFieldData({})})
runtime.get_block = Mock()
block = HasParent(runtime, scope_ids=Mock(spec=ScopeIds))
# block has no parent yet, and we don't need to call the runtime to find
# that out.
assert_equals(block.get_parent(), None)
assert not runtime.get_block.called
# Set a parent id for the block. Get the parent. Now we have one, and we
# used runtime.get_block to get it.
block.parent = "some_parent_id"
parent = block.get_parent()
assert_not_equals(parent, None)
assert runtime.get_block.called_with("some_parent_id")
# Get the parent again. It will be the same parent, and we didn't call the
# runtime.
runtime.get_block.reset_mock()
parent2 = block.get_parent()
assert parent2 is parent
assert not runtime.get_block.called
示例2: TestRuntimeGetBlock
# 需要導入模塊: from xblock.test.tools import TestRuntime [as 別名]
# 或者: from xblock.test.tools.TestRuntime import get_block [as 別名]
class TestRuntimeGetBlock(TestCase):
"""
Test the get_block default method on Runtime.
"""
def setUp(self):
patcher = patch.object(TestRuntime, 'construct_xblock')
self.construct_block = patcher.start()
self.addCleanup(patcher.stop)
self.id_reader = Mock(IdReader)
self.user_id = Mock()
self.field_data = Mock(FieldData)
self.runtime = TestRuntime(self.id_reader, services={'field-data': self.field_data})
self.runtime.user_id = self.user_id
self.usage_id = 'usage_id'
# Can only get a definition id from the id_reader
self.def_id = self.id_reader.get_definition_id.return_value
# Can only get a block type from the id_reader
self.block_type = self.id_reader.get_block_type.return_value
def test_basic(self):
self.runtime.get_block(self.usage_id)
self.id_reader.get_definition_id.assert_called_with(self.usage_id)
self.id_reader.get_block_type.assert_called_with(self.def_id)
self.construct_block.assert_called_with(
self.block_type,
ScopeIds(self.user_id, self.block_type, self.def_id, self.usage_id),
for_parent=None,
)
def test_missing_usage(self):
self.id_reader.get_definition_id.side_effect = NoSuchUsage
with self.assertRaises(NoSuchUsage):
self.runtime.get_block(self.usage_id)
def test_missing_definition(self):
self.id_reader.get_block_type.side_effect = NoSuchDefinition
# If we don't have a definition, then the usage doesn't exist
with self.assertRaises(NoSuchUsage):
self.runtime.get_block(self.usage_id)