当前位置: 首页>>代码示例>>Python>>正文


Python Registry.getUtility方法代码示例

本文整理汇总了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
开发者ID:debonzi,项目名称:websauna,代码行数:28,代码来源:utils.py

示例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)
开发者ID:JDeuce,项目名称:pyramid,代码行数:10,代码来源:test_settings.py

示例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)
开发者ID:canni,项目名称:pyramid,代码行数:11,代码来源:test_settings.py

示例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')
开发者ID:Pylons,项目名称:pyramid,代码行数:11,代码来源:test_init.py

示例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')
开发者ID:Pylons,项目名称:pyramid,代码行数:11,代码来源:test_init.py

示例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')
开发者ID:Pylons,项目名称:pyramid,代码行数:11,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:12,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:12,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:13,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py

示例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)
开发者ID:liqd,项目名称:adhocracy3,代码行数:14,代码来源:__init__.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py

示例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)
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_init.py


注:本文中的pyramid.registry.Registry.getUtility方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。