本文整理汇总了Python中pyramid.registry.Registry.getUtility方法的典型用法代码示例。如果您正苦于以下问题:Python Registry.getUtility方法的具体用法?Python Registry.getUtility怎么用?Python Registry.getUtility使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.registry.Registry
的用法示例。
在下文中一共展示了Registry.getUtility方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_user
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def create_user(dbsession:Session, registry:Registry, email:str=EMAIL, password:str=PASSWORD, admin:bool=False) -> User:
"""A helper function to create normal and admin users for tests.
:param admin: If True run :py:class:`websauna.system.user.usermixin.SiteCreator` login and set the user to admin group.
"""
user = User(email=email)
if password:
hasher = registry.getUtility(IPasswordHasher)
user.hashed_password = hasher.hash_password(password)
user.user_registration_source = "dummy"
dbsession.add(user)
dbsession.flush()
user.username = user.generate_username()
user.activated_at = now()
assert user.can_login()
# First user, make it admin
if admin:
site_creator = get_site_creator(registry)
site_creator.init_empty_site(dbsession, user)
return user
示例2: test_add_settings_settings_None
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_add_settings_settings_None(self):
from pyramid.registry import Registry
from pyramid.interfaces import ISettings
reg = Registry()
config = self._makeOne(reg)
config.add_settings(None, a=1)
settings = reg.getUtility(ISettings)
self.assertEqual(settings['a'], 1)
示例3: test_add_settings_settings_not_yet_registered
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_add_settings_settings_not_yet_registered(self):
from pyramid.registry import Registry
from pyramid.interfaces import ISettings
reg = Registry()
config = self._makeOne(reg)
config.add_settings({"a": 1})
settings = reg.getUtility(ISettings)
self.assertEqual(settings["a"], 1)
示例4: test_setup_registry_default_permission
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_default_permission(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDefaultPermission
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(default_permission='view')
config.commit()
self.assertEqual(reg.getUtility(IDefaultPermission), 'view')
示例5: test_setup_registry_debug_logger_None_default
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_debug_logger_None_default(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
config.setup_registry()
logger = reg.getUtility(IDebugLogger)
self.assertEqual(logger.name, 'tests.test_config')
示例6: test_setup_registry_debug_logger_name
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_debug_logger_name(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(debug_logger='foo')
result = reg.getUtility(IDebugLogger)
self.assertEqual(result.name, 'foo')
示例7: test_setup_registry_alternate_renderers
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_alternate_renderers(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRendererFactory
renderer = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(renderers=[('yeah', renderer)])
config.commit()
self.assertEqual(reg.getUtility(IRendererFactory, 'yeah'), renderer)
示例8: test_setup_registry_debug_logger_non_None
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_debug_logger_non_None(self):
from pyramid.registry import Registry
from pyramid.interfaces import IDebugLogger
logger = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(debug_logger=logger)
result = reg.getUtility(IDebugLogger)
self.assertEqual(logger, result)
示例9: test_setup_registry_authentication_policy
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_authentication_policy(self):
from pyramid.registry import Registry
from pyramid.interfaces import IAuthenticationPolicy
policy = object()
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(authentication_policy=policy)
config.commit()
result = reg.getUtility(IAuthenticationPolicy)
self.assertEqual(policy, result)
示例10: test_setup_registry_locale_negotiator
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_locale_negotiator(self):
from pyramid.registry import Registry
from pyramid.interfaces import ILocaleNegotiator
reg = Registry()
config = self._makeOne(reg)
negotiator = object()
config.setup_registry(locale_negotiator=negotiator)
self.assertEqual(reg.queryUtility(ILocaleNegotiator), None)
config.commit()
utility = reg.getUtility(ILocaleNegotiator)
self.assertEqual(utility, negotiator)
示例11: test_setup_registry_dottedname_root_factory
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_dottedname_root_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IRootFactory
reg = Registry()
config = self._makeOne(reg)
import tests.test_config
config.setup_registry(root_factory='tests.test_config')
self.assertEqual(reg.queryUtility(IRootFactory), None)
config.commit()
self.assertEqual(reg.getUtility(IRootFactory), tests.test_config)
示例12: test_setup_registry_authentication_policy_dottedname
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_authentication_policy_dottedname(self):
from pyramid.registry import Registry
from pyramid.interfaces import IAuthenticationPolicy
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(authentication_policy='tests.test_config')
config.commit()
result = reg.getUtility(IAuthenticationPolicy)
import tests.test_config
self.assertEqual(result, tests.test_config)
示例13: __init__
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def __init__(self, registry: Registry):
"""Create a new instance.
:param registry: used to retrieve and configure the mailer
"""
self.registry = registry
settings = registry['config']
self.settings = settings
self.abuse_handler_mail = settings.adhocracy.abuse_handler_mail
self.site_name = settings.adhocracy.site_name
self.frontend_url = settings.adhocracy.canonical_url
self.mailer = registry.getUtility(IMailer)
示例14: test_setup_registry_response_factory
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_response_factory(self):
from pyramid.registry import Registry
from pyramid.interfaces import IResponseFactory
reg = Registry()
config = self._makeOne(reg)
factory = lambda r: object()
config.setup_registry(response_factory=factory)
self.assertEqual(reg.queryUtility(IResponseFactory), None)
config.commit()
utility = reg.getUtility(IResponseFactory)
self.assertEqual(utility, factory)
示例15: test_setup_registry_custom_settings
# 需要导入模块: from pyramid.registry import Registry [as 别名]
# 或者: from pyramid.registry.Registry import getUtility [as 别名]
def test_setup_registry_custom_settings(self):
from pyramid.registry import Registry
from pyramid.interfaces import ISettings
settings = {'reload_templates': True, 'mysetting': True}
reg = Registry()
config = self._makeOne(reg)
config.setup_registry(settings=settings)
settings = reg.getUtility(ISettings)
self.assertEqual(settings['reload_templates'], True)
self.assertEqual(settings['debug_authorization'], False)
self.assertEqual(settings['mysetting'], True)