本文整理汇总了Python中pyramid.configuration.Configurator.testing_securitypolicy方法的典型用法代码示例。如果您正苦于以下问题:Python Configurator.testing_securitypolicy方法的具体用法?Python Configurator.testing_securitypolicy怎么用?Python Configurator.testing_securitypolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.configuration.Configurator
的用法示例。
在下文中一共展示了Configurator.testing_securitypolicy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerDummySecurityPolicy
# 需要导入模块: from pyramid.configuration import Configurator [as 别名]
# 或者: from pyramid.configuration.Configurator import testing_securitypolicy [as 别名]
def registerDummySecurityPolicy(userid=None, groupids=(), permissive=True):
""" Registers a pair of faux :app:`Pyramid` security policies:
a :term:`authentication policy` and a :term:`authorization
policy`.
The behavior of the registered :term:`authorization policy`
depends on the ``permissive`` argument. If ``permissive`` is
true, a permissive :term:`authorization policy` is registered;
this policy allows all access. If ``permissive`` is false, a
nonpermissive :term:`authorization policy` is registered; this
policy denies all access.
The behavior of the registered :term:`authentication policy`
depends on the values provided for the ``userid`` and ``groupids``
argument. The authentication policy will return the userid
identifier implied by the ``userid`` argument and the group ids
implied by the ``groupids`` argument when the
:func:`pyramid.security.authenticated_userid` or
:func:`pyramid.security.effective_principals` APIs are used.
This function is most useful when testing code that uses the APIs
named :func:`pyramid.security.has_permission`,
:func:`pyramid.security.authenticated_userid`,
:func:`pyramid.security.effective_principals`, and
:func:`pyramid.security.principals_allowed_by_permission`.
.. warning:: This API is deprecated as of :app:`Pyramid` 1.0.
Instead use the
:meth:`pyramid.configuration.Configurator.testing_securitypolicy`
method in your unit and integration tests.
"""
registry = get_current_registry()
config = Configurator(registry=registry)
return config.testing_securitypolicy(userid=userid, groupids=groupids, permissive=permissive)