本文整理汇总了Python中djblets.avatars.registry.AvatarServiceRegistry.set_enabled_services方法的典型用法代码示例。如果您正苦于以下问题:Python AvatarServiceRegistry.set_enabled_services方法的具体用法?Python AvatarServiceRegistry.set_enabled_services怎么用?Python AvatarServiceRegistry.set_enabled_services使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类djblets.avatars.registry.AvatarServiceRegistry
的用法示例。
在下文中一共展示了AvatarServiceRegistry.set_enabled_services方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_service
# 需要导入模块: from djblets.avatars.registry import AvatarServiceRegistry [as 别名]
# 或者: from djblets.avatars.registry.AvatarServiceRegistry import set_enabled_services [as 别名]
def test_default_service(self):
"""Testing AvatarServiceRegistry.default_service"""
registry = AvatarServiceRegistry()
registry.register(DummyAvatarService)
registry.set_enabled_services([DummyAvatarService, GravatarService])
self.assertIsNone(registry.default_service)
# Set the default backend to the dummy backend.
registry.set_default_service(DummyAvatarService)
self.assertIsInstance(registry.default_service, DummyAvatarService)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
DummyAvatarService.avatar_service_id)
# Set the default backend to the Gravatar backend.
registry.set_default_service(GravatarService)
self.assertIsInstance(registry.default_service, GravatarService)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
GravatarService.avatar_service_id)
# Remove the default backend.
registry.set_default_service(None)
self.assertIsNone(registry.default_service)
siteconfig = SiteConfiguration.objects.get_current()
self.assertIsNone(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY))
示例2: test_set_enabled_services_invalid_service
# 需要导入模块: from djblets.avatars.registry import AvatarServiceRegistry [as 别名]
# 或者: from djblets.avatars.registry.AvatarServiceRegistry import set_enabled_services [as 别名]
def test_set_enabled_services_invalid_service(self):
"""Testing AvatarServiceRegistry.set_enabled_services with an
unregistered service
"""
registry = AvatarServiceRegistry()
with self.assertRaises(ItemLookupError):
registry.set_enabled_services([DummyAvatarService,
GravatarService])
self.assertEqual(registry.enabled_services, set())
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[])
示例3: test_disable_default_from_setter
# 需要导入模块: from djblets.avatars.registry import AvatarServiceRegistry [as 别名]
# 或者: from djblets.avatars.registry.AvatarServiceRegistry import set_enabled_services [as 别名]
def test_disable_default_from_setter(self):
"""Testing AvatarServiceRegistry.set_enabled_services unsets the
default services when removed
"""
registry = AvatarServiceRegistry()
registry.enable_service(GravatarService)
registry.set_default_service(GravatarService)
registry.set_enabled_services([])
self.assertIsNone(registry.default_service)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[])
self.assertIsNone(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY))
示例4: test_set_enabled_services
# 需要导入模块: from djblets.avatars.registry import AvatarServiceRegistry [as 别名]
# 或者: from djblets.avatars.registry.AvatarServiceRegistry import set_enabled_services [as 别名]
def test_set_enabled_services(self):
"""Testing AvatarServiceRegistry.set_enabled_services"""
registry = AvatarServiceRegistry()
registry.register(DummyAvatarService)
registry.set_enabled_services([DummyAvatarService, GravatarService])
self.assertEqual(registry.enabled_services,
{DummyAvatarService, GravatarService})
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
set(siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY)),
{
DummyAvatarService.avatar_service_id,
GravatarService.avatar_service_id,
})
示例5: test_set_enabled_services_with_save_false
# 需要导入模块: from djblets.avatars.registry import AvatarServiceRegistry [as 别名]
# 或者: from djblets.avatars.registry.AvatarServiceRegistry import set_enabled_services [as 别名]
def test_set_enabled_services_with_save_false(self):
"""Testing AvatarServiceRegistry.set_enabled_services with save=False
"""
registry = AvatarServiceRegistry()
registry.register(DummyAvatarService)
registry.set_enabled_services([DummyAvatarService, GravatarService],
save=False)
self.assertEqual(registry.enabled_services,
{DummyAvatarService, GravatarService})
# Make sure we've saved this in our cached siteconfig...
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
set(siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY)),
{DummyAvatarService.avatar_service_id,
GravatarService.avatar_service_id})
# ... but not in the database.
siteconfig = SiteConfiguration.objects.get(pk=siteconfig.pk)
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[])