本文整理汇总了Python中rules.add_perm方法的典型用法代码示例。如果您正苦于以下问题:Python rules.add_perm方法的具体用法?Python rules.add_perm怎么用?Python rules.add_perm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rules
的用法示例。
在下文中一共展示了rules.add_perm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_test_perms
# 需要导入模块: import rules [as 别名]
# 或者: from rules import add_perm [as 别名]
def setup_test_perms():
"""
Create missing permissions that would be defined in edx-platform,
or elsewhere.
edx-platform imports tests from edx-proctoring, which causes duplicate
rules, so ignore the KeyError thrown by the rules package.
"""
try:
rules.add_perm('accounts.can_retire_user', rules.is_staff)
except KeyError: # pragma: no cover
pass
try:
rules.add_perm('edx_proctoring.can_take_proctored_exam', rules.always_true)
except KeyError: # pragma: no cover
pass
示例2: test_explicit_permission_coupon_overview
# 需要导入模块: import rules [as 别名]
# 或者: from rules import add_perm [as 别名]
def test_explicit_permission_coupon_overview(self):
"""
Test that we get explicit access via role assignment
"""
# Re-order rules predicate to check explicit access first.
rules.remove_perm('enterprise.can_view_coupon')
rules.add_perm(
'enterprise.can_view_coupon',
request_user_has_explicit_access |
request_user_has_implicit_access
)
response = self.get_response('POST', ENTERPRISE_COUPONS_LINK, self.data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
response = self.get_response(
'GET',
reverse(
'api:v2:enterprise-coupons-overview',
kwargs={'enterprise_id': self.data['enterprise_customer']['id']}
)
)
self.assertEqual(response.status_code, status.HTTP_200_OK)