本文整理匯總了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)