當前位置: 首頁>>代碼示例>>Python>>正文


Python registry.AvatarServiceRegistry類代碼示例

本文整理匯總了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)
開發者ID:chipx86,項目名稱:djblets,代碼行數:25,代碼來源:tests.py

示例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)
開發者ID:chipx86,項目名稱:djblets,代碼行數:31,代碼來源:tests.py

示例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})
開發者ID:iconoeugen,項目名稱:djblets,代碼行數:13,代碼來源:tests.py

示例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)
開發者ID:iconoeugen,項目名稱:djblets,代碼行數:13,代碼來源:tests.py

示例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])
開發者ID:chipx86,項目名稱:djblets,代碼行數:26,代碼來源:tests.py

示例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())
開發者ID:mikicz,項目名稱:djblets,代碼行數:15,代碼來源:tests.py

示例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})
開發者ID:chipx86,項目名稱:djblets,代碼行數:16,代碼來源:tests.py

示例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),
            [])
開發者ID:chipx86,項目名稱:djblets,代碼行數:16,代碼來源:tests.py

示例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)
開發者ID:chipx86,項目名稱:djblets,代碼行數:17,代碼來源:tests.py

示例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)
開發者ID:iconoeugen,項目名稱:djblets,代碼行數:10,代碼來源:tests.py

示例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))
開發者ID:chipx86,項目名稱:djblets,代碼行數:18,代碼來源:tests.py

示例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,
            })
開發者ID:chipx86,項目名稱:djblets,代碼行數:18,代碼來源:tests.py

示例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())
開發者ID:iconoeugen,項目名稱:djblets,代碼行數:13,代碼來源:tests.py

示例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)
開發者ID:iconoeugen,項目名稱:djblets,代碼行數:10,代碼來源:tests.py

示例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)
開發者ID:chipx86,項目名稱:djblets,代碼行數:22,代碼來源:tests.py


注:本文中的djblets.avatars.registry.AvatarServiceRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。