本文整理汇总了Python中lms.djangoapps.lms_xblock.runtime.LmsModuleSystem.service方法的典型用法代码示例。如果您正苦于以下问题:Python LmsModuleSystem.service方法的具体用法?Python LmsModuleSystem.service怎么用?Python LmsModuleSystem.service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lms.djangoapps.lms_xblock.runtime.LmsModuleSystem
的用法示例。
在下文中一共展示了LmsModuleSystem.service方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestUserServiceAPI
# 需要导入模块: from lms.djangoapps.lms_xblock.runtime import LmsModuleSystem [as 别名]
# 或者: from lms.djangoapps.lms_xblock.runtime.LmsModuleSystem import service [as 别名]
class TestUserServiceAPI(TestCase):
"""Test the user service interface"""
def setUp(self):
super(TestUserServiceAPI, self).setUp()
self.course_id = SlashSeparatedCourseKey("org", "course", "run")
self.user = User(username='runtime_robot', email='[email protected]', password='test', first_name='Robot')
self.user.save()
def mock_get_real_user(_anon_id):
"""Just returns the test user"""
return self.user
self.runtime = LmsModuleSystem(
static_url='/static',
track_function=Mock(),
get_module=Mock(),
render_template=Mock(),
replace_urls=str,
course_id=self.course_id,
get_real_user=mock_get_real_user,
descriptor_runtime=Mock(),
)
self.scope = 'course'
self.key = 'key1'
self.mock_block = Mock()
self.mock_block.service_declaration.return_value = 'needs'
def test_get_set_tag(self):
# test for when we haven't set the tag yet
tag = self.runtime.service(self.mock_block, 'user_tags').get_tag(self.scope, self.key)
self.assertIsNone(tag)
# set the tag
set_value = 'value'
self.runtime.service(self.mock_block, 'user_tags').set_tag(self.scope, self.key, set_value)
tag = self.runtime.service(self.mock_block, 'user_tags').get_tag(self.scope, self.key)
self.assertEqual(tag, set_value)
# Try to set tag in wrong scope
with self.assertRaises(ValueError):
self.runtime.service(self.mock_block, 'user_tags').set_tag('fake_scope', self.key, set_value)
# Try to get tag in wrong scope
with self.assertRaises(ValueError):
self.runtime.service(self.mock_block, 'user_tags').get_tag('fake_scope', self.key)
示例2: TestI18nService
# 需要导入模块: from lms.djangoapps.lms_xblock.runtime import LmsModuleSystem [as 别名]
# 或者: from lms.djangoapps.lms_xblock.runtime.LmsModuleSystem import service [as 别名]
class TestI18nService(ModuleStoreTestCase):
""" Test ModuleI18nService """
shard = 4
def setUp(self):
""" Setting up tests """
super(TestI18nService, self).setUp()
self.course = CourseFactory.create()
self.test_language = 'dummy language'
self.runtime = LmsModuleSystem(
static_url='/static',
track_function=Mock(),
get_module=Mock(),
render_template=Mock(),
replace_urls=str,
course_id=self.course.id,
descriptor_runtime=Mock(),
)
self.mock_block = Mock()
self.mock_block.service_declaration.return_value = 'need'
def test_module_i18n_lms_service(self):
"""
Test: module i18n service in LMS
"""
i18n_service = self.runtime.service(self.mock_block, 'i18n')
self.assertIsNotNone(i18n_service)
self.assertIsInstance(i18n_service, ModuleI18nService)
def test_no_service_exception_with_none_declaration_(self):
"""
Test: NoSuchServiceError should be raised block declaration returns none
"""
self.mock_block.service_declaration.return_value = None
with self.assertRaises(NoSuchServiceError):
self.runtime.service(self.mock_block, 'i18n')
def test_no_service_exception_(self):
"""
Test: NoSuchServiceError should be raised if i18n service is none.
"""
self.runtime._services['i18n'] = None # pylint: disable=protected-access
with self.assertRaises(NoSuchServiceError):
self.runtime.service(self.mock_block, 'i18n')
def test_i18n_service_callable(self):
"""
Test: _services dict should contain the callable i18n service in LMS.
"""
self.assertTrue(callable(self.runtime._services.get('i18n'))) # pylint: disable=protected-access
def test_i18n_service_not_callable(self):
"""
Test: i18n service should not be callable in LMS after initialization.
"""
self.assertFalse(callable(self.runtime.service(self.mock_block, 'i18n')))