本文整理汇总了Python中djblets.avatars.registry.AvatarServiceRegistry类的典型用法代码示例。如果您正苦于以下问题:Python AvatarServiceRegistry类的具体用法?Python AvatarServiceRegistry怎么用?Python AvatarServiceRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AvatarServiceRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unregister
def test_unregister(self):
"""Testing AvatarServiceRegistry.unregister"""
self.siteconfig.set(AvatarServiceRegistry.DEFAULT_SERVICE_KEY,
GravatarService.avatar_service_id)
self.siteconfig.set(AvatarServiceRegistry.ENABLED_SERVICES_KEY,
[GravatarService.avatar_service_id])
self.siteconfig.save()
registry = AvatarServiceRegistry()
gravatar_service = registry.get('avatar_service_id',
GravatarService.avatar_service_id)
self.assertEqual(registry.enabled_services, {gravatar_service})
registry.unregister(gravatar_service)
self.assertEqual(registry.enabled_services, set())
self.assertIsNone(registry.default_service)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[GravatarService.avatar_service_id])
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
GravatarService.avatar_service_id)
示例2: test_default_service_after_service_reregistered
def test_default_service_after_service_reregistered(self):
"""Testing AvatarServiceRegistry.default_service after service
registered after previously unregistered
"""
self.siteconfig.set(AvatarServiceRegistry.ENABLED_SERVICES_KEY,
[DummyAvatarService.avatar_service_id])
self.siteconfig.set(AvatarServiceRegistry.DEFAULT_SERVICE_KEY,
DummyAvatarService.avatar_service_id)
self.siteconfig.save()
registry = AvatarServiceRegistry()
registry.populate()
self.assertIsNone(registry.default_service)
# Make sure it's still saved in siteconfig. We'd only unset it if
# wasn't in the list of stoerd enabled service IDs, since we might be
# running without extensions loaded.
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
DummyAvatarService.avatar_service_id)
registry.register(DummyAvatarService)
self.assertIsInstance(registry.default_service, DummyAvatarService)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
DummyAvatarService.avatar_service_id)
示例3: test_set_enabled_services
def test_set_enabled_services(self):
"""Testing AvatarServiceRegistry.enabled_services setter"""
registry = AvatarServiceRegistry()
dummy_service = DummyAvatarService()
registry.register(dummy_service)
gravatar_service = registry.get('id', GravatarService.id)
registry.enabled_services = [dummy_service, gravatar_service]
self.assertEqual(registry.enabled_services,
{dummy_service, gravatar_service})
示例4: test_set_default_service_disabled
def test_set_default_service_disabled(self):
"""Testing AvatarServiceRegistry.set_default_service setter with a
disabled service
"""
registry = AvatarServiceRegistry()
gravatar_service = registry.get('id', GravatarService.id)
self.assertIsNone(registry.default_service)
with self.assertRaises(DisabledServiceError):
registry.set_default_service(gravatar_service)
self.assertIsNone(registry.default_service)
示例5: test_disable_service_by_id_with_save_false
def test_disable_service_by_id_with_save_false(self):
"""Testing AvatarServiceRegistry.disable_service_by_id with save=False
"""
registry = AvatarServiceRegistry()
self.assertFalse(registry.is_enabled(GravatarService))
registry.enable_service(GravatarService)
self.assertTrue(registry.is_enabled(GravatarService))
self.assertEqual(set(registry.enabled_services), {GravatarService})
registry.disable_service_by_id(GravatarService.avatar_service_id,
save=False)
self.assertFalse(registry.is_enabled(GravatarService))
self.assertEqual(set(registry.enabled_services), set())
# Make sure we've saved this in our cached siteconfig...
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[])
# ... but not in the database.
siteconfig = SiteConfiguration.objects.get(pk=siteconfig.pk)
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.ENABLED_SERVICES_KEY),
[GravatarService.avatar_service_id])
示例6: test_set_enabled_services_invalid_service
def test_set_enabled_services_invalid_service(self):
"""Testing AvatarServiceRegistry.enabled_services setter with an
unregistered service
"""
registry = AvatarServiceRegistry()
dummy_service = DummyAvatarService()
gravatar_service = registry.get('avatar_service_id',
GravatarService.avatar_service_id)
with self.assertRaises(ItemLookupError):
registry.enabled_services = [dummy_service, gravatar_service]
self.assertEqual(registry.enabled_services, set())
示例7: test_populate
def test_populate(self):
"""Testing AvatarServiceRegistry.populate with site configuration
settings
"""
self.siteconfig.set(AvatarServiceRegistry.ENABLED_SERVICES_KEY,
[GravatarService.avatar_service_id])
self.siteconfig.set(AvatarServiceRegistry.DEFAULT_SERVICE_KEY,
GravatarService.avatar_service_id)
self.siteconfig.save()
registry = AvatarServiceRegistry()
registry.populate()
self.assertTrue(registry.populated)
self.assertIsInstance(registry.default_service, GravatarService)
self.assertEqual(registry.enabled_services, {GravatarService})
示例8: test_set_enabled_services_invalid_service
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),
[])
示例9: test_set_default_service
def test_set_default_service(self):
"""Testing AvatarServiceRegistry.set_default_service"""
self.siteconfig.set(AvatarServiceRegistry.ENABLED_SERVICES_KEY,
[GravatarService.avatar_service_id])
self.siteconfig.save()
registry = AvatarServiceRegistry()
self.assertIsNone(registry.default_service)
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)
示例10: test_disable_default
def test_disable_default(self):
"""Testing AvatarServiceRegistry.disable_service unsets the default
service
"""
registry = AvatarServiceRegistry()
registry.enable_service(GravatarService.id)
registry.set_default_service(registry.get('id', GravatarService.id))
registry.disable_service(GravatarService.id)
self.assertIsNone(registry.default_service)
示例11: test_set_default_service_disabled
def test_set_default_service_disabled(self):
"""Testing AvatarServiceRegistry.set_default_service with a disabled
service
"""
registry = AvatarServiceRegistry()
gravatar_service = registry.get('avatar_service_id',
GravatarService.avatar_service_id)
self.assertIsNone(registry.default_service)
with self.assertRaises(DisabledServiceError):
registry.set_default_service(gravatar_service)
self.assertIsNone(registry.default_service)
siteconfig = SiteConfiguration.objects.get_current()
self.assertIsNone(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY))
示例12: test_set_enabled_services
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,
})
示例13: test_disable_service
def test_disable_service(self):
"""Testing AvatarServiceRegistry.disable_service"""
registry = AvatarServiceRegistry()
self.assertFalse(registry.is_enabled(GravatarService.id))
registry.enable_service(GravatarService.id)
self.assertTrue(registry.is_enabled(GravatarService.id))
self.assertSetEqual(set(registry.enabled_services),
set(registry))
registry.disable_service(GravatarService.id)
self.assertFalse(registry.is_enabled(GravatarService.id))
self.assertSetEqual(set(registry.enabled_services), set())
示例14: test_disable_default_from_setter
def test_disable_default_from_setter(self):
"""Testing AvatarServiceRegistry.enabled_services setter unsets the
default services
"""
registry = AvatarServiceRegistry()
registry.enable_service(GravatarService.id)
registry.set_default_service(registry.get('id', GravatarService.id))
registry.enabled_services = []
self.assertIsNone(registry.default_service)
示例15: test_set_default_service_invalid
def test_set_default_service_invalid(self):
"""Testing AvatarServiceRegistry.set_default_service with an
unregistered service
"""
self.siteconfig.set(AvatarServiceRegistry.ENABLED_SERVICES_KEY,
[GravatarService.avatar_service_id])
self.siteconfig.set(AvatarServiceRegistry.DEFAULT_SERVICE_KEY,
GravatarService.avatar_service_id)
self.siteconfig.save()
registry = AvatarServiceRegistry()
self.assertIsInstance(registry.default_service, GravatarService)
with self.assertRaises(ItemLookupError):
registry.set_default_service(DummyAvatarService)
self.assertIsInstance(registry.default_service, GravatarService)
siteconfig = SiteConfiguration.objects.get_current()
self.assertEqual(
siteconfig.get(AvatarServiceRegistry.DEFAULT_SERVICE_KEY),
GravatarService.avatar_service_id)