本文整理汇总了Python中helpers.FakeArgs.is_admin方法的典型用法代码示例。如果您正苦于以下问题:Python FakeArgs.is_admin方法的具体用法?Python FakeArgs.is_admin怎么用?Python FakeArgs.is_admin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.FakeArgs
的用法示例。
在下文中一共展示了FakeArgs.is_admin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bin
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import is_admin [as 别名]
def test_bin(self):
xproto = \
"""
policy output < (ctx.is_admin = True | obj.empty = True) | False>
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
exec(output) # This loads the generated function, which should look like this:
"""
def policy_output_validator(obj, ctx):
i2 = (ctx.is_admin == True)
i3 = (obj.empty == True)
i1 = (i2 or i3)
if (not i1):
raise Exception('Necessary Failure')
"""
obj = FakeArgs()
obj.empty = False
ctx = FakeArgs()
ctx.is_admin = False
with self.assertRaises(Exception):
verdict = policy_output_validator(obj, ctx)
示例2: test_bin
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import is_admin [as 别名]
def test_bin(self):
xproto = \
"""
policy output < ctx.is_admin = True | obj.empty = True>
"""
args = FakeArgs()
args.inputs = xproto
args.target = self.target
output = XOSGenerator.generate(args)
exec(output) # This loads the generated function, which should look like this:
"""
def policy_output_enforcer(obj, ctx):
i2 = (ctx.is_admin == True)
i3 = (obj.empty == True)
i1 = (i2 or i3)
return i1
"""
obj = FakeArgs()
obj.empty = True
ctx = FakeArgs()
ctx.is_admin = True
verdict = policy_output_enforcer(obj, ctx)
self.assertTrue(verdict)
示例3: test_bin
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import is_admin [as 别名]
def test_bin(self):
xproto = \
"""
policy slice_admin < slice.is_admin | obj.empty >
"""
target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.slice_admin }}")
args = FakeArgs()
args.inputs = xproto
args.target = target
output = XOSGenerator.generate(args)
slice = FakeArgs()
slice.is_admin = False
obj = FakeArgs()
obj.empty = []
(op, operands), = eval(output).items()
expr = op.join(operands).replace('|',' or ')
self.assertFalse(eval(expr))
示例4: test_implies
# 需要导入模块: from helpers import FakeArgs [as 别名]
# 或者: from helpers.FakeArgs import is_admin [as 别名]
def test_implies(self):
xproto = \
"""
policy implies < obj.name -> obj.creator >
"""
target = XProtoTestHelpers.write_tmp_target("{{ proto.policies.implies }}")
args = FakeArgs()
args.inputs = xproto
args.target = target
output = XOSGenerator.generate(args)
slice = FakeArgs()
slice.is_admin = False
obj = FakeArgs()
obj.name = 'Thing 1'
obj.creator = None
(op, operands), = eval(output).items()
expr = 'not ' + op.join(operands).replace('->',' or ')
self.assertFalse(eval(expr))