def test_add_global_defaults(self): """Testing SiteConfiguration.add_global_defaults""" SiteConfiguration.add_global_defaults({ 'valid_key_1': 'global_value_1', 'valid_key_2': 'global_value_2', 'valid_key_3': 'global_value_3', }) try: self.assertEqual(self.siteconfig.get('valid_key_1'), 'global_value_1') self.assertEqual(self.siteconfig.get('valid_key_2'), 'global_value_2') self.assertEqual(self.siteconfig.get('valid_key_3'), 'global_value_3') finally: SiteConfiguration.remove_global_default('valid_key_1') SiteConfiguration.remove_global_default('valid_key_2') SiteConfiguration.remove_global_default('valid_key_3')
def test_get_defaults(self): """Testing SiteConfiguration.get_defaults""" SiteConfiguration.add_global_defaults({ 'valid_key_1': 'global_value_1', 'valid_key_2': 'global_value_2', 'valid_key_3': 'global_value_3', }) SiteConfiguration.add_global_default('valid_key_1', 'new_global_value') try: siteconfig_defaults = SiteConfiguration.get_global_defaults() self.assertEqual(siteconfig_defaults['valid_key_1'], 'new_global_value') self.assertEqual(siteconfig_defaults['valid_key_2'], 'global_value_2') self.assertEqual(siteconfig_defaults['valid_key_3'], 'global_value_3') finally: SiteConfiguration.remove_global_default('valid_key_1') SiteConfiguration.remove_global_default('valid_key_2') SiteConfiguration.remove_global_default('valid_key_3')
user (django.contrib.auth.models.User): The user to retrieve the avatar service for. service_id (unicode, optional): The unique identifier of the service that is to be retrieved. If this is ``None``, the default service will be used. Returns: djblets.avatars.services.base.AvatarService: An avatar service, or ``None`` if one could not be found. """ settings_manager = self.settings_manager_class(user) user_service_id = settings_manager.avatar_service_id for sid in (service_id, user_service_id): if sid is None or not self.has_service(sid): continue service = self.get('avatar_service_id', sid) if self.is_enabled(service): return self.get_avatar_service(sid) return self.default_service SiteConfiguration.add_global_defaults({ AvatarServiceRegistry.ENABLED_SERVICES_KEY: [], AvatarServiceRegistry.DEFAULT_SERVICE_KEY: None, })